[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24276] branches/bmesh/blender/release/ scripts: more missing files

Joseph Eagar joeedh at gmail.com
Tue Nov 3 15:10:34 CET 2009


Revision: 24276
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24276
Author:   joeedh
Date:     2009-11-03 15:10:34 +0100 (Tue, 03 Nov 2009)

Log Message:
-----------
more missing files

Added Paths:
-----------
    branches/bmesh/blender/release/scripts/io/add_mesh_torus.py
    branches/bmesh/blender/release/scripts/io/export_mdd.py
    branches/bmesh/blender/release/scripts/io/mesh_skin.py
    branches/bmesh/blender/release/scripts/modules/dynamic_menu.py
    branches/bmesh/blender/release/scripts/ui/buttons_render.py

Added: branches/bmesh/blender/release/scripts/io/add_mesh_torus.py
===================================================================
--- branches/bmesh/blender/release/scripts/io/add_mesh_torus.py	                        (rev 0)
+++ branches/bmesh/blender/release/scripts/io/add_mesh_torus.py	2009-11-03 14:10:34 UTC (rev 24276)
@@ -0,0 +1,98 @@
+
+import bpy, Mathutils
+from math import cos, sin, pi, radians
+
+
+def add_torus(PREF_MAJOR_RAD, PREF_MINOR_RAD, PREF_MAJOR_SEG, PREF_MINOR_SEG):
+	Vector = Mathutils.Vector
+	Quaternion = Mathutils.Quaternion
+	
+	PI_2= pi*2
+	Z_AXIS = 0,0,1
+	
+	verts = []
+	faces = []
+	i1 = 0
+	tot_verts = PREF_MAJOR_SEG * PREF_MINOR_SEG
+	for major_index in range(PREF_MAJOR_SEG):
+		verts_tmp = []
+		quat = Quaternion( Z_AXIS, (major_index/PREF_MAJOR_SEG)*PI_2)
+
+		for minor_index in range(PREF_MINOR_SEG):
+			angle = 2*pi*minor_index/PREF_MINOR_SEG
+			
+			vec = Vector(PREF_MAJOR_RAD+(cos(angle)*PREF_MINOR_RAD), 0, (sin(angle)*PREF_MINOR_RAD)) * quat
+			verts.extend([vec.x, vec.y, vec.z])
+			
+			if minor_index+1==PREF_MINOR_SEG:
+				i2 = (major_index)*PREF_MINOR_SEG
+				i3 = i1 + PREF_MINOR_SEG
+				i4 = i2 + PREF_MINOR_SEG
+				
+			else:
+				i2 = i1 + 1
+				i3 = i1 + PREF_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
+
+
+class MESH_OT_primitive_torus_add(bpy.types.Operator):
+	'''Add a torus mesh.'''
+	__idname__ = "mesh.primitive_torus_add"
+	__label__ = "Add Torus"
+	__register__ = True
+	__undo__ = True
+	__props__ = [
+		bpy.props.FloatProperty(attr="major_radius", name="Major Radius", description="Number of segments for the main ring of the torus", default= 1.0, min= 0.01, max= 100.0),
+		bpy.props.FloatProperty(attr="minor_radius", name="Minor Radius", description="Number of segments for the minor ring of the torus", default= 0.25, min= 0.01, max= 100.0),
+		bpy.props.IntProperty(attr="major_segments", name="Major Segments", description="Number of segments for the main ring of the torus", default= 48, min= 3, max= 256),
+		bpy.props.IntProperty(attr="minor_segments", 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)
+		
+		me= bpy.data.add_mesh("Torus")
+		
+		me.add_geometry(int(len(verts_loc)/3), 0, int(len(faces)/4))
+		me.verts.foreach_set("co", verts_loc)
+		me.faces.foreach_set("verts_raw", faces)
+		
+		sce = context.scene
+		
+		# ugh
+		for ob in sce.objects:
+			ob.selected = False
+		
+		me.update()
+		ob= bpy.data.add_object('MESH', "Torus")
+		ob.data= me
+		context.scene.add_object(ob)
+		context.scene.active_object = ob
+		ob.selected = True
+		
+		ob.location = tuple(context.scene.cursor_location)
+		
+		return ('FINISHED',)
+
+# Register the operator
+bpy.ops.add(MESH_OT_primitive_torus_add)
+
+# Add to a menu
+import dynamic_menu
+import space_info
+menu_item = dynamic_menu.add(bpy.types.INFO_MT_mesh_add, (lambda self, context: self.layout.itemO("mesh.primitive_torus_add", text="Torus", icon='ICON_MESH_DONUT')) )
+
+if __name__ == "__main__":
+	bpy.ops.mesh.primitive_torus_add()
\ No newline at end of file

Added: branches/bmesh/blender/release/scripts/io/export_mdd.py
===================================================================
--- branches/bmesh/blender/release/scripts/io/export_mdd.py	                        (rev 0)
+++ branches/bmesh/blender/release/scripts/io/export_mdd.py	2009-11-03 14:10:34 UTC (rev 24276)
@@ -0,0 +1,184 @@
+
+__author__ = "Bill L.Nieuwendorp"
+__bpydoc__ = """\
+This script Exports Lightwaves MotionDesigner format.
+
+The .mdd format has become quite a popular Pipeline format<br>
+for moving animations from package to package.
+
+Be sure not to use modifiers that change the number or order of verts in the mesh
+"""
+#Please send any fixes,updates,bugs to Slow67_at_Gmail.com or cbarton_at_metavr.com
+#Bill Niewuendorp
+# ***** 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 LICENCE BLOCK *****
+
+import bpy
+import Mathutils
+import math
+import os
+
+#import Blender
+#from Blender import *
+#import BPyMessages
+try:
+	from struct import pack
+except:
+	pack = None
+
+def zero_file(filepath):
+	'''
+	If a file fails, this replaces it with 1 char, better not remove it?
+	'''
+	file = open(filepath, 'w')
+	file.write('\n') # apparently macosx needs some data in a blank file?
+	file.close()
+
+def check_vertcount(mesh,vertcount):
+	'''
+	check and make sure the vertcount is consistent throughout the frame range
+	'''
+	if len(mesh.verts) != vertcount:
+		raise Exception('Error, number of verts has changed during animation, cannot export')
+		f.close()
+		zero_file(filepath)
+		return
+	
+	
+def write(filename, sce, ob, PREF_STARTFRAME, PREF_ENDFRAME, PREF_FPS):
+	if not pack:
+		raise Exception('Error, this script requires the "pack" module')
+	
+	if ob.type != 'MESH':
+		raise Exception('Error, active object is not a mesh')
+	"""
+	Window.EditMode(0)
+	Blender.Window.WaitCursor(1)
+
+	mesh_orig = Mesh.New()
+	mesh_orig.getFromObject(ob.name)
+	"""
+	orig_frame = sce.current_frame
+	sce.set_frame(PREF_STARTFRAME)
+	me = ob.create_mesh(True, 'PREVIEW')
+
+	#Flip y and z
+	mat_flip= Mathutils.Matrix(\
+	[1.0, 0.0, 0.0, 0.0],\
+	[0.0, 0.0, 1.0, 0.0],\
+	[0.0, 1.0, 0.0, 0.0],\
+	[0.0, 0.0, 0.0, 1.0],\
+	)
+
+	numverts = len(me.verts)
+
+	numframes = PREF_ENDFRAME-PREF_STARTFRAME+1
+	PREF_FPS= float(PREF_FPS)
+	f = open(filename, 'wb') #no Errors yet:Safe to create file
+	
+	# Write the header
+	f.write(pack(">2i", numframes, numverts))
+	
+	# Write the frame times (should we use the time IPO??)
+	f.write( pack(">%df" % (numframes), *[frame/PREF_FPS for frame in range(numframes)]) ) # seconds
+	
+	#rest frame needed to keep frames in sync
+	"""
+	Blender.Set('curframe', PREF_STARTFRAME)
+	me_tmp.getFromObject(ob.name)
+	"""
+
+	check_vertcount(me,numverts)
+	me.transform(mat_flip * ob.matrix)
+	f.write(pack(">%df" % (numverts*3), *[axis for v in me.verts for axis in v.co]))
+		
+	for frame in range(PREF_STARTFRAME,PREF_ENDFRAME+1):#in order to start at desired frame
+		"""
+		Blender.Set('curframe', frame)
+		me_tmp.getFromObject(ob.name)
+		"""
+
+		sce.set_frame(frame)
+		me = ob.create_mesh(True, 'PREVIEW')
+		check_vertcount(me,numverts)
+		me.transform(mat_flip * ob.matrix)
+		
+		# Write the vertex data
+		f.write(pack(">%df" % (numverts*3), *[axis for v in me.verts for axis in v.co]))
+	
+	"""
+	me_tmp.verts= None
+	"""
+	f.close()
+	
+	print ('MDD Exported: %s frames:%d\n'% (filename, numframes-1))
+	"""
+	Blender.Window.WaitCursor(0)
+	Blender.Set('curframe', orig_frame)
+	"""
+	sce.set_frame(orig_frame)
+
+class EXPORT_OT_mdd(bpy.types.Operator):
+	'''Animated mesh to MDD vertex keyframe file.'''
+	__idname__ = "export.mdd"
+	__label__ = "Export MDD"
+
+	# get first scene to get min and max properties for frames, fps
+
+	sce = bpy.data.scenes[bpy.data.scenes.keys()[0]]
+	minframe = sce.rna_type.properties["current_frame"].soft_min
+	maxframe = sce.rna_type.properties["current_frame"].soft_max
+	minfps = sce.render_data.rna_type.properties["fps"].soft_min
+	maxfps = sce.render_data.rna_type.properties["fps"].soft_max
+
+	# List of operator properties, the attributes will be assigned
+	# to the class instance from the operator settings before calling.
+	__props__ = [
+		bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the MDD file", maxlen= 1024, default= "tmp.mdd"),
+		bpy.props.IntProperty(attr="fps", name="Frames Per Second", description="Number of frames/second", min=minfps, max=maxfps, default= 25),
+		bpy.props.IntProperty(attr="start_frame", name="Start Frame", description="Start frame for baking", min=minframe,max=maxframe,default=1),
+		bpy.props.IntProperty(attr="end_frame", name="End Frame", description="End frame for baking", min=minframe, max=maxframe, default= 250),
+	]
+
+	def poll(self, context):
+		return context.active_object != None
+
+	def execute(self, context):
+		if not self.path:
+			raise Exception("filename not set")
+		write(self.path, context.scene, context.active_object,
+			self.start_frame, self.end_frame, self.fps )
+		return ('FINISHED',)
+	
+	def invoke(self, context, event):	
+		wm = context.manager
+		wm.add_fileselect(self.__operator__)
+		return ('RUNNING_MODAL',)
+
+bpy.ops.add(EXPORT_OT_mdd)
+
+# Add to a menu
+import dynamic_menu
+menu_func = lambda self, context: self.layout.itemO("export.mdd", text="Vertex Keyframe Animation (.mdd)...")
+menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
+
+if __name__=='__main__':
+	#if not pack:
+#		Draw.PupMenu('Error%t|This script requires a full python install')
+	#Blender.Window.FileSelector(mdd_export_ui, 'EXPORT MDD', sys.makename(ext='.mdd'))
+	bpy.ops.EXPORT_OT_mdd(path="/tmp/test.mdd")

Added: branches/bmesh/blender/release/scripts/io/mesh_skin.py
===================================================================
--- branches/bmesh/blender/release/scripts/io/mesh_skin.py	                        (rev 0)
+++ branches/bmesh/blender/release/scripts/io/mesh_skin.py	2009-11-03 14:10:34 UTC (rev 24276)
@@ -0,0 +1,647 @@
+# 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 
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list