[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24310] trunk/blender: new operator directory, move some scripts from io
Campbell Barton
ideasman42 at gmail.com
Wed Nov 4 15:40:37 CET 2009
Revision: 24310
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24310
Author: campbellbarton
Date: 2009-11-04 15:40:35 +0100 (Wed, 04 Nov 2009)
Log Message:
-----------
new operator directory, move some scripts from io
Modified Paths:
--------------
trunk/blender/source/blender/python/intern/bpy_interface.c
Added Paths:
-----------
trunk/blender/release/scripts/op/
trunk/blender/release/scripts/op/add_mesh_torus.py
trunk/blender/release/scripts/op/mesh_skin.py
trunk/blender/release/scripts/op/uvcalc_smart_project.py
trunk/blender/release/scripts/op/vertexpaint_dirt.py
Removed Paths:
-------------
trunk/blender/release/scripts/io/add_mesh_torus.py
trunk/blender/release/scripts/io/mesh_skin.py
trunk/blender/release/scripts/io/uvcalc_smart_project.py
trunk/blender/release/scripts/io/vertexpaint_dirt.py
Deleted: trunk/blender/release/scripts/io/add_mesh_torus.py
===================================================================
--- trunk/blender/release/scripts/io/add_mesh_torus.py 2009-11-04 14:33:37 UTC (rev 24309)
+++ trunk/blender/release/scripts/io/add_mesh_torus.py 2009-11-04 14:40:35 UTC (rev 24310)
@@ -1,139 +0,0 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-# <pep8-80 compliant>
-import bpy
-import Mathutils
-from math import cos, sin, pi
-
-
-def add_torus(major_rad, minor_rad, major_seg, minor_seg):
- Vector = Mathutils.Vector
- Quaternion = Mathutils.Quaternion
-
- PI_2 = pi * 2
- z_axis = (0, 0, 1)
-
- verts = []
- faces = []
- i1 = 0
- tot_verts = major_seg * minor_seg
- for major_index in range(major_seg):
- quat = Quaternion(z_axis, (major_index / major_seg) * PI_2)
-
- for minor_index in range(minor_seg):
- angle = 2 * pi * minor_index / minor_seg
-
- vec = Vector(major_rad + (cos(angle) * minor_rad), 0.0,
- (sin(angle) * minor_rad)) * quat
-
- verts.extend([vec.x, vec.y, vec.z])
-
- if minor_index + 1 == minor_seg:
- i2 = (major_index) * minor_seg
- i3 = i1 + minor_seg
- i4 = i2 + minor_seg
-
- else:
- i2 = i1 + 1
- i3 = i1 + minor_seg
- i4 = i3 + 1
-
- if i2 >= tot_verts:
- i2 = i2 - tot_verts
- if i3 >= tot_verts:
- i3 = i3 - tot_verts
- if i4 >= tot_verts:
- i4 = i4 - tot_verts
-
- # stupid eekadoodle
- if i2:
- faces.extend([i1, i3, i4, i2])
- else:
- faces.extend([i2, i1, i3, i4])
-
- i1 += 1
-
- return verts, faces
-
-from bpy.props import *
-
-
-class AddTorus(bpy.types.Operator):
- '''Add a torus mesh.'''
- bl_idname = "mesh.primitive_torus_add"
- bl_label = "Add Torus"
- bl_register = True
- bl_undo = True
-
- major_radius = FloatProperty(name="Major Radius",
- description="Number of segments for the main ring of the torus",
- default=1.0, min=0.01, max=100.0)
- minor_radius = FloatProperty(name="Minor Radius",
- description="Number of segments for the minor ring of the torus",
- default=0.25, min=0.01, max=100.0)
- major_segments = IntProperty(name="Major Segments",
- description="Number of segments for the main ring of the torus",
- default=48, min=3, max=256)
- minor_segments = IntProperty(name="Minor Segments",
- description="Number of segments for the minor ring of the torus",
- default=16, min=3, max=256)
-
- def execute(self, context):
-
- verts_loc, faces = add_torus(self.major_radius,
- self.minor_radius,
- self.major_segments,
- self.minor_segments)
-
- mesh = bpy.data.add_mesh("Torus")
-
- mesh.add_geometry(int(len(verts_loc) / 3), 0, int(len(faces) / 4))
- mesh.verts.foreach_set("co", verts_loc)
- mesh.faces.foreach_set("verts_raw", faces)
-
- scene = context.scene
-
- # ugh
- for ob in scene.objects:
- ob.selected = False
-
- mesh.update()
- ob_new = bpy.data.add_object('MESH', "Torus")
- ob_new.data = mesh
- scene.add_object(ob_new)
- scene.objects.active = ob_new
- ob_new.selected = True
-
- ob_new.location = tuple(context.scene.cursor_location)
-
- return ('FINISHED',)
-
-# Register the operator
-bpy.ops.add(AddTorus)
-
-# Add to a menu
-import dynamic_menu
-
-menu_func = (lambda self, context: self.layout.itemO(AddTorus.bl_idname,
- text="Torus", icon='ICON_MESH_DONUT'))
-
-menu_item = dynamic_menu.add(bpy.types.INFO_MT_mesh_add, menu_func)
-
-if __name__ == "__main__":
- bpy.ops.mesh.primitive_torus_add()
Deleted: trunk/blender/release/scripts/io/mesh_skin.py
===================================================================
--- trunk/blender/release/scripts/io/mesh_skin.py 2009-11-04 14:33:37 UTC (rev 24309)
+++ trunk/blender/release/scripts/io/mesh_skin.py 2009-11-04 14:40:35 UTC (rev 24310)
@@ -1,664 +0,0 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-# import Blender
-import time, functools
-import bpy
-# from Blender import Window
-from Mathutils import MidpointVecs, Vector
-from Mathutils import AngleBetweenVecs as _AngleBetweenVecs_
-# import BPyMessages
-
-# from Blender.Draw import PupMenu
-
-BIG_NUM = 1<<30
-
-global CULL_METHOD
-CULL_METHOD = 0
-
-def AngleBetweenVecs(a1,a2):
- import math
- try:
- return math.degrees(_AngleBetweenVecs_(a1,a2))
- except:
- return 180.0
-
-class edge(object):
- __slots__ = 'v1', 'v2', 'co1', 'co2', 'length', 'removed', 'match', 'cent', 'angle', 'next', 'prev', 'normal', 'fake'
- def __init__(self, v1,v2):
- self.v1 = v1
- self.v2 = v2
- co1, co2= v1.co, v2.co
- self.co1= co1
- self.co2= co2
-
- # uv1 uv2 vcol1 vcol2 # Add later
- self.length = (co1 - co2).length
- self.removed = 0 # Have we been culled from the eloop
- self.match = None # The other edge were making a face with
-
- self.cent= MidpointVecs(co1, co2)
- self.angle= 0.0
- self.fake= False
-
-class edgeLoop(object):
- __slots__ = 'centre', 'edges', 'normal', 'closed', 'backup_edges'
- def __init__(self, loop, me, closed): # Vert loop
- # Use next and prev, nextDist, prevDist
-
- # Get Loops centre.
- fac= len(loop)
- verts = me.verts
- self.centre= functools.reduce(lambda a,b: a+verts[b].co/fac, loop, Vector())
-
- # Convert Vert loop to Edges.
- self.edges = [edge(verts[loop[vIdx-1]], verts[loop[vIdx]]) for vIdx in range(len(loop))]
-
- if not closed:
- self.edges[0].fake = True # fake edge option
-
- self.closed = closed
-
-
- # Assign linked list
- for eIdx in range(len(self.edges)-1):
- self.edges[eIdx].next = self.edges[eIdx+1]
- self.edges[eIdx].prev = self.edges[eIdx-1]
- # Now last
- self.edges[-1].next = self.edges[0]
- self.edges[-1].prev = self.edges[-2]
-
-
-
- # GENERATE AN AVERAGE NORMAL FOR THE WHOLE LOOP.
- self.normal = Vector()
- for e in self.edges:
- n = (self.centre-e.co1).cross(self.centre-e.co2)
- # Do we realy need tot normalize?
- n.normalize()
- self.normal += n
-
- # Generate the angle
- va= e.cent - e.prev.cent
- vb= e.next.cent - e.cent
-
- e.angle= AngleBetweenVecs(va, vb)
-
- # Blur the angles
- #for e in self.edges:
- # e.angle= (e.angle+e.next.angle)/2
-
- # Blur the angles
- #for e in self.edges:
- # e.angle= (e.angle+e.prev.angle)/2
-
- self.normal.normalize()
-
- # Generate a normal for each edge.
- for e in self.edges:
-
- n1 = e.co1
- n2 = e.co2
- n3 = e.prev.co1
-
- a = n1-n2
- b = n1-n3
- normal1 = a.cross(b)
- normal1.normalize()
-
- n1 = e.co2
- n3 = e.next.co2
- n2 = e.co1
-
- a = n1-n2
- b = n1-n3
-
- normal2 = a.cross(b)
- normal2.normalize()
-
- # Reuse normal1 var
- normal1 += normal1 + normal2
- normal1.normalize()
-
- e.normal = normal1
- #print e.normal
-
-
-
- def backup(self):
- # Keep a backup of the edges
- self.backup_edges = self.edges[:]
-
- def restore(self):
- self.edges = self.backup_edges[:]
- for e in self.edges:
- e.removed = 0
-
- def reverse(self):
- self.edges.reverse()
- self.normal.negate()
-
- for e in self.edges:
- e.normal.negate()
- e.v1, e.v2 = e.v2, e.v1
- e.co1, e.co2 = e.co2, e.co1
- e.next, e.prev = e.prev, e.next
-
-
- def removeSmallest(self, cullNum, otherLoopLen):
- '''
- Removes N Smallest edges and backs up the loop,
- this is so we can loop between 2 loops as if they are the same length,
- backing up and restoring incase the loop needs to be skinned with another loop of a different length.
- '''
- global CULL_METHOD
- if CULL_METHOD == 1: # Shortest edge
- eloopCopy = self.edges[:]
-
- # Length sort, smallest first
- try: eloopCopy.sort(key = lambda e1: e1.length)
- except: eloopCopy.sort(lambda e1, e2: cmp(e1.length, e2.length ))
-
- # Dont use atm
- #eloopCopy.sort(lambda e1, e2: cmp(e1.angle*e1.length, e2.angle*e2.length)) # Length sort, smallest first
- #eloopCopy.sort(lambda e1, e2: cmp(e1.angle, e2.angle)) # Length sort, smallest first
-
- remNum = 0
- for i, e in enumerate(eloopCopy):
- if not e.fake:
- e.removed = 1
- self.edges.remove( e ) # Remove from own list, still in linked list.
- remNum += 1
-
- if not remNum < cullNum:
- break
-
- else: # CULL METHOD is even
-
- culled = 0
-
- step = int(otherLoopLen / float(cullNum)) * 2
-
- currentEdge = self.edges[0]
- while culled < cullNum:
-
- # Get the shortest face in the next STEP
- step_count= 0
- bestAng= 360.0
- smallestEdge= None
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list