Merge pull request #679 from slapin/exporter_work

Export shape keys to .dae as geometry
This commit is contained in:
Juan Linietsky 2014-09-17 20:01:23 -03:00
commit 76aaa96d0e
2 changed files with 38 additions and 14 deletions

View file

@ -126,6 +126,10 @@ class ExportDAE(bpy.types.Operator, ExportHelper):
default=True,
options={'HIDDEN'},
)
export_shapekeys = BoolProperty(
name="Export Shape Keys",
default=False,
)
@property
def check_extension(self):

View file

@ -315,12 +315,12 @@ class DaeExporter:
return matid
def export_mesh(self,node,armature=None):
def export_mesh(self,node,armature=None,shapename=None):
if (node.data in self.mesh_cache):
if (node.data in self.mesh_cache) and shapename==None:
return self.mesh_cache[mesh]
if (len(node.modifiers) and self.config["use_mesh_modifiers"]):
if (len(node.modifiers) and self.config["use_mesh_modifiers"]) or shapename!=None:
mesh=node.to_mesh(self.scene,True,"RENDER") #is this allright?
else:
mesh=node.data
@ -427,9 +427,13 @@ class DaeExporter:
indices.append(idx)
meshid = self.new_id("mesh")
if shapename != None:
meshid = self.new_id("mesh_"+shapename)
self.writel(S_GEOM,1,'<geometry id="'+meshid+'" name="'+mesh.name+'_'+shapename+'">')
else:
meshid = self.new_id("mesh")
self.writel(S_GEOM,1,'<geometry id="'+meshid+'" name="'+mesh.name+'">')
self.writel(S_GEOM,1,'<geometry id="'+meshid+'" name="'+mesh.name+'">')
self.writel(S_GEOM,2,'<mesh>')
@ -604,7 +608,7 @@ class DaeExporter:
return meshdata
def export_mesh_node(self,node,il):
def export_mesh_node(self,node,il,shapename=None):
if (node.data==None):
return
@ -614,8 +618,7 @@ class DaeExporter:
if (node.parent.type=="ARMATURE"):
armature=node.parent
meshdata = self.export_mesh(node,armature)
meshdata = self.export_mesh(node,armature,shapename)
if (armature==None):
self.writel(S_NODES,il,'<instance_geometry url="#'+meshdata["id"]+'">')
@ -903,18 +906,21 @@ class DaeExporter:
def export_node(self,node,il):
def export_node(self,node,il,shapename=None):
if (not self.is_node_valid(node)):
return
bpy.context.scene.objects.active = node
self.writel(S_NODES,il,'<node id="'+self.validate_id(node.name)+'" name="'+node.name+'" type="NODE">')
if shapename != None:
self.writel(S_NODES,il,'<node id="'+self.validate_id(node.name + '_' + shapename)+'" name="'+node.name+'_'+shapename+'" type="NODE">')
else:
self.writel(S_NODES,il,'<node id="'+self.validate_id(node.name)+'" name="'+node.name+'" type="NODE">')
il+=1
self.writel(S_NODES,il,'<matrix sid="transform">'+strmtx(node.matrix_local)+'</matrix>')
print("NODE TYPE: "+node.type+" NAME: "+node.name)
if (node.type=="MESH"):
self.export_mesh_node(node,il)
self.export_mesh_node(node,il,shapename)
elif (node.type=="CURVE"):
self.export_curve_node(node,il)
elif (node.type=="ARMATURE"):
@ -925,8 +931,22 @@ class DaeExporter:
self.export_lamp_node(node,il)
self.valid_nodes.append(node)
for x in node.children:
self.export_node(x,il)
if shapename==None:
for x in node.children:
self.export_node(x,il)
if node.type=="MESH" and self.config["export_shapekeys"]:
for k in range(0,len(node.data.shape_keys.key_blocks)):
shape = node.data.shape_keys.key_blocks[k]
oldval = shape.value
shape.value = 1.0
node.active_shape_key_index = k
p = node.data
v = node.to_mesh(bpy.context.scene, True, "RENDER")
node.data = v
self.export_node(node,il,shape.name)
node.data = p
node.data.update()
shape.value = oldval
il-=1
self.writel(S_NODES,il,'</node>')