Ejemplo n.º 1
0
 def execute(self, context):
     #print("Selected: " + context.active_object.name)
     #print("Filename: %s"%self.properties.filepath)
     
     if not self.properties.filepath:
         indigo_log('Filename not set', message_type='ERROR')
         return {'CANCELLED'}
     
     if self.properties.objectname == '':
         self.properties.objectname = context.active_object.name
     
     try:
         obj = bpy.data.objects[self.properties.objectname]
     except:
         indigo_log('Cannot find mesh data in context', message_type='ERROR')
         return {'CANCELLED'}
     
     mesh = obj.to_mesh(self.scene, True, 'RENDER')
     igmesh_writer.factory(context.scene, obj, self.properties.filepath, mesh, debug=False)
     bpy.data.meshes.remove(mesh)
     
     return {'FINISHED'}
Ejemplo n.º 2
0
 def execute(self, context):
     #print("Selected: " + context.active_object.name)
     #print("Filename: %s"%self.properties.filepath)
     
     if not self.properties.filepath:
         indigo_log('Filename not set', message_type='ERROR')
         return {'CANCELLED'}
     
     if self.properties.objectname == '':
         self.properties.objectname = context.active_object.name
     
     try:
         obj = bpy.data.objects[self.properties.objectname]
     except:
         indigo_log('Cannot find mesh data in context', message_type='ERROR')
         return {'CANCELLED'}
     
     mesh = obj.to_mesh(self.scene, True, 'RENDER')
     igmesh_writer.factory(context.scene, obj, self.properties.filepath, mesh, debug=False)
     bpy.data.meshes.remove(mesh)
     
     return {'FINISHED'}
Ejemplo n.º 3
0
    def exportMeshElement(self, obj):
        if OBJECT_ANALYSIS: indigo_log('exportMeshElement: %s' % obj)

        if obj.type in self.supported_mesh_types:
        
            start_time = time.time()
            
            # If this object has already been exported, then don't export it again. 
            exported_mesh = self.ExportedMeshes.get(obj)
            if exported_mesh != None:
                self.total_mesh_export_time += time.time() - start_time
                return exported_mesh
        
            # Create mesh with applied modifiers
            mesh = obj.to_mesh(self.scene, True, 'RENDER')

            # Compute a hash over the mesh data (vertex positions, material names etc..)
            mesh_hash = self.meshHash(obj, mesh)

            # Form a mesh name like "4618cbf0bc13316135d676fffe0a74fc9b0577909246477354da9254"
            # The name cannot contain the objects name, as the name itself is always unique.
            exported_mesh_name = bpy.path.clean_name(mesh_hash)

            # If this mesh has already been exported, then don't export it again
            exported_mesh = self.MeshesOnDisk.get(exported_mesh_name)
            if exported_mesh != None:
                # Important! If an object is matched to a mesh on disk, add to ExportedMeshes.
                # Otherwise the mesh checksum will be computed over and over again.
                self.ExportedMeshes[obj] = exported_mesh
                bpy.data.meshes.remove(mesh)
                self.total_mesh_export_time += time.time() - start_time
                return exported_mesh

            # Make full mesh path.
            mesh_filename = exported_mesh_name + '.igmesh'
            full_mesh_path = efutil.filesystem_path( '/'.join([self.mesh_dir, mesh_filename]) )
            
            #indigo_log('full_mesh_path: %s'%full_mesh_path)

            # pass the full mesh path to write to filesystem if the object is not a proxy
            if hasattr(obj.data, 'indigo_mesh') and not obj.data.indigo_mesh.valid_proxy():
                if os.path.exists(full_mesh_path) and self.skip_existing_meshes:
                    # if skipping mesh write, parse faces to gather used mats
                    used_mat_indices = set()
                    num_smooth = 0
                    for face in mesh.tessfaces:
                        used_mat_indices.add(face.material_index)
                        if face.use_smooth:
                            num_smooth += 1

                    use_shading_normals = num_smooth > 0
                else:
                    # else let the igmesh_writer do its thing
                    (used_mat_indices, use_shading_normals) = igmesh_writer.factory(self.scene, obj, full_mesh_path, mesh, debug=OBJECT_ANALYSIS)
                    self.mesh_uses_shading_normals[full_mesh_path] = use_shading_normals
            else:
                # Assume igmesh has same number of mats as the proxy object
                used_mat_indices = range(len(obj.material_slots))

            # Remove mesh.
            bpy.data.meshes.remove(mesh)
            
            # Export materials used by this mesh
            if len(obj.material_slots) > 0:
                for mi in used_mat_indices:
                    mat = obj.material_slots[mi].material
                    if mat == None or mat.name in self.ExportedMaterials: continue
                    mat_xmls = mat.indigo_material.factory(obj, mat, self.scene)
                    self.ExportedMaterials[mat.name] = mat_xmls

            # .. put the relative path in the mesh element
            filename = '/'.join([self.rel_mesh_dir, mesh_filename])

            #print('MESH FILENAME %s' % filename)

            shading_normals = True
            if full_mesh_path in self.mesh_uses_shading_normals:
                shading_normals = self.mesh_uses_shading_normals[full_mesh_path]

            xml = obj.data.indigo_mesh.build_xml_element(obj, filename, shading_normals, exported_name=exported_mesh_name)

            mesh_definition = (exported_mesh_name, xml)

            self.MeshesOnDisk[exported_mesh_name] = mesh_definition
            self.ExportedMeshes[obj] = mesh_definition
            
            total = time.time() - start_time
            self.total_mesh_export_time += total
            if self.verbose: indigo_log('Mesh Export took: %f s' % total)

            return mesh_definition