Beispiel #1
0
def get_materials(just_selected=False):
    materials = OrderedDict()
    material_counter = {}

    for group in utils.get_mesh_export_nodes(just_selected):
        material_counter[group.name] = 0
        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 = 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 _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)

        node = self._write_visual_scene_node(group.objects, node, group)

        extra = self._create_cryengine_extra(group)
        node.appendChild(extra)
        visual_scene.appendChild(node)
Beispiel #3
0
    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")

        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)
Beispiel #4
0
    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)
Beispiel #5
0
    def _create_xsi_profile(self, node):
        technique_xsi = self._doc.createElement("technique")
        technique_xsi.setAttribute("profile", "XSI")

        xsi_custom_p_set = self._doc.createElement("XSI_CustomPSet")
        xsi_custom_p_set.setAttribute("name", "ExportProperties")

        propagation = self._doc.createElement("propagation")
        propagation.appendChild(self._doc.createTextNode("NODE"))
        xsi_custom_p_set.appendChild(propagation)

        type_node = self._doc.createElement("type")
        type_node.appendChild(
            self._doc.createTextNode("CryExportNodeProperties"))
        xsi_custom_p_set.appendChild(type_node)

        xsi_parameter = self._doc.createElement("XSI_Parameter")
        xsi_parameter.setAttribute("id", "FileType")
        xsi_parameter.setAttribute("type", "Integer")
        xsi_parameter.setAttribute("value", utils.get_xsi_filetype_value(node))
        xsi_custom_p_set.appendChild(xsi_parameter)

        xsi_parameter = self._doc.createElement("XSI_Parameter")
        xsi_parameter.setAttribute("id", "Filename")
        xsi_parameter.setAttribute("type", "Text")
        xsi_parameter.setAttribute("value", utils.get_node_name(node))
        xsi_custom_p_set.appendChild(xsi_parameter)

        xsi_parameter = self._doc.createElement("XSI_Parameter")
        xsi_parameter.setAttribute("id", "Exportable")
        xsi_parameter.setAttribute("type", "Boolean")
        xsi_parameter.setAttribute("value", "1")
        xsi_custom_p_set.appendChild(xsi_parameter)

        xsi_parameter = self._doc.createElement("XSI_Parameter")
        xsi_parameter.setAttribute("id", "MergeObjects")
        xsi_parameter.setAttribute("type", "Boolean")
        xsi_parameter.setAttribute("value",
                                   str(int(self._config.merge_all_nodes)))
        xsi_custom_p_set.appendChild(xsi_parameter)

        technique_xsi.appendChild(xsi_custom_p_set)

        return technique_xsi
Beispiel #6
0
def get_materials(just_selected=False):
    materials = OrderedDict()
    material_counter = {}

    for group in utils.get_mesh_export_nodes(just_selected):
        material_counter[group.name] = 0
        for object in group.objects:
            for i in range(0, len(object.material_slots)):
                slot = object.material_slots[i]
                material = slot.material
                if material is None:
                    continue

                if material not in materials.values():
                    node_name = utils.get_node_name(group)

                    material.name = utils.replace_invalid_rc_characters(
                        material.name)
                    for image in get_textures(material):
                        try:
                            image.name = utils.replace_invalid_rc_characters(
                                image.name)
                        except AttributeError:
                            pass

                    node, index, name, physics = 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]

                    material_name = "{}__{:02d}__{}__{}".format(
                        node, index, name, physics)
                    materials[material_name] = material

    return sort_materials_by_names(materials)
    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
                layers = None

                if node_type == 'i_caf':
                    object_ = utils.get_armature_from_node(group)
                    layers = utils.activate_all_bone_layers(object_)
                elif node_type == 'anm':
                    object_ = group.objects[0]

                frame_start, frame_end = utils.get_animation_node_range(
                    object_, node_name, initial_frame_start, initial_frame_end)
                bpy.context.scene.frame_start = frame_start
                bpy.context.scene.frame_end = frame_end

                print('')
                bcPrint(group.name)
                bcPrint("Animation is being preparing to process.")
                bcPrint("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()
                        utils.recover_bone_layers(object_, layers)

                    bcPrint("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)
Beispiel #8
0
    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