Revision: 20439
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20439
Author:   migius
Date:     2009-05-27 01:37:40 +0200 (Wed, 27 May 2009)

Log Message:
-----------
patch by Jan Diederich (collad)
[#18829] COLLADA Export: Fixed bug, cleaned up deprecated code

translator.py:
1.fixed a bug that happened due to the explicit deletion of a temporary mesh 
(del temp_mesh).
2.removed redundant code. the execution time of the script increased 
significantly.
3.improved option to apply modifiers to handle absolutely every mesh instance 
created by a modifier.

cstartup.py:
1. improved the feedback for the end user about the time it took to process and 
the save the data.

Modified Paths:
--------------
    trunk/blender/release/scripts/bpymodules/colladaImEx/cstartup.py
    trunk/blender/release/scripts/bpymodules/colladaImEx/translator.py

Modified: trunk/blender/release/scripts/bpymodules/colladaImEx/cstartup.py
===================================================================
--- trunk/blender/release/scripts/bpymodules/colladaImEx/cstartup.py    
2009-05-26 21:34:20 UTC (rev 20438)
+++ trunk/blender/release/scripts/bpymodules/colladaImEx/cstartup.py    
2009-05-26 23:37:40 UTC (rev 20439)
@@ -523,6 +523,11 @@
 
        LoadDefaultVals()
 
+def CalcElapsedTime(startTime):
+       '''
+       Calc elapsed time between now and start time.
+       '''     
+       return Blender.sys.time() - startTime   
 
 def Event(evt, val):
        pass
@@ -674,20 +679,20 @@
                                                                                
lookAt, usePhysics, exportCurrentScene, \
                                                                                
exportRelativePaths, useUV, sampleAnimation, \
                                                                                
onlyMainScene, applyModifiers)
-                       # Redraw al 3D windows.
+                       
+                       cutils.Debug.Debug('Time to process and save data: 
%.1f' \
+                                                       % 
CalcElapsedTime(startTime), 'FEEDBACK')
+                       
+                       # Redraw all 3D windows.
                        Blender.Window.RedrawAll()
