def __write_mesh(self, mesh_name): # Compute tangents if needed. if self.bl_obj.data.appleseed.smooth_tangents and self.bl_obj.data.appleseed.export_uvs: asr.compute_smooth_vertex_tangents(self.__mesh_object) # Compute the mesh signature and the mesh filename. hash = asr.MurmurHash() asr.compute_signature(hash, self.__mesh_object) logger.debug("Mesh info:") logger.debug(" get_triangle_count %s", self.__mesh_object.get_triangle_count()) logger.debug(" get_material_slot_count %s", self.__mesh_object.get_material_slot_count()) logger.debug(" get_vertex_count %s", self.__mesh_object.get_vertex_count()) logger.debug(" get_tex_coords_count %s", self.__mesh_object.get_tex_coords_count()) logger.debug(" get_vertex_normal_count %s", self.__mesh_object.get_vertex_normal_count()) logger.debug(" get_vertex_tangent_count %s", self.__mesh_object.get_vertex_tangent_count()) logger.debug(" get_motion_segment_count %s", self.__mesh_object.get_motion_segment_count()) logger.debug("Computed mesh signature for object %s, hash: %s", self.appleseed_name, hash) # Save the mesh filename for later use. mesh_filename = str(hash) + ".binarymesh" self.__mesh_filenames.append(mesh_filename) # Write the binarymesh file. mesh_abs_path = os.path.join(self.__geom_dir, mesh_filename) if not os.path.exists(mesh_abs_path): logger.debug("Writing mesh for object %s to %s", mesh_name, mesh_abs_path) asr.MeshObjectWriter.write(self.__mesh_object, "mesh", mesh_abs_path) else: logger.debug("Skipping already saved mesh file for mesh %s", mesh_name)
def flush_entities(self, assembly): # Compute tangents if needed. if self.__export_mode != ProjectExportMode.PROJECT_EXPORT: if self.bl_obj.data.appleseed.smooth_tangents and self.bl_obj.data.appleseed.export_uvs: asr.compute_smooth_vertex_tangents(self.__mesh_object) asr_obj_props = self.bl_obj.appleseed mesh_name = self.__mesh_object.get_name() object_instance_params = {'visibility': {'camera': asr_obj_props.camera_visible, 'light': asr_obj_props.light_visible, 'shadow': asr_obj_props.shadow_visible, 'diffuse': asr_obj_props.diffuse_visible, 'glossy': asr_obj_props.glossy_visible, 'specular': asr_obj_props.specular_visible, 'transparency': asr_obj_props.transparency_visible}, 'medium_priority': asr_obj_props.medium_priority, 'ray_bias_method': asr_obj_props.object_ray_bias_method, 'ray_bias_distance': asr_obj_props.object_ray_bias_distance} if asr_obj_props.object_sss_set != "": object_instance_params['sss_set_id'] = asr_obj_props.object_sss_set if self.__export_mode == ProjectExportMode.PROJECT_EXPORT: # Replace the MeshObject by an empty one referencing # the binarymesh files we saved before. params = {} if len(self.__mesh_filenames) == 1: # No motion blur. Write a single filename. params['filename'] = "_geometry/" + self.__mesh_filenames[0] else: # Motion blur. Write one filename per motion pose. params['filename'] = {} for i, f in enumerate(self.__mesh_filenames): params['filename'][str(i)] = "_geometry/" + f self.__mesh_object = asr.MeshObject(mesh_name, params) self._xform_seq.optimize() logger.debug( "Flushing object %s, num instances = %s, num xform keys = %s", self.appleseed_name, self._num_instances, self._xform_seq.size()) if self.__export_mode == ProjectExportMode.INTERACTIVE_RENDER: # We always create assemblies when doing IPR to allow quick xform edits. needs_assembly = True else: # Only create an assembly if the object is instanced or has xform motion blur. needs_assembly = self._num_instances > 1 or self._xform_seq.size() > 1 if needs_assembly: logger.debug("Creating assembly for object %s, name: %s", mesh_name, self.assembly_name) ass = asr.Assembly(self.assembly_name) logger.debug("Creating object instance for object %s, name: %s", mesh_name, self.appleseed_name) obj_inst = asr.ObjectInstance( self.appleseed_name, object_instance_params, self.__object_instance_mesh_name(mesh_name), asr.Transformd(asr.Matrix4d().identity()), self.__front_materials, self.__back_materials) ass.objects().insert(self.__mesh_object) self.__mesh_object = ass.objects().get_by_name(mesh_name) obj_inst_name = obj_inst.get_name() ass.object_instances().insert(obj_inst) self.__obj_inst = ass.object_instances().get_by_name(obj_inst_name) assembly_instance_name = self.assembly_name + "_inst" logger.debug("Creating assembly instance for object %s, name: %s", mesh_name, assembly_instance_name) ass_name = self._insert_entity_with_unique_name(assembly.assemblies(), ass, ass.get_name()) self.__ass = assembly.assemblies().get_by_name(ass_name) ass_inst = asr.AssemblyInstance( assembly_instance_name, {}, ass_name) ass_inst.set_transform_sequence(self._xform_seq) ass_inst_name = self._insert_entity_with_unique_name(assembly.assembly_instances(), ass_inst, ass_inst.get_name()) self.__ass_inst = assembly.assembly_instances().get_by_name(ass_inst_name) if self.__alpha_tex is not None: self.__ass.textures().insert(self.__alpha_tex) if self.__alpha_tex_inst is not None: self.__ass.texture_instances().insert(self.__alpha_tex_inst) else: logger.debug("Creating object instance for object %s, name: %s", mesh_name, self.appleseed_name) mesh_name = self._insert_entity_with_unique_name(assembly.objects(), self.__mesh_object, mesh_name) self.__mesh_object = assembly.objects().get_by_name(mesh_name) obj_inst = asr.ObjectInstance( self.appleseed_name, object_instance_params, self.__object_instance_mesh_name(mesh_name), self._xform_seq.get_earliest_transform(), self.__front_materials, self.__back_materials) obj_inst_name = self._insert_entity_with_unique_name(assembly.object_instances(), obj_inst, obj_inst.get_name()) self.__obj_inst = assembly.object_instances().get_by_name(obj_inst_name) if self.__alpha_tex is not None: assembly.textures().insert(self.__alpha_tex) if self.__alpha_tex_inst is not None: assembly.texture_instances().insert(self.__alpha_tex_inst)
def flush_entities(self, assembly): # Compute tangents if needed. if self.__export_mode != ProjectExportMode.PROJECT_EXPORT: if self.bl_obj.data.appleseed.smooth_tangents and self.bl_obj.data.appleseed.export_uvs: asr.compute_smooth_vertex_tangents(self.__mesh_object) asr_obj_props = self.bl_obj.appleseed mesh_name = self.__mesh_object.get_name() object_instance_params = {'visibility': {'camera': asr_obj_props.camera_visible, 'light': asr_obj_props.light_visible, 'shadow': asr_obj_props.shadow_visible, 'diffuse': asr_obj_props.diffuse_visible, 'glossy': asr_obj_props.glossy_visible, 'specular': asr_obj_props.specular_visible, 'transparency': asr_obj_props.transparency_visible}, 'medium_priority': asr_obj_props.medium_priority, 'photon_target': asr_obj_props.photon_target, 'ray_bias_method': asr_obj_props.object_ray_bias_method, 'ray_bias_distance': asr_obj_props.object_ray_bias_distance} if asr_obj_props.object_sss_set != "": object_instance_params['sss_set_id'] = asr_obj_props.object_sss_set if self.__export_mode == ProjectExportMode.PROJECT_EXPORT: # Replace the MeshObject by an empty one referencing # the binarymesh files we saved before. params = {} if len(self.__mesh_filenames) == 1: # No motion blur. Write a single filename. params['filename'] = "_geometry/" + self.__mesh_filenames[0] else: # Motion blur. Write one filename per motion pose. params['filename'] = {} for i, f in enumerate(self.__mesh_filenames): params['filename'][str(i)] = "_geometry/" + f self.__mesh_object = asr.MeshObject(mesh_name, params) self._xform_seq.optimize() logger.debug( "Flushing object %s, num instances = %s, num xform keys = %s", self.appleseed_name, self._num_instances, self._xform_seq.size()) if self.__export_mode == ProjectExportMode.INTERACTIVE_RENDER: # We always create assemblies when doing IPR to allow quick xform edits. needs_assembly = True else: # Only create an assembly if the object is instanced or has xform motion blur. needs_assembly = self._num_instances > 1 or self._xform_seq.size() > 1 if needs_assembly: logger.debug("Creating assembly for object %s, name: %s", mesh_name, self.assembly_name) ass = asr.Assembly(self.assembly_name) logger.debug("Creating object instance for object %s, name: %s", mesh_name, self.appleseed_name) obj_inst = asr.ObjectInstance( self.appleseed_name, object_instance_params, self.__object_instance_mesh_name(mesh_name), asr.Transformd(asr.Matrix4d().identity()), self.__front_materials, self.__back_materials) ass.objects().insert(self.__mesh_object) self.__mesh_object = ass.objects().get_by_name(mesh_name) obj_inst_name = obj_inst.get_name() ass.object_instances().insert(obj_inst) self.__obj_inst = ass.object_instances().get_by_name(obj_inst_name) assembly_instance_name = self.assembly_name + "_inst" logger.debug("Creating assembly instance for object %s, name: %s", mesh_name, assembly_instance_name) ass_name = self._insert_entity_with_unique_name(assembly.assemblies(), ass, ass.get_name()) self.__ass = assembly.assemblies().get_by_name(ass_name) ass_inst = asr.AssemblyInstance( assembly_instance_name, {}, ass_name) ass_inst.set_transform_sequence(self._xform_seq) ass_inst_name = self._insert_entity_with_unique_name(assembly.assembly_instances(), ass_inst, ass_inst.get_name()) self.__ass_inst = assembly.assembly_instances().get_by_name(ass_inst_name) if self.__alpha_tex is not None: self.__ass.textures().insert(self.__alpha_tex) if self.__alpha_tex_inst is not None: self.__ass.texture_instances().insert(self.__alpha_tex_inst) else: logger.debug("Creating object instance for object %s, name: %s", mesh_name, self.appleseed_name) mesh_name = self._insert_entity_with_unique_name(assembly.objects(), self.__mesh_object, mesh_name) self.__mesh_object = assembly.objects().get_by_name(mesh_name) obj_inst = asr.ObjectInstance( self.appleseed_name, object_instance_params, self.__object_instance_mesh_name(mesh_name), self._xform_seq.get_earliest_transform(), self.__front_materials, self.__back_materials) obj_inst_name = self._insert_entity_with_unique_name(assembly.object_instances(), obj_inst, obj_inst.get_name()) self.__obj_inst = assembly.object_instances().get_by_name(obj_inst_name) if self.__alpha_tex is not None: assembly.textures().insert(self.__alpha_tex) if self.__alpha_tex_inst is not None: assembly.texture_instances().insert(self.__alpha_tex_inst)