def _write_lods(self, object_, parent_node, group): #prop_name = object_.name prop_name = utils.changed_lod_name(object_.name) node_type = utils.get_node_type(group) if node_type in ('chr', 'ckin'): prop_name = join(object_.name, self._create_properties_name(object_, group)) node = self._doc.createElement("node") node.setAttribute("id", prop_name) node.setAttribute("name", prop_name) node.setIdAttribute("id") self._write_transforms(object_, node) ALLOWED_NODE_TYPES = ('cgf', 'cga', 'chr', 'skin') if utils.get_node_type(group) in ALLOWED_NODE_TYPES: instance = self._create_instance(group, object_) if instance is not None: node.appendChild(instance) udp_extra = self._create_user_defined_property(object_) if udp_extra is not None: node.appendChild(udp_extra) parent_node.appendChild(node) return node
def _create_ik_properties(self, bone, object_): props = "" if utils.is_physic_bone(bone): armature_object = bpy.data.objects[object_.name[:-5]] pose_bone = armature_object.pose.bones[bone.name[:-5]] xIK, yIK, zIK = udp.get_bone_ik_max_min(pose_bone) damping, spring, spring_tension = udp.get_bone_ik_properties( pose_bone) props = join( xIK, '_xdamping={}'.format(damping[1]), '_xspringangle={}'.format(spring[1]), '_xspringtension={}'.format(spring_tension[1]), yIK, '_ydamping={}'.format(damping[0]), '_yspringangle={}'.format(spring[0]), '_yspringtension={}'.format(spring_tension[0]), zIK, '_zdamping={}'.format(damping[2]), '_zspringangle={}'.format(spring[2]), '_zspringtension={}'.format(spring_tension[2]) ) return props
def _write_triangle_list(self, object_, bmesh_, mesh_node, geometry_name): tessfaces = utils.get_tessfaces(bmesh_) current_material_index = 0 for material, materialname in self._m_exporter.get_materials_for_object( object_).items(): triangles = '' triangle_count = 0 normal_uv_index = 0 for face in bmesh_.faces: norm_uv_indices = {} for index in range(0, len(face.verts)): norm_uv_indices[str( face.verts[index].index)] = normal_uv_index + index if face.material_index == current_material_index: for tessface in tessfaces[face.index]: triangle_count += 1 for vert in tessface: normal_uv = norm_uv_indices[str(vert)] dae_vertex = self._write_vertex_data( vert, normal_uv, normal_uv, object_.data.vertex_colors) triangles = join(triangles, dae_vertex) normal_uv_index += len(face.verts) current_material_index += 1 if triangle_count == 0: continue triangle_list = self._doc.createElement('triangles') triangle_list.setAttribute('material', materialname) triangle_list.setAttribute('count', str(triangle_count)) inputs = [] inputs.append(utils.write_input(geometry_name, 0, 'vtx', 'VERTEX')) inputs.append( utils.write_input(geometry_name, 1, 'normal', 'NORMAL')) inputs.append( utils.write_input(geometry_name, 2, 'uvs', 'TEXCOORD')) if object_.data.vertex_colors: inputs.append( utils.write_input(geometry_name, 3, 'vcol', 'COLOR')) for input in inputs: triangle_list.appendChild(input) p = self._doc.createElement('p') p_text = self._doc.createTextNode(triangles) p.appendChild(p_text) triangle_list.appendChild(p) mesh_node.appendChild(triangle_list)
def _write_visual_scene_node(self, objects, parent_node, group): for object_ in objects: if (object_.type == "MESH" or object_.type == 'EMPTY') \ and not utils.is_fakebone(object_) \ and not utils.is_lod_geometry(object_) \ and not utils.is_there_a_parent_releation(object_, group): prop_name = object_.name node_type = utils.get_node_type(group) if node_type in ('chr', 'skin'): prop_name = join( object_.name, self._create_properties_name(object_, group)) node = self._doc.createElement("node") node.setAttribute("id", prop_name) node.setAttribute("name", prop_name) node.setIdAttribute("id") self._write_transforms(object_, node) if not utils.is_dummy(object_): ALLOWED_NODE_TYPES = ('cgf', 'cga', 'chr', 'skin') if node_type in ALLOWED_NODE_TYPES: instance = self._create_instance(group, object_) if instance is not None: node.appendChild(instance) udp_extra = self._create_user_defined_property(object_) if udp_extra is not None: node.appendChild(udp_extra) parent_node.appendChild(node) if utils.is_has_lod(object_): sub_node = node for lod in utils.get_lod_geometries(object_): sub_node = self._write_lods(lod, sub_node, group) if node_type in ('chr', 'skin') and object_.parent \ and object_.parent.type == "ARMATURE": armature = object_.parent self._write_bone_list([utils.get_root_bone(armature)], object_, parent_node, group) armature_physic = utils.get_armature_physic(armature) if armature_physic: self._write_bone_list( [utils.get_root_bone(armature_physic)], armature_physic, parent_node, group) else: self._write_child_objects(object_, node, group) return parent_node
def _write_bone_list(self, bones, object_, parent_node, group): scene = bpy.context.scene bone_names = [] for bone in bones: props_name = self._create_properties_name(bone, group) props_ik = self._create_ik_properties(bone, object_) bone_name = join(bone.name, props_name, props_ik) bone_names.append(bone_name) node = self._doc.createElement("node") node.setAttribute("id", bone_name) node.setAttribute("name", bone_name) node.setIdAttribute("id") fakebone = utils.get_fakebone(bone.name) if fakebone is not None: self._write_transforms(fakebone, node) bone_geometry = utils.get_bone_geometry(bone) if bone_geometry is not None: geo_name = utils.get_geometry_name(group, bone_geometry) instance = self._create_bone_instance( bone_geometry, geo_name) node.appendChild(instance) extra = self._create_physic_proxy_for_bone( object_.parent, bone) if extra is not None: node.appendChild(extra) elif utils.is_physic_bone(bone): bone_geometry = utils.get_bone_geometry(bone) if fakebone is not None: self._write_transforms(fakebone, node) parent_node.appendChild(node) if bone.children: self._write_bone_list(bone.children, object_, node, group)