-
-                       # calculate the elapsed time
-                       endTime = Blender.sys.time()
-                       elapsedTime = endTime - startTime
+                       
                        Blender.Draw.PupMenu(importExportText + " Successful 
%t")
-               except:
-                       endTime = Blender.sys.time()
-                       elapsedTime = endTime - startTime
+               except:                                         
                        Blender.Draw.PupMenu(importExportText + "ing failed%t | 
Check the console for more info")
                        raise # throw the exception
 
-               cutils.Debug.Debug('FINISHED - time elapsed: 
%.1f'%(elapsedTime),'FEEDBACK')
+               cutils.Debug.Debug('FINISHED - time elapsed: %.1f' % 
CalcElapsedTime(startTime), \
+                                               'FEEDBACK')
 
                # Hide the wait cursor in blender
                Blender.Window.WaitCursor(0)

Modified: trunk/blender/release/scripts/bpymodules/colladaImEx/translator.py
===================================================================
--- trunk/blender/release/scripts/bpymodules/colladaImEx/translator.py  
2009-05-26 21:34:20 UTC (rev 20438)
+++ trunk/blender/release/scripts/bpymodules/colladaImEx/translator.py  
2009-05-26 23:37:40 UTC (rev 20439)
@@ -398,8 +398,6 @@
                                        self.containerMesh = temp_mesh
                if not self.containerMesh:
                        self.containerMesh = Blender.Mesh.New(temp_mesh_name)
-               
-               del temp_mesh
                #------------ [end] Copied from export OBJ 
------------------------
                
                # Loop through all scenes
@@ -2107,29 +2105,30 @@
                        instance = collada.DaeGeometryInstance()
                        daeGeometry = 
self.document.colladaDocument.geometriesLibrary.FindObject(bNode.getData(True))
                        meshNode = MeshNode(self.document)
-                       if daeGeometry is None:
-                               # TODO: Maybe add a for-loop if multiple 
instance are made by
-                               #               a transformation. But so far 
even a double mirror
-                               #               (x and y axis) results only in 
_1_ instance.
-                               derivedObject = 
BPyObject.getDerivedObjects(bNode)[0][0]
-                               virtualMesh = 
BPyMesh.getMeshFromObject(derivedObject, \
-                                                               
self.document.containerMesh, applyModifiers, False, bScene)
-                               if debprn:
-                                       print("Virtual mesh: " + 
str(virtualMesh) )
-                                       # + "; type: " + str(type(virtualMesh)))
-                               if not virtualMesh:
-                                       # Fallback!
-                                       # Should never happen!
-                                       # (The "mesh=1" param on the getData() 
method ensures that
-                                       # it gets a "Mesh" instead of a 
"NMesh".) 
-                                       print("Error while trying to save 
derived object / apply modifiers. Try saving " \
-                                                 + "more direct, all modifiers 
will be ignored.")
-                                       daeGeometry = 
meshNode.SaveToDae(bNode.getData(mesh=1))
-                               else:
-                                       # Apply original name from 
untransformed object
-                                       # to transformed object (name is later 
copied 1:1 to id).
-                                       virtualMesh.name = derivedObject.name
-                                       daeGeometry = 
meshNode.SaveToDae(virtualMesh)
+                       if daeGeometry is None:                                 
                   
+                               derivedObjsMatrices = 
BPyObject.getDerivedObjects(bNode)
+                               for derivedObject, matrix in 
derivedObjsMatrices:
+                                       virtualMesh = 
BPyMesh.getMeshFromObject(derivedObject, \
+                                                                       
self.document.containerMesh, applyModifiers, False, bScene)                     
                
+                                       if debprn:
+                                               print("Virtual mesh: " + 
str(virtualMesh) )
+                                               # + "; type: " + 
str(type(virtualMesh)))
+                                       if not virtualMesh:
+                                               # Fallback!
+                                               # Should never happen!
+                                               # (The "mesh=1" param on the 
getData() method ensures that
+                                               # it gets a "Mesh" instead of a 
"NMesh".) 
+                                               print("Error while trying to 
save derived object / apply modifiers. Try saving " \
+                                                         + "more direct, all 
modifiers will be ignored.")
+                                               daeGeometry = 
meshNode.SaveToDae(bNode.getData(mesh=1))
+                                       else:
+                                               # Apply original name from 
untransformed object
+                                               # to transformed object (name 
is later copied 1:1 to id).
+                                               virtualMesh.name = 
derivedObject.name
+                                               # _Don't_ apply transformation 
matrix "matrix"!
+                                               # The transformation will get 
instead written in the file itself
+                                               # seperately!
+                                               daeGeometry = 
meshNode.SaveToDae(virtualMesh)
                                        
                        meshID = daeGeometry.id
                        bindMaterials = 
