Metaball - docs were wrong

Sound - needed t ohave the PyType as extern
3ds_export can now export derived objects (dupli's)
This commit is contained in:
2007-01-07 15:33:28 +00:00
parent 7135cd0721
commit 713f42dc3c
3 changed files with 72 additions and 58 deletions

View File

@@ -48,7 +48,11 @@ from the lib3ds project (http://lib3ds.sourceforge.net/) sourcecode.
import Blender import Blender
from Blender import Object, Material from Blender import Object, Material
import BPyMesh import BPyMesh
getMeshFromObject = BPyMesh.getMeshFromObject
import BPyObject
getDerivedObjects= BPyObject.getDerivedObjects
import struct import struct
@@ -490,16 +494,18 @@ class tri_wrapper(object):
def split_into_tri(face, do_uv=False): def split_into_tri(face, do_uv=False):
'''Split a quad face into two triangles''' '''Split a quad face into two triangles'''
v = face.v v = face.v
uv = face.uv
mat = face.mat mat = face.mat
if (do_uv): if (do_uv):
img = face.image img = face.image
if img: img = img.name if img: img = img.name
else:
img = None
first_tri = tri_wrapper((v[0].index, v[1].index, v[2].index), mat, img) first_tri = tri_wrapper((v[0].index, v[1].index, v[2].index), mat, img)
second_tri = tri_wrapper((v[0].index, v[2].index, v[3].index), mat, img) second_tri = tri_wrapper((v[0].index, v[2].index, v[3].index), mat, img)
if (do_uv): if (do_uv):
uv = face.uv
first_tri.faceuvs= uv_key(uv[0]), uv_key(uv[1]), uv_key(uv[2]) first_tri.faceuvs= uv_key(uv[0]), uv_key(uv[1]), uv_key(uv[2])
second_tri.faceuvs= uv_key(uv[0]), uv_key(uv[2]), uv_key(uv[3]) second_tri.faceuvs= uv_key(uv[0]), uv_key(uv[2]), uv_key(uv[3])
@@ -782,7 +788,7 @@ def make_track_chunk(ID, obj):
track_chunk.add_variable("scale", _3ds_point_3d((1.0, 1.0, 1.0))) track_chunk.add_variable("scale", _3ds_point_3d((1.0, 1.0, 1.0)))
return track_chunk return track_chunk
"""
def make_kf_obj_node(obj, name_to_id): def make_kf_obj_node(obj, name_to_id):
'''Make a node chunk for a Blender object. '''Make a node chunk for a Blender object.
@@ -842,12 +848,13 @@ def make_kf_obj_node(obj, name_to_id):
kf_obj_node.add_subchunk(make_track_chunk(SCL_TRACK_TAG, obj)) kf_obj_node.add_subchunk(make_track_chunk(SCL_TRACK_TAG, obj))
return kf_obj_node return kf_obj_node
"""
def save_3ds(filename): def save_3ds(filename):
'''Save the Blender scene to a 3ds file.''' '''Save the Blender scene to a 3ds file.'''
# Time the export # Time the export
time1= Blender.sys.time() time1= Blender.sys.time()
Blender.Window.WaitCursor(1)
scn= Blender.Scene.GetCurrent() scn= Blender.Scene.GetCurrent()
# Initialize the main chunk (primary): # Initialize the main chunk (primary):
@@ -866,70 +873,75 @@ def save_3ds(filename):
''' '''
# Get all the supported objects selected in this scene: # Get all the supported objects selected in this scene:
ob_sel= list(scn.objects.context) # ob_sel= list(scn.objects.context)
# mesh_objects = [ (ob, me) for ob in ob_sel for me in (BPyMesh.getMeshFromObject(ob, None, True, False, scn),) if me ]
mesh_objects = [ (ob, me) for ob in ob_sel for me in (BPyMesh.getMeshFromObject(ob, None, True, False, scn),) if me ] # empty_objects = [ ob for ob in ob_sel if ob.type == 'Empty' ]
empty_objects = [ ob for ob in ob_sel if ob.type == 'Empty' ]
# Make a list of all materials used in the selected meshes (use a dictionary, # Make a list of all materials used in the selected meshes (use a dictionary,
# each material is added once): # each material is added once):
materialDict = {} materialDict = {}
mesh_objects = []
for ob, data in mesh_objects: for ob in scn.objects.context:
# get material/image tuples. for ob_derived, mat in getDerivedObjects(ob, False):
if data.faceUV: data = getMeshFromObject(ob_derived, None, True, False, scn)
mat_ls = data.materials if data:
data.transform(mat)
if not mat_ls: mesh_objects.append((ob_derived, data))
mat = mat_name = None
for f in data.faces:
if mat_ls:
mat = mat_ls[f.mat]
if mat: mat_name = mat.name
else: mat_name = None
# else there alredy set to none
img = f.image
if img: img_name = img.name
else: img_name = None
try: # get material/image tuples.
materialDict[mat_name, img_name] if data.faceUV:
except: mat_ls = data.materials
materialDict[mat_name, img_name]= mat, img
if not mat_ls:
else: mat = mat_name = None
for mat in data.materials:
if mat: # material may be None so check its not. for f in data.faces:
try: if mat_ls:
materialDict[mat.name, None] mat = mat_ls[f.mat]
except: if mat: mat_name = mat.name
materialDict[mat.name, None]= mat, None else: mat_name = None
# else there alredy set to none
img = f.image
if img: img_name = img.name
else: img_name = None
try:
materialDict[mat_name, img_name]
except:
materialDict[mat_name, img_name]= mat, img
else:
for mat in data.materials:
if mat: # material may be None so check its not.
try:
materialDict[mat.name, None]
except:
materialDict[mat.name, None]= mat, None
# Make material chunks for all materials used in the meshes: # Make material chunks for all materials used in the meshes:
for mat_and_image in materialDict.itervalues(): for mat_and_image in materialDict.itervalues():
object_info.add_subchunk(make_material_chunk(*mat_and_image)) object_info.add_subchunk(make_material_chunk(*mat_and_image))
# Give all objects a unique ID and build a dictionary from object name to object id: # Give all objects a unique ID and build a dictionary from object name to object id:
"""
name_to_id = {} name_to_id = {}
for ob, data in mesh_objects: for ob, data in mesh_objects:
name_to_id[ob.name]= len(name_to_id) name_to_id[ob.name]= len(name_to_id)
for ob in empty_objects: #for ob in empty_objects:
name_to_id[ob.name]= len(name_to_id) # name_to_id[ob.name]= len(name_to_id)
"""
# Create object chunks for all meshes: # Create object chunks for all meshes:
i = 0
for ob, blender_mesh in mesh_objects: for ob, blender_mesh in mesh_objects:
# create a new object chunk # create a new object chunk
object_chunk = _3ds_chunk(OBJECT) object_chunk = _3ds_chunk(OBJECT)
# transform the mesh:
blender_mesh.transform(ob.matrixWorld)
# set the object name # set the object name
object_chunk.add_variable("name", _3ds_string(ob.name)) object_chunk.add_variable("name", _3ds_string(str(i) + ob.name))
# make a mesh chunk out of the mesh: # make a mesh chunk out of the mesh:
object_chunk.add_subchunk(make_mesh_chunk(blender_mesh, materialDict)) object_chunk.add_subchunk(make_mesh_chunk(blender_mesh, materialDict))
@@ -939,6 +951,8 @@ def save_3ds(filename):
# make a kf object node for the object: # make a kf object node for the object:
kfdata.add_subchunk(make_kf_obj_node(ob, name_to_id)) kfdata.add_subchunk(make_kf_obj_node(ob, name_to_id))
''' '''
blender_mesh.verts = None
i+=i
# Create chunks for all empties: # Create chunks for all empties:
''' # COMMENTED OUT FOR 2.42 RELEASE!! CRASHES 3DS MAX ''' # COMMENTED OUT FOR 2.42 RELEASE!! CRASHES 3DS MAX
@@ -970,16 +984,19 @@ def save_3ds(filename):
file.close() file.close()
# Free memory # Free memory
"""
for ob, blender_mesh in mesh_objects: for ob, blender_mesh in mesh_objects:
blender_mesh.verts= None blender_mesh.verts= None
"""
# Debugging only: report the exporting time: # Debugging only: report the exporting time:
Blender.Window.WaitCursor(0)
print "3ds export time: %.2f" % (Blender.sys.time() - time1) print "3ds export time: %.2f" % (Blender.sys.time() - time1)
# Debugging only: dump the chunk hierarchy: # Debugging only: dump the chunk hierarchy:
#primary.dump() #primary.dump()
if __name__=='__main__': if __name__=='__main__':
Blender.Window.FileSelector(save_3ds, "Export 3DS", Blender.sys.makename(ext='.3ds')) Blender.Window.FileSelector(save_3ds, "Export 3DS", Blender.sys.makename(ext='.3ds'))
# save_3ds('/test_b.3ds') # save_3ds('/test_b.3ds')

View File

@@ -37,6 +37,7 @@
#include "DNA_sound_types.h" #include "DNA_sound_types.h"
#define BPy_Sound_Check(v) ((v)->ob_type == &Sound_Type) #define BPy_Sound_Check(v) ((v)->ob_type == &Sound_Type)
extern PyTypeObject Sound_Type;
/*****************************************************************************/ /*****************************************************************************/
/* Python BPy_Sound structure definition */ /* Python BPy_Sound structure definition */

View File

@@ -8,23 +8,22 @@ This module provides access to B{Metaball} data in Blender and the elements they
Example:: Example::
import Blender import Blender
ob = Blender.Object.New("Mball","mb")
mb = Blender.Metaball.New() mb = Blender.Metaball.New()
for i in xrange(20): for i in xrange(20):
element= mb.elements.add() element= mb.elements.add()
element.loc= Blender.Mathutils.Vector(i, 0, 0) element.co = Blender.Mathutils.Vector(i, 0, 0)
ob.link(mb) sce = Blender.Scene.GetCurrent()
sc = Blender.Scene.GetCurrent() sce.objects.new(mb)
sc.link(ob)
from Blender import *
Example:: Example::
# Converts the active armature into metaballs # Converts the active armature into metaballs
from Blender import *
def main(): def main():
scn= Scene.GetCurrent() scn= Scene.GetCurrent()
ob_arm= scn.getActiveObject() ob_arm= scn.objects.active
if not ob_arm or ob_arm.type!='Armature': if not ob_arm or ob_arm.type!='Armature':
Draw.PupMenu('No Armature Selected') Draw.PupMenu('No Armature Selected')
return return
@@ -35,14 +34,11 @@ Example::
return return
# Make a metaball # Make a metaball
ob_mb= Object.New('Mball')
mb= Metaball.New() mb= Metaball.New()
mb.wiresize= res mb.wiresize= res
# Link to the Scene # Link to the Scene
ob_mb.link(mb) ob_mb = scn.objects.new(ob_mb)
scn.link(ob_mb)
ob_mb.sel=1
ob_arm.sel= 0 ob_arm.sel= 0
ob_mb.setMatrix(ob_arm.matrixWorld) ob_mb.setMatrix(ob_arm.matrixWorld)