예제 #1
0
        public remMesh Clone(bool submeshes, bool boneList, remParser parser, List <remSkin> clonedSkins)
        {
            remMesh mesh = new remMesh(numMats);

            mesh.name = new remId(name);
            rem.CopyUnknowns(this, mesh);

            if (submeshes)
            {
                for (int i = 0; i < numMats; i++)
                {
                    mesh.AddMaterial(new remId(materials[i]));
                }
                mesh.vertices = new remVertex[numVertices];
                for (int i = 0; i < numVertices; i++)
                {
                    mesh.vertices[i] = vertices[i].Clone();
                }
                mesh.faces     = (int[])faces.Clone();
                mesh.faceMarks = (int[])faceMarks.Clone();
            }

            remSkin skin = rem.FindSkin(name, parser.SKIC);

            if (skin != null)
            {
                skin      = skin.Clone();
                skin.mesh = mesh.name;
                clonedSkins.Add(skin);
            }

            return(mesh);
        }
예제 #2
0
파일: remReplace.cs 프로젝트: kkdevs/sb3u
        public static remMesh CreateMesh(WorkspaceMesh mesh, out string[] materialNames, out int[] indices, out bool[] worldCoords, out bool[] replaceSubmeshesOption)
        {
            int numUncheckedSubmeshes = 0;

            foreach (ImportedSubmesh submesh in mesh.SubmeshList)
            {
                if (!mesh.isSubmeshEnabled(submesh))
                {
                    numUncheckedSubmeshes++;
                }
            }
            int numSubmeshes = mesh.SubmeshList.Count - numUncheckedSubmeshes;

            materialNames          = new string[numSubmeshes];
            indices                = new int[numSubmeshes];
            worldCoords            = new bool[numSubmeshes];
            replaceSubmeshesOption = new bool[numSubmeshes];

            remMesh newMesh = new remMesh(numSubmeshes);

            newMesh.name = new remId(mesh.Name);

            List <remVertex> newVertices  = new List <remVertex>();
            List <int>       newFaces     = new List <int>();
            List <int>       newFaceMarks = new List <int>();

            for (int i = 0, submeshIdx = 0; i < numSubmeshes; i++, submeshIdx++)
            {
                while (!mesh.isSubmeshEnabled(mesh.SubmeshList[submeshIdx]))
                {
                    submeshIdx++;
                }

                ImportedSubmesh submesh = mesh.SubmeshList[submeshIdx];

                newMesh.AddMaterial(new remId(submesh.Material));
                materialNames[i]          = submesh.Material;
                indices[i]                = submesh.Index;
                worldCoords[i]            = submesh.WorldCoords;
                replaceSubmeshesOption[i] = mesh.isSubmeshReplacingOriginal(submesh);

                List <ImportedFace> faceList = submesh.FaceList;
                newFaces.Capacity += faceList.Count * 3;
                int[] faceMarks = new int[faceList.Count];
                for (int j = 0; j < faceList.Count; j++)
                {
                    ImportedFace face = faceList[j];
                    for (int k = 0; k < 3; k++)
                    {
                        newFaces.Add(face.VertexIndices[k] + newVertices.Count);
                    }
                    faceMarks[j] = i;
                }
                newFaceMarks.AddRange(faceMarks);

                List <ImportedVertex> vertexList = submesh.VertexList;
                newVertices.Capacity += vertexList.Count;
                for (int j = 0; j < vertexList.Count; j++)
                {
                    ImportedVertex vert      = vertexList[j];
                    remVertex      newVertex = new remVertex();

                    if (submesh.WorldCoords)
                    {
                        newVertex.Position = vert.Position;
                        newVertex.Normal   = vert.Normal;
                    }
                    else
                    {
                        newVertex.Position = new Vector3(vert.Position.X, -vert.Position.Z, vert.Position.Y);
                        newVertex.Normal   = new Vector3(vert.Normal.X, -vert.Normal.Z, vert.Normal.Y);
                    }
                    newVertex.UV = new Vector2(vert.UV[0], vert.UV[1]);
                    newVertices.Add(newVertex);
                }
            }
            newMesh.vertices  = newVertices.ToArray();
            newMesh.faces     = newFaces.ToArray();
            newMesh.faceMarks = newFaceMarks.ToArray();

            return(newMesh);
        }