meshNode.GetBindMaterials(bNode.getData(),\
@@ -2808,14 +2807,14 @@
                        return bMesh2
                return
 
-       def SaveToDae(self, bMesh):
+       def SaveToDae(self, mesh):
                global useTriangles, usePolygons, useUV
 
                uvTextures = dict()
                uvIndex = dict()
 
                daeGeometry = collada.DaeGeometry()
-               daeGeometry.id = daeGeometry.name = 
self.document.CreateID(bMesh.name,'-Geometry')
+               daeGeometry.id = daeGeometry.name = 
self.document.CreateID(mesh.name,'-Geometry')
 
                daeMesh = collada.DaeMesh()
 
@@ -2831,7 +2830,7 @@
                accessor = collada.DaeAccessor()
                daeSource.techniqueCommon.accessor = accessor
                accessor.source = daeFloatArray.id
-               accessor.count = len(bMesh.verts)
+               accessor.count = len(mesh.verts)
                accessor.AddParam('X','float')
                accessor.AddParam('Y','float')
                accessor.AddParam('Z','float')
@@ -2878,7 +2877,7 @@
 
                hasColor = False
                #Vertex colors:
-               if ( bMesh.vertexColors ) :
+               if ( mesh.vertexColors ) :
                        hasColor = True
                        daeSourceColors = collada.DaeSource()
                        daeSourceColors.id = 
self.document.CreateID(daeGeometry.id , '-color')
@@ -2894,7 +2893,7 @@
                        accessorColors.AddParam('B','float')
                        accessorColors.AddParam('A','float')
 
-               for vert in bMesh.verts:
+               for vert in mesh.verts:
                        #print vert
                        for co in vert.co:
                                daeFloatArray.data.append(co)
@@ -2906,14 +2905,13 @@
                daeTrianglesDict = dict()
                daeLines = None
 
-               mesh = Blender.Mesh.Get(bMesh.name)
 
                # Loop trough all the faces
                for face in mesh.faces:
                        matIndex = -1
-                       if not useUV and bMesh.materials and 
len(bMesh.materials) > 0:
+                       if not useUV and mesh.materials and len(mesh.materials) 
> 0:
                                matIndex = face.mat
-                       elif mesh.faceUV and (useUV or bMesh.materials is None 
or len(bMesh.materials) == 0):
+                       elif mesh.faceUV and (useUV or mesh.materials is None 
or len(mesh.materials) == 0):
                                if not face.image is None:
                                        matIndex = face.image.name
 
@@ -2970,6 +2968,7 @@
                                        # Update the prevVert vertice.
                                        prevVert = vert
 
+                       # Now use that AddVerts(...) function exactly in this 
"if"-block
                        if (vertCount == 3 and not usePolygons) or 
(useTriangles and vertCount == 4): # triangle
                                # Iff a Triangle Item for the current material 
not exists, create one.
                                daeTrianglesDict.setdefault(matIndex, 
collada.DaeTriangles())
@@ -2979,14 +2978,14 @@
                                                
daeFloatArrayNormals.data.append(no)
                                        accessorNormals.count = 
accessorNormals.count + 1
                                if vertCount == 3:
-                                       # Add al the vertices to the triangle 
list.
+                                       # Add all the vertices to the triangle 
list.
                                        
AddVerts(face.verts,daeTrianglesDict[matIndex].triangles, face.smooth )
                                        # Update the vertice count for the 
trianglelist.
                                        daeTrianglesDict[matIndex].count += 1
                                else: # Convert polygon to triangles
                                        verts1 = face.verts[:3]
                                        verts2 = face.verts[2:] + 
tuple([face.verts[0]])
-                                       # Add al the vertices to the triangle 
list.
+                                       # Add all the vertices to the triangle 
list.
                                        
AddVerts(verts1,daeTrianglesDict[matIndex].triangles, face.smooth)
                                        AddVerts(verts2, 
daeTrianglesDict[matIndex].triangles,face.smooth,True)
                                        # Update the vertice count for the 
trianglelist.
@@ -3001,7 +3000,7 @@
                                        for no in face.no:
                                                
daeFloatArrayNormals.data.append(no)
                                        accessorNormals.count = 
accessorNormals.count + 1
-                               # Add al the vertices to the pverts list.
+                               # Add all the vertices to the pverts list.
                                AddVerts(face.verts,pverts, face.smooth)
                                # Add the pverts list to the polygons list.
                                
daePolygonsDict[matIndex].polygons.append(pverts)
@@ -3041,9 +3040,9 @@
                for k, daeTriangles in daeTrianglesDict.iteritems():
                        ##print k
                        if k != -1:
-                               if not useUV and not bMesh.materials is None 
and len(bMesh.materials) > 0 and k >= 0:
-                                       daeTriangles.material = 
bMesh.materials[k].name
-                               elif mesh.faceUV and (useUV or bMesh.materials 
is None or len(bMesh.materials) == 0):
+                               if not useUV and not mesh.materials is None and 
len(mesh.materials) > 0 and k >= 0:
+                                       daeTriangles.material = 
mesh.materials[k].name
+                               elif mesh.faceUV and (useUV or mesh.materials 
is None or len(mesh.materials) == 0):
                                        daeTriangles.material = uvTextures[k]
                        offsetCount = 0
                        daeInput.offset = offsetCount
@@ -3065,9 +3064,9 @@
                        daeMesh.primitives.append(daeTriangles)
                for k, daePolygons in daePolygonsDict.iteritems():
                        if k != -1:
-                               if not useUV and not bMesh.materials is None 
and len(bMesh.materials) > 0 and k >= 0:
-                                       daePolygons.material = 
bMesh.materials[k].name
-                               elif mesh.faceUV and (useUV or bMesh.materials 
is None or len(bMesh.materials) == 0):
+                               if not useUV and not mesh.materials is None and 
len(mesh.materials) > 0 and k >= 0:
+                                       daePolygons.material = 
mesh.materials[k].name
+                               elif mesh.faceUV and (useUV or mesh.materials 
is None or len(mesh.materials) == 0):
                                        daePolygons.material = uvTextures[k]
                        offsetCount = 0
                        daeInput.offset = offsetCount


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to