def _write_export_node(self, group, visual_scene): if not self._config.export_for_lumberyard: node_name = "CryExportNode_{}".format(utils.get_node_name(group)) node = self._doc.createElement("node") node.setAttribute("id", node_name) node.setIdAttribute("id") else: node_name = "{}".format(utils.get_node_name(group)) node = self._doc.createElement("node") node.setAttribute("id", node_name) node.setAttribute("LumberyardExportNode", "1") node.setIdAttribute("id") bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0)) self._write_transforms(bpy.context.active_object, node) bpy.ops.object.delete(use_global=False) root_objects = [] for object_ in group.objects: if utils.is_visual_scene_node_writed(object_, group): root_objects.append(object_) node = self._write_visual_scene_node(root_objects, node, group) extra = self._create_cryengine_extra(group) node.appendChild(extra) visual_scene.appendChild(node)
def _get_materials(self): materials = OrderedDict() material_counter = {} for group in utils.get_mesh_export_nodes( self._config.export_selected_nodes): material_counter[group.name] = 50 for object in group.objects: for slot in object.material_slots: if slot.material is None: continue if slot.material not in materials: node_name = utils.get_node_name(group) node, index, name, physics = utils.get_material_parts( node_name, slot.material.name) # check if material has no position defined if index == 0: material_counter[group.name] += 1 index = material_counter[group.name] materials[slot.material] = "{}__{:02d}__{}__{}".format( node, index, name, physics) return materials
def __rename_anm_files(self, dae_path): output_path = os.path.dirname(dae_path) for group in utils.get_export_nodes(): if utils.get_node_type(group) == 'anm': node_name = utils.get_node_name(group) src_name = "{}_{}".format(node_name, group.name) src_name = os.path.join(output_path, src_name) if os.path.exists(src_name): dest_name = utils.get_geometry_animation_file_name(group) dest_name = os.path.join(output_path, dest_name) if os.path.exists(dest_name): os.remove(dest_name) os.rename(src_name, dest_name)
def export(self): self._prepare_for_export() root_element = self._doc.createElement('collada') root_element.setAttribute( "xmlns", "http://www.collada.org/2005/11/COLLADASchema") root_element.setAttribute("version", "1.4.1") self._doc.appendChild(root_element) self._create_file_header(root_element) libanmcl = self._doc.createElement("library_animation_clips") libanm = self._doc.createElement("library_animations") root_element.appendChild(libanmcl) root_element.appendChild(libanm) lib_visual_scene = self._doc.createElement("library_visual_scenes") visual_scene = self._doc.createElement("visual_scene") visual_scene.setAttribute("id", "scene") visual_scene.setAttribute("name", "scene") lib_visual_scene.appendChild(visual_scene) root_element.appendChild(lib_visual_scene) initial_frame_active = bpy.context.scene.frame_current initial_frame_start = bpy.context.scene.frame_start initial_frame_end = bpy.context.scene.frame_end ALLOWED_NODE_TYPES = ("i_caf", "anm") for group in utils.get_animation_export_nodes(): node_type = utils.get_node_type(group) node_name = utils.get_node_name(group) if node_type in ALLOWED_NODE_TYPES: object_ = None if node_type == 'i_caf': object_ = utils.get_armature_from_node(group) elif node_type == 'anm': object_ = group.objects[0] frame_start, frame_end = utils.get_animation_node_range( object_, node_name) bpy.context.scene.frame_start = frame_start bpy.context.scene.frame_end = frame_end print('') cbPrint(group.name) cbPrint("Animation is being preparing to process.") cbPrint("Animation frame range are [{} - {}]".format( frame_start, frame_end)) if node_type == 'i_caf': utils.add_fakebones(group) try: self._export_library_animation_clips_and_animations( libanmcl, libanm, group) self._export_library_visual_scenes(visual_scene, group) except RuntimeError: pass finally: if node_type == 'i_caf': utils.remove_fakebones() cbPrint("Animation has been processed.") bpy.context.scene.frame_current = initial_frame_active bpy.context.scene.frame_start = initial_frame_start bpy.context.scene.frame_end = initial_frame_end print('') self._export_scene(root_element) converter = RCInstance(self._config) converter.convert_dae(self._doc)
def _create_properties_name(self, bone, group): bone_name = bone.name.replace("__", "*") node_name = utils.get_node_name(group) props_name = '%{!s}%--PRprops_name={!s}'.format(node_name, bone_name) return props_name