예제 #3
0
파일: remOps.cs 프로젝트: kkdevs/sb3u
            public remMesh CreateMesh(out remSkin skin)
            {
                remMesh mesh = new remMesh(Count);

                skin      = new remSkin(0);
                skin.mesh = mesh.name = name;

                List <remVertex> newVertices  = new List <remVertex>();
                List <int>       newFaces     = new List <int>();
                List <int>       newFaceMarks = new List <int>();
                Dictionary <remId, Tuple <Matrix, List <int>, List <float> > > boneDic = new Dictionary <remId, Tuple <Matrix, List <int>, List <float> > >();

                for (int i = 0; i < Count; i++)
                {
                    Submesh submesh = this[i];

                    mesh.AddMaterial(submesh.MaterialName);

                    newFaces.Capacity += submesh.FaceList.Count;
                    foreach (int vertexIdx in submesh.FaceList)
                    {
                        newFaces.Add(newVertices.Count + vertexIdx);
                    }
                    int[] faceMarks = new int[submesh.numFaces];
                    for (int j = 0; j < submesh.numFaces; j++)
                    {
                        faceMarks[j] = i;
                    }
                    newFaceMarks.AddRange(faceMarks);

                    if (submesh.BoneList != null)
                    {
                        foreach (remBoneWeights boneWeights in submesh.BoneList)
                        {
                            Tuple <Matrix, List <int>, List <float> > newBone = null;
                            if (!boneDic.TryGetValue(boneWeights.bone, out newBone))
                            {
                                newBone = new Tuple <Matrix, List <int>, List <float> >(boneWeights.matrix, new List <int>(boneWeights.numVertIdxWts), new List <float>(boneWeights.numVertIdxWts));
                                boneDic.Add(boneWeights.bone, newBone);
                            }
                            List <int> vertIdxs = newBone.Item2;
                            vertIdxs.Capacity += boneWeights.vertexIndices.Length;
                            foreach (int vertexIdx in boneWeights.vertexIndices)
                            {
                                vertIdxs.Add(newVertices.Count + vertexIdx);
                            }
                            List <float> weights = newBone.Item3;
                            weights.AddRange(boneWeights.vertexWeights);
                        }
                    }

                    newVertices.AddRange(submesh.VertexList);
                }

                mesh.vertices  = newVertices.ToArray();
                mesh.faces     = newFaces.ToArray();
                mesh.faceMarks = newFaceMarks.ToArray();

                foreach (var pair in boneDic)
                {
                    remBoneWeights newBoneWeights = new remBoneWeights();
                    newBoneWeights.bone          = pair.Key;
                    newBoneWeights.matrix        = pair.Value.Item1;
                    newBoneWeights.vertexIndices = pair.Value.Item2.ToArray();
                    newBoneWeights.vertexWeights = pair.Value.Item3.ToArray();
                    skin.AddChild(newBoneWeights);
                }
                return(mesh);
            }
예제 #4
0
파일: REMParser.cs 프로젝트: kkdevs/sb3u
        private static remMESCsection ReadMeshes(string sectionName, int sectionLength, int numMeshes, byte[] sectionBuffer)
        {
            remMESCsection meshSec   = new remMESCsection(numMeshes);
            int            secBufIdx = 0;

            for (int subSection = 0; subSection < numMeshes; subSection++)
            {
                byte[] type = new byte[4] {
                    sectionBuffer[secBufIdx + 0], sectionBuffer[secBufIdx + 1], sectionBuffer[secBufIdx + 2], sectionBuffer[secBufIdx + 3]
                };
                int length = BitConverter.ToInt32(sectionBuffer, secBufIdx + 4);

                remMesh mesh = new remMesh(5);
                Trace.Assert(TypeCheck(remMesh.ClassType, type));
                mesh.frame = GetIdentifier(sectionBuffer, secBufIdx + 8);

                int numMats = BitConverter.ToInt32(sectionBuffer, secBufIdx + 8 + 256);
                mesh.name = GetIdentifier(sectionBuffer, secBufIdx + 8 + 256 + 4);
                int numFaces    = BitConverter.ToInt32(sectionBuffer, secBufIdx + 8 + 256 + 4 + 256);
                int numVertices = BitConverter.ToInt32(sectionBuffer, secBufIdx + 8 + 256 + 4 + 256 + 4);
                for (int i = 0; i < mesh.unknown.Length; i++)
                {
                    mesh.unknown[i] = BitConverter.ToInt32(sectionBuffer, secBufIdx + 8 + 256 + 4 + 256 + 8 + i * 4);
                }
                for (int i = 0; i < numMats; i++)
                {
                    remId mat = GetIdentifier(sectionBuffer, secBufIdx + 8 + 256 + 4 + 256 + 4 * 4 + i * 256);
                    mesh.AddMaterial(mat);
                }

                mesh.vertices = new remVertex[numVertices];
                int vertBufIdx = secBufIdx + 8 + 256 + 4 + 256 + 4 * 4 + mesh.numMats * 256;
                for (int i = 0; i < numVertices; i++)
                {
                    remVertex vertex = new remVertex();
                    vertex.Position    = new Vector3();
                    vertex.Position[0] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 0);
                    vertex.Position[1] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 4);
                    vertex.Position[2] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 8);

                    vertex.UV    = new Vector2();
                    vertex.UV[0] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 12);
                    vertex.UV[1] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 16);

                    vertex.Normal    = new Vector3();
                    vertex.Normal[0] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 20);
                    vertex.Normal[1] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 24);
                    vertex.Normal[2] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 28);

                    vertex.RGBA = new Color4(BitConverter.ToInt32(sectionBuffer, vertBufIdx + 32));

                    mesh.vertices[i] = vertex;
                    vertBufIdx      += 36;
                }

                mesh.faces = new int[numFaces * 3];
                int faceBufIdx = vertBufIdx;
                for (int i = 0; i < numFaces; i++)
                {
                    mesh.faces[i * 3 + 0] = BitConverter.ToInt32(sectionBuffer, faceBufIdx + 0);
                    mesh.faces[i * 3 + 1] = BitConverter.ToInt32(sectionBuffer, faceBufIdx + 4);
                    mesh.faces[i * 3 + 2] = BitConverter.ToInt32(sectionBuffer, faceBufIdx + 8);
                    faceBufIdx           += 12;
                }

                mesh.faceMarks = new int[numFaces];
                int faceExtraIdx = faceBufIdx;
                for (int i = 0; i < numFaces; i++)
                {
                    mesh.faceMarks[i] = BitConverter.ToInt32(sectionBuffer, faceExtraIdx);
                    faceExtraIdx     += 4;
                }

                meshSec.AddChild(mesh);

                secBufIdx += length;
            }
            if (secBufIdx != sectionLength)
            {
                Report.ReportLog("Warning! MESC section has wrong length.");
            }
            return(meshSec);
        }