public void VertexComponents() { UnityEngine.Mesh resultMesh = _resultMesh.Unity3dObject as UnityEngine.Mesh; Assert.IsTrue(mesh.VerticesLength == resultMesh.vertexCount); // vertices for (int i = 0; i < mesh.VerticesLength; i++) { Vec3 v1 = mesh.GetVertices(i); Vector3 v2 = resultMesh.vertices[i]; Assert.AreEqual(v1.X, v2.x); Assert.AreEqual(v1.Y, v2.y); Assert.AreEqual(v1.Z, v2.z); } // uv Assert.IsTrue(mesh.UvLength == resultMesh.uv.Length); for (int i = 0; i < mesh.UvLength; i++) { Vec2 v1 = mesh.GetUv(i); Vector2 v2 = resultMesh.uv[i]; Assert.AreEqual(v1.X, v2.x); Assert.AreEqual(v1.Y, v2.y); } // uv2 Assert.IsTrue(mesh.Uv2Length == resultMesh.uv2.Length); for (int i = 0; i < mesh.Uv2Length; i++) { Vec2 v1 = mesh.GetUv2(i); Vector2 v2 = resultMesh.uv2[i]; Assert.AreEqual(v1.X, v2.x); Assert.AreEqual(v1.Y, v2.y); } // uv3 Assert.IsTrue(mesh.Uv3Length == resultMesh.uv3.Length); for (int i = 0; i < mesh.Uv3Length; i++) { Vec2 v1 = mesh.GetUv3(i); Vector2 v2 = resultMesh.uv3[i]; Assert.AreEqual(v1.X, v2.x); Assert.AreEqual(v1.Y, v2.y); } // uv4 Assert.IsTrue(mesh.Uv4Length == resultMesh.uv4.Length); for (int i = 0; i < mesh.Uv4Length; i++) { Vec2 v1 = mesh.GetUv4(i); Vector2 v2 = resultMesh.uv4[i]; Assert.AreEqual(v1.X, v2.x); Assert.AreEqual(v1.Y, v2.y); } // normals Assert.IsTrue(mesh.NormalsLength == resultMesh.normals.Length); for (int i = 0; i < mesh.NormalsLength; i++) { Vec3 v1 = mesh.GetNormals(i); Vector3 v2 = resultMesh.normals[i]; Assert.AreEqual(v1.X, v2.x); Assert.AreEqual(v1.Y, v2.y); Assert.AreEqual(v1.Z, v2.z); } // tangents Assert.IsTrue(mesh.TangentsLength == resultMesh.tangents.Length); for (int i = 0; i < mesh.TangentsLength; i++) { Vec4 v1 = mesh.GetTangents(i); Vector4 v2 = resultMesh.tangents[i]; Assert.AreEqual(v1.X, v2.x); Assert.AreEqual(v1.Y, v2.y); Assert.AreEqual(v1.Z, v2.z); Assert.AreEqual(v1.W, v2.w); } // colors Assert.IsTrue(mesh.ColorsLength == resultMesh.colors.Length); for (int i = 0; i < mesh.ColorsLength; i++) { Schema.Color c1 = mesh.GetColors(i); UnityEngine.Color c2 = resultMesh.colors[i]; Assert.AreEqual(c1.A, c2.a); Assert.AreEqual(c1.B, c2.b); Assert.AreEqual(c1.G, c2.g); Assert.AreEqual(c1.R, c2.r); } // colors32 Assert.IsTrue(mesh.Colors32Length == resultMesh.colors32.Length); for (int i = 0; i < mesh.Colors32Length; i++) { Schema.Color32 c1 = mesh.GetColors32(i); UnityEngine.Color32 c2 = resultMesh.colors32[i]; Assert.AreEqual(c1.A, c2.a); Assert.AreEqual(c1.B, c2.b); Assert.AreEqual(c1.G, c2.g); Assert.AreEqual(c1.R, c2.r); } // BoneWeigths Assert.IsTrue(mesh.BoneWeightsLength == resultMesh.boneWeights.Length); for (int i = 0; i < mesh.BoneWeightsLength; i++) { Schema.BoneWeight bw1 = mesh.GetBoneWeights(i); UnityEngine.BoneWeight bw2 = resultMesh.boneWeights[i]; Assert.AreEqual(bw1.BoneIndex0, bw2.boneIndex0); Assert.AreEqual(bw1.BoneIndex1, bw2.boneIndex1); Assert.AreEqual(bw1.BoneIndex2, bw2.boneIndex2); Assert.AreEqual(bw1.BoneIndex3, bw2.boneIndex3); Assert.AreEqual(bw1.Weight0, bw2.weight0); Assert.AreEqual(bw1.Weight1, bw2.weight1); Assert.AreEqual(bw1.Weight2, bw2.weight2); Assert.AreEqual(bw1.Weight3, bw2.weight3); } // 三角面列表 Assert.IsTrue(mesh.TrianglesLength == resultMesh.triangles.Length); for (int i = 0; i < mesh.TrianglesLength; i++) { int t1 = mesh.GetTriangles(i); int t2 = resultMesh.triangles[i]; Assert.AreEqual(t1, t2); } }
public ResourceObject Parse(ByteBuffer bb) { Schema.Mesh fbMesh = Schema.Mesh.GetRootAsMesh(bb); UnityEngine.Mesh mesh = new UnityEngine.Mesh(); Vec3 v3 = new Vec3(); Vec2 v2 = new Vec2(); Vec4 v4 = new Vec4(); Vector3[] inVertices = new Vector3[fbMesh.VerticesLength]; for (int i = 0; i < fbMesh.VerticesLength; i++) { Vec3 v = fbMesh.GetVertices(v3, i); inVertices[i] = new Vector3(v.X, v.Y, v.Z); } mesh.vertices = inVertices; if (fbMesh.UvLength > 0) { Vector2[] uvs = new Vector2[fbMesh.UvLength]; for (int i = 0; i < fbMesh.UvLength; i++) { Vec2 v = fbMesh.GetUv(v2, i); uvs[i] = new Vector2(v.X, v.Y); } mesh.uv = uvs; } if (fbMesh.Uv2Length > 0) { Vector2[] uvs = new Vector2[fbMesh.Uv2Length]; for (int i = 0; i < fbMesh.Uv2Length; i++) { Vec2 v = fbMesh.GetUv2(v2, i); uvs[i] = new Vector2(v.X, v.Y); } mesh.uv2 = uvs; } if (fbMesh.Uv3Length > 0) { Vector2[] uvs = new Vector2[fbMesh.Uv3Length]; for (int i = 0; i < fbMesh.Uv3Length; i++) { Vec2 v = fbMesh.GetUv3(v2, i); uvs[i] = new Vector2(v.X, v.Y); } mesh.uv3 = uvs; } if (fbMesh.Uv4Length > 0) { Vector2[] uvs = new Vector2[fbMesh.Uv4Length]; for (int i = 0; i < fbMesh.Uv4Length; i++) { Vec2 v = fbMesh.GetUv4(v2, i); uvs[i] = new Vector2(v.X, v.Y); } mesh.uv4 = uvs; } if (fbMesh.NormalsLength > 0) { Vector3[] normals = new Vector3[fbMesh.NormalsLength]; for (int i = 0; i < fbMesh.NormalsLength; i++) { Vec3 v = fbMesh.GetNormals(v3, i); normals[i] = new Vector3(v.X, v.Y, v.Z); } mesh.normals = normals; } if (fbMesh.TangentsLength > 0) { Vector4[] tangents = new Vector4[fbMesh.TangentsLength]; for (int i = 0; i < fbMesh.TangentsLength; i++) { Vec4 v = fbMesh.GetTangents(v4, i); tangents[i] = new Vector4(v.X, v.Y, v.Z, v.W); } mesh.tangents = tangents; } if (fbMesh.ColorsLength > 0) { Schema.Color cobj = new Schema.Color(); UnityEngine.Color[] colors = new UnityEngine.Color[fbMesh.ColorsLength]; for (int i = 0; i < fbMesh.ColorsLength; i++) { Schema.Color c = fbMesh.GetColors(cobj, i); colors[i] = new UnityEngine.Color(c.R, c.G, c.B, c.A); } mesh.colors = colors; } if (fbMesh.Colors32Length > 0) { Schema.Color32 cobj = new Schema.Color32(); UnityEngine.Color32[] colors = new UnityEngine.Color32[fbMesh.Colors32Length]; for (int i = 0; i < fbMesh.Colors32Length; i++) { Schema.Color32 c = fbMesh.GetColors32(cobj, i); colors[i] = new UnityEngine.Color32(c.R, c.G, c.B, c.A); } mesh.colors32 = colors; } if (fbMesh.BoneWeightsLength > 0) { Schema.BoneWeight bwobj = new Schema.BoneWeight(); UnityEngine.BoneWeight[] boneWeights = new UnityEngine.BoneWeight[fbMesh.BoneWeightsLength]; for (int i = 0; i < fbMesh.BoneWeightsLength; i++) { Schema.BoneWeight _bw = fbMesh.GetBoneWeights(bwobj, i); UnityEngine.BoneWeight bw = new UnityEngine.BoneWeight(); bw.boneIndex0 = _bw.BoneIndex0; bw.boneIndex1 = _bw.BoneIndex1; bw.boneIndex2 = _bw.BoneIndex2; bw.boneIndex3 = _bw.BoneIndex3; bw.weight0 = _bw.Weight0; bw.weight1 = _bw.Weight1; bw.weight2 = _bw.Weight2; bw.weight3 = _bw.Weight3; boneWeights[i] = bw; } mesh.boneWeights = boneWeights; } int[] triangles = new int[fbMesh.TrianglesLength]; for (int i = 0; i < fbMesh.TrianglesLength; i++) { triangles[i] = fbMesh.GetTriangles(i); } mesh.triangles = triangles; if (fbMesh.SubmeshesLength > 1) { for (int i = 0; i < fbMesh.SubmeshesLength; i++) { Schema.SubMesh sb = fbMesh.GetSubmeshes(i); int[] indices = new int[sb.NumOfTriangles]; for (int j = 0; j < sb.NumOfTriangles; j++) { indices[j] = fbMesh.GetTriangles((int)sb.StartTriangle + j); } mesh.SetIndices(indices, (UnityEngine.MeshTopology)sb.MeshTopology, i); } } if (fbMesh.BindposesLength > 0) { Matrix16 matrixObj = new Matrix16(); Matrix4x4[] matrices = new Matrix4x4[fbMesh.BindposesLength]; for (int i = 0; i < fbMesh.BindposesLength; i++) { Matrix16 _matrix = fbMesh.GetBindposes(matrixObj, i); Matrix4x4 matrix = new Matrix4x4(); matrix.m00 = _matrix.M00; matrix.m01 = _matrix.M01; matrix.m02 = _matrix.M02; matrix.m03 = _matrix.M03; matrix.m10 = _matrix.M10; matrix.m11 = _matrix.M11; matrix.m12 = _matrix.M12; matrix.m13 = _matrix.M13; matrix.m20 = _matrix.M20; matrix.m21 = _matrix.M21; matrix.m22 = _matrix.M22; matrix.m23 = _matrix.M23; matrix.m30 = _matrix.M30; matrix.m31 = _matrix.M31; matrix.m32 = _matrix.M32; matrix.m33 = _matrix.M33; matrices[i] = matrix; } mesh.bindposes = matrices; } Bound _b = fbMesh.GetBound(new Bound()); Vec3 _min = _b.GetMin(v3); Vector3 min = new Vector3(_min.X, _min.Y, _min.Z); Vec3 _max = _b.GetMax(v3); Vector3 max = new Vector3(_max.X, _max.Y, _max.Z); Bounds b = new Bounds(min, max); mesh.bounds = b; string[] joints = new string[fbMesh.JointsLength]; for (int i = 0; i < fbMesh.JointsLength; i++) { joints[i] = fbMesh.GetJoints(i); } return(new ResourceObjectMesh(mesh, joints)); }
public BoneWeight GetBoneWeights(BoneWeight obj, int j) { int o = __offset(30); return(o != 0 ? obj.__init(__vector(o) + j * 32, bb) : null); }