public int ReadNodes(byte[] data, int start, FieldInfo f, object target, Dictionary <string, byte[]> other) { //Debug.Log("Loading model " + geometryHeader.modelName + " with supermodel " + supermodelName); int rootOffset = (int)geometryHeader.rootNodeOffset; MDLNode node = new MDLNode(); node.Load(data, other, rootOffset); rootNode = node; return(start); }
void DrawNode(MDLNode node) { using (new EditorGUILayout.VerticalScope("box")) { int node_idx = node.nodeHeader.nodeNumber; string node_name = mdlObj.nameHeader.names[node_idx].name; GUILayout.Label("Node " + node_name); if (node.vertices != null) { GUILayout.Label(" - Vertices: " + node.vertices.Length); GUILayout.Label(" - TVertices: " + node.tVertices.Length); //GUILayout.Label(" - Faces: " + node.trimeshHeader.faces.Length); } foreach (MDLNode child in node.childNodes) { DrawNode(child); } } }
List <MDLNode> GetNodes(MDLNode obj) { if (obj == null) { return(new List <MDLNode>()); } List <MDLNode> nodes = new List <MDLNode>(); // Add the current node nodes.Add(obj); // Add all child nodes foreach (MDLNode n in obj.childNodes) { nodes.AddRange(GetNodes(n)); } return(nodes); }
public int ReadChildren(byte[] data, int offset, FieldInfo f, object target, Dictionary <string, byte[]> other) { int childArrayOffset = (int)nodeHeader.childArray.pointer; MDLNode[] children = new MDLNode[nodeHeader.childArray.used]; //Debug.Log("Node has " + nodeHeader.childArray.used + " children"); // Read from the child array for (int i = 0; i < nodeHeader.childArray.used; i++) { //Debug.Log("Getting child offset from: " + (childArrayOffset + 4 * i)); // Read the offset for the child node int childOffset = BitConverter.ToInt32(data, childArrayOffset + 4 * i); // Load the node children[i] = new MDLNode(); children[i].Load(data, other, childOffset); } childNodes = children; return(offset); }
static GameObject CreateObject(MDLNode node, NodeName[] names, Transform parent, Dictionary <int, (GameObject, MDLNode)> nodeIdx, Dictionary <string, (GameObject, MDLNode)> nodeStr,
static Mesh CreateUnityMesh(MDLNode node) { Mesh mesh = new Mesh(); mesh.SetVertices(new List <Vector3>(node.vertices)); mesh.SetTriangles(new List <int>(node.faces), 0); //mesh.SetNormals(new List<Vector3>(node.tVertices)); if (node.uvs.Length >= 1) { mesh.SetUVs(0, new List <Vector2>(node.uvs[0])); } if (node.uvs.Length >= 2) { mesh.SetUVs(1, new List <Vector2>(node.uvs[1])); } if (node.uvs.Length >= 3) { mesh.SetUVs(2, new List <Vector2>(node.uvs[2])); } if (node.uvs.Length >= 4) { mesh.SetUVs(3, new List <Vector2>(node.uvs[3])); } mesh.RecalculateBounds(); mesh.RecalculateNormals(); mesh.RecalculateTangents(); if (node.skinmeshHeader != null) { BoneWeight[] weights = new BoneWeight[node.vertices.Length]; // This node needs weights for (int i = 0; i < node.vertices.Length; i++) { if (node.weights[i][0] == 0) { throw new System.Exception("Invalid zero weight detected"); } weights[i] = new BoneWeight { weight0 = node.weights[i][0], weight1 = node.weights[i][1], weight2 = node.weights[i][2], weight3 = node.weights[i][3], boneIndex0 = node.weightIdxs[i][0], boneIndex1 = node.weightIdxs[i][1] == -1 ? 0 : node.weightIdxs[i][1], boneIndex2 = node.weightIdxs[i][2] == -1 ? 0 : node.weightIdxs[i][2], boneIndex3 = node.weightIdxs[i][3] == -1 ? 0 : node.weightIdxs[i][3] }; //Debug.Log(weights[i]); } mesh.boneWeights = weights; } //mesh.Optimize(); return(mesh); }