public void Load(System.IO.Stream stream, PoseBoneMatrix last) { byte[] btag = new byte[2]; stream.Read(btag, 0, 2); this.tag = (PoseBoneMatrix.changetag)btag[0]; PoseBoneMatrix.changetag savetag = (PoseBoneMatrix.changetag)btag[1]; //Debug.LogWarning("savetag=" + this.tag + "|" + savetag); if ((savetag & PoseBoneMatrix.changetag.Rotate) > 0) { byte[] buf = new byte[16]; stream.Read(buf, 0, 16); r = BitHelper.ToQuaternion(buf, 0); } else { r = last.r; } if ((savetag & PoseBoneMatrix.changetag.Trans) > 0) { byte[] buf = new byte[12]; stream.Read(buf, 0, 12); t = BitHelper.ToVector3(buf, 0); } else { t = last.t; } if ((savetag & PoseBoneMatrix.changetag.Scale) > 0) { byte[] buf = new byte[12]; stream.Read(buf, 0, 12); s = BitHelper.ToVector3(buf, 0); } else { s = last.s; } }
public static Mesh ReadMesh(byte[] data, int _seek) { Mesh m = new Mesh(); int seek = _seek; int offset; m.name = BitHelper.ReadString(data, seek, out offset); m.name = "Instance"; seek += offset; m.bounds = BitHelper.ToBounds(data, seek); seek += 24; UInt32 vcount = BitConverter.ToUInt32(data, seek); seek += 4; while (true) { byte tag = data[seek]; Debug.Log("ReadMesh tag=" + tag); seek += 1; if (tag == 255) { break; } if (tag == 1)//pos { Vector3[] poss = new Vector3[vcount]; for (int i = 0; i < vcount; i++) { poss[i] = BitHelper.ToVector3(data, seek); seek += 12; //if (i == 0) //{ // Debug.Log("vertices0:" + poss[i]); //} } m.vertices = poss; } if (tag == 2)//color { Color32[] colors = new Color32[vcount]; for (int i = 0; i < vcount; i++) { colors[i] = BitHelper.ToColor32(data, seek); seek += 4; //if (i == 0) //{ // Debug.Log("colors320:" + colors[i]); //} } m.colors32 = colors; } if (tag == 3)//normal { Vector3[] normals = new Vector3[vcount]; for (int i = 0; i < vcount; i++) { normals[i] = BitHelper.ToVector3(data, seek); seek += 12; //if (i == 0) //{ // Debug.Log("normals0:" + normals[i]); //} } m.normals = normals; } if (tag == 4)//uv { Vector2[] uvs = new Vector2[vcount]; for (int i = 0; i < vcount; i++) { uvs[i] = BitHelper.ToVector2(data, seek); seek += 8; //if (i == 0) //{ // Debug.Log("uvs0:" + uvs[i]); //} } m.uv = uvs; } if (tag == 5)//uv2 { Vector2[] uvs = new Vector2[vcount]; for (int i = 0; i < vcount; i++) { uvs[i] = BitHelper.ToVector2(data, seek); seek += 8; } m.uv2 = uvs; } if (tag == 6)//uv3 { Vector2[] uvs = new Vector2[vcount]; for (int i = 0; i < vcount; i++) { uvs[i] = BitHelper.ToVector2(data, seek); seek += 8; } m.uv3 = uvs; } if (tag == 7) { Vector4[] tangents = new Vector4[vcount]; for (int i = 0; i < vcount; i++) { tangents[i] = BitHelper.ToVector4(data, seek); seek += 16; } m.tangents = tangents; } if (tag == 8)//uv4 { Vector2[] uvs = new Vector2[vcount]; for (int i = 0; i < vcount; i++) { uvs[i] = BitHelper.ToVector2(data, seek); seek += 8; } m.uv4 = uvs; } if (tag == 16) { int len = data[seek]; seek++; //s.WriteByte((byte)mesh.bindposes.Length);//length diff Matrix4x4[] bindpose = new Matrix4x4[len]; for (int i = 0; i < len; i++) { Vector3 pos = BitHelper.ToVector3(data, seek); seek += 12; Vector3 scale = BitHelper.ToVector3(data, seek); seek += 12; Quaternion quat = BitHelper.ToQuaternion(data, seek); seek += 16; bindpose[i] = Matrix4x4.TRS(pos, quat, scale); } m.bindposes = bindpose; } if (tag == 17) { BoneWeight[] weights = new BoneWeight[vcount]; for (int i = 0; i < vcount; i++) { weights[i].boneIndex0 = BitConverter.ToInt32(data, seek); seek += 4; weights[i].boneIndex1 = BitConverter.ToInt32(data, seek); seek += 4; weights[i].boneIndex2 = BitConverter.ToInt32(data, seek); seek += 4; weights[i].boneIndex3 = BitConverter.ToInt32(data, seek); seek += 4; weights[i].weight0 = BitConverter.ToSingle(data, seek); seek += 4; weights[i].weight1 = BitConverter.ToSingle(data, seek); seek += 4; weights[i].weight2 = BitConverter.ToSingle(data, seek); seek += 4; weights[i].weight3 = BitConverter.ToSingle(data, seek); seek += 4; } m.boneWeights = weights; } } int subcount = data[seek]; seek += 1; Debug.Log("sub=" + subcount); for (int i = 0; i < subcount; i++) { int tv = BitConverter.ToInt32(data, seek); seek += 4; UInt32 length = BitConverter.ToUInt32(data, seek); Debug.Log("indlength:" + length); seek += 4; int[] indices = new int[length]; for (int j = 0; j < length; j++) { indices[j] = BitConverter.ToInt32(data, seek); seek += 4; } MeshTopology ttv = (MeshTopology)tv; m.SetIndices(indices, (MeshTopology)tv, i); } return(m); }