public Primitive(int vtxCount) { VertexCount = vtxCount; Matrices.AddRange(new int[vtxCount]); Positions.AddRange(new int[vtxCount]); Normals.AddRange(new int[vtxCount]); Colors.AddRange(new int[vtxCount]); TexCoords.AddRange(new int[vtxCount]); }
public Primitive(Primitive original) { Type = original.Type; VertexCount = original.VertexCount; Matrices.AddRange(original.Matrices); Positions.AddRange(original.Positions); Normals.AddRange(original.Normals); Colors.AddRange(original.Colors); TexCoords.AddRange(original.TexCoords); Processed = original.Processed; NextCandidateCount = original.NextCandidateCount; NextCandidates[0] = original.NextCandidates[0]; NextCandidates[1] = original.NextCandidates[1]; NextCandidates[2] = original.NextCandidates[2]; NextCandidates[3] = original.NextCandidates[3]; }
public void AddTriangle(MeshTriangle _triangle) { int currentVerticeCount = vertices.Count; Vertices.AddRange(_triangle.Vertices); Normals.AddRange(_triangle.Normals); UVs.AddRange(_triangle.UVs); if (SubmeshIndices.Count < _triangle.SubmeshIndex + 1) { for (int i = submeshIndices.Count; i < (_triangle.SubmeshIndex + 1); i++) { SubmeshIndices.Add(new List <int>()); } } for (int i = 0; i < 3; i++) { SubmeshIndices[_triangle.SubmeshIndex].Add(currentVerticeCount + i); } }
public void Append(Model m, Vector3 pivot) { if (m.Vertices.Count < 3) { return; } int oldFacesPos = Faces.Count; Faces.AddRange(m.Faces); for (int i = oldFacesPos; i < Faces.Count; ++i) { for (int j = 0; j < Faces[i].VertexIndices.Length; ++j) { Faces[i].VertexIndices[j] += Vertices.Count; } for (int j = 0; j < Faces[i].NormalIndices.Length; ++j) { Faces[i].NormalIndices[j] += Normals.Count; } for (int j = 0; j < Faces[i].TextureIndices.Length; ++j) { Faces[i].TextureIndices[j] += TexCoords.Count; } } Vertices.AddRange(m.Vertices); Normals.AddRange(m.Normals); TexCoords.AddRange(m.TexCoords); for (int i = 0; i < Vertices.Count; ++i) { Vertices[i] += pivot; } }
public bool TryMerge(SubMesh other) { // return false; if (MaterialID != other.MaterialID) { return(false); } int offset = Positions.Count; Positions.AddRange(other.Positions); Normals.AddRange(other.Normals); Tangents.AddRange(other.Tangents); TexCoords.AddRange(other.TexCoords); VertexColors.AddRange(other.VertexColors); foreach (int index in other.Indices) { Indices.Add(index + offset); } return(true); }
public void Push(SkinnedMeshRenderer renderer) { var mesh = renderer.sharedMesh; if (mesh == null) { Debug.LogWarningFormat("{0} has no mesh", renderer.name); return; } Renderers.Add(renderer); var indexOffset = Positions.Count; var boneIndexOffset = Bones.Count; Positions.AddRange(mesh.vertices); Normals.AddRange(mesh.normals); UV.AddRange(mesh.uv); Tangents.AddRange(mesh.tangents); if (mesh.vertexCount == mesh.boneWeights.Length) { BoneWeights.AddRange(mesh.boneWeights.Select(x => AddBoneIndexOffset(x, boneIndexOffset)).ToArray()); } else { BoneWeights.AddRange(Enumerable.Range(0, mesh.vertexCount).Select(x => new BoneWeight()).ToArray()); } BindPoses.AddRange(mesh.bindposes); Bones.AddRange(renderer.bones); for (int i = 0; i < mesh.subMeshCount; ++i) { var indices = mesh.GetIndices(i).Select(x => x + indexOffset); var mat = renderer.sharedMaterials[i]; var sameMaterialSubMeshIndex = SubMeshes.FindIndex(x => ReferenceEquals(x.Material, mat)); if (sameMaterialSubMeshIndex >= 0) { SubMeshes[sameMaterialSubMeshIndex].Indices.AddRange(indices); } else { SubMeshes.Add(new SubMesh { Indices = indices.ToList(), Material = mat, }); } } for (int i = 0; i < mesh.blendShapeCount; ++i) { var positions = (Vector3[])mesh.vertices.Clone(); var normals = (Vector3[])mesh.normals.Clone(); var tangents = mesh.tangents.Select(x => (Vector3)x).ToArray(); mesh.GetBlendShapeFrameVertices(i, 0, positions, normals, tangents); BlendShapes.Add(new BlendShape { VertexOffset = indexOffset, FrameWeight = mesh.GetBlendShapeFrameWeight(i, 0), Name = mesh.GetBlendShapeName(i), Positions = positions, Normals = normals, Tangents = tangents, }); } }
public void Push(MeshRenderer renderer) { var meshFilter = renderer.GetComponent <MeshFilter>(); if (meshFilter == null) { Debug.LogWarningFormat("{0} has no mesh filter", renderer.name); return; } var mesh = meshFilter.sharedMesh; if (mesh == null) { Debug.LogWarningFormat("{0} has no mesh", renderer.name); return; } Result.SourceMeshRenderers.Add(renderer); Result.MeshMap.Sources.Add(mesh); var indexOffset = Positions.Count; var boneIndexOffset = Bones.Count; Positions.AddRange(mesh.vertices .Select(x => renderer.transform.TransformPoint(x)) ); Normals.AddRange(mesh.normals .Select(x => renderer.transform.TransformVector(x)) ); UV.AddRange(mesh.uv); Tangents.AddRange(mesh.tangents .Select(t => { var v = renderer.transform.TransformVector(t.x, t.y, t.z); return(new Vector4(v.x, v.y, v.z, t.w)); }) ); var self = renderer.transform; var bone = self.parent; if (bone == null) { Debug.LogWarningFormat("{0} is root gameobject.", self.name); return; } var bindpose = bone.worldToLocalMatrix; BoneWeights.AddRange(Enumerable.Range(0, mesh.vertices.Length) .Select(x => new BoneWeight() { boneIndex0 = Bones.Count, weight0 = 1, }) ); BindPoses.Add(bindpose); Bones.Add(bone); for (int i = 0; i < mesh.subMeshCount && i < renderer.sharedMaterials.Length; ++i) { var indices = mesh.GetIndices(i).Select(x => x + indexOffset); var mat = renderer.sharedMaterials[i]; var sameMaterialSubMeshIndex = SubMeshes.FindIndex(x => ReferenceEquals(x.Material, mat)); if (sameMaterialSubMeshIndex >= 0) { SubMeshes[sameMaterialSubMeshIndex].Indices.AddRange(indices); } else { SubMeshes.Add(new SubMesh { Indices = indices.ToList(), Material = mat, }); } } }