Exemplo n.º 1
0
        public static ColMesh[] SplitMesh(ColMesh mesh)
        {
            var meshes = new List <ColMesh>();

            if (mesh.Vertices.Count > short.MaxValue || mesh.Triangles.Count > short.MaxValue)
            {
                var curMesh       = new ColMesh();
                var curVertCopies = new Dictionary <Vertex, Vertex>();
                foreach (Triangle t in mesh.Triangles)
                {
                    var newTri = new Triangle();
                    newTri.CollisionType = t.CollisionType;
                    for (int i = 0, loopTo = t.ColParams.Length - 1; i <= loopTo; i++)
                    {
                        newTri.ColParams[i] = t.ColParams[i];
                    }
                    for (int i = 0, loopTo1 = t.Vertices.Length - 1; i <= loopTo1; i++)
                    {
                        var v = t.Vertices[i];
                        if (curVertCopies.ContainsKey(v))
                        {
                            newTri.Vertices[i] = curVertCopies[v];
                        }
                        else
                        {
                            var newVert = new Vertex();
                            newVert.X = v.X;
                            newVert.Y = v.Y;
                            newVert.Z = v.Z;
                            curMesh.Vertices.Add(newVert);
                            curVertCopies.Add(v, newVert);
                            newTri.Vertices[i] = newVert;
                        }
                    }

                    if (curMesh.Vertices.Count > short.MaxValue - 3 || curMesh.Triangles.Count >= short.MaxValue)
                    {
                        meshes.Add(curMesh);
                        curMesh = new ColMesh();
                        curVertCopies.Clear();
                    }
                }

                if (!meshes.Contains(curMesh) && curMesh.Triangles.Count > 0 && curMesh.Vertices.Count > 0)
                {
                    meshes.Add(curMesh);
                }
            }
            else
            {
                meshes.Add(mesh);
            }

            return(meshes.ToArray());
        }
Exemplo n.º 2
0
        public static byte[] UsedPolytypes(ColMesh mesh)
        {
            var types = new List <byte>();

            foreach (Triangle tri in mesh.Triangles)
            {
                if (!types.Contains(tri.CollisionType))
                {
                    types.Add(tri.CollisionType);
                }
            }

            return(types.ToArray());
        }
Exemplo n.º 3
0
        public void FromBinaryData(BinaryData s, int dataOffset)
        {
            bool endlessOn = true;

            Mesh = new ColMesh();
            SpecialBoxes.Clear();
            s.Position = dataOffset;

            do
            {
                short curVal = s.ReadInt16();
                switch (curVal)
                {
                case 0x40:     // S T A R T   O F   V E R T I C E S
                               // Lese Eckpunkte / Read Vertices
                    for (int i = 1, loopTo = s.ReadUInt16(); i <= loopTo; i++)
                    {
                        var nVert = new Vertex()
                        {
                            X = s.ReadInt16(),
                            Y = s.ReadInt16(),
                            Z = s.ReadInt16()
                        };
                        Mesh.Vertices.Add(nVert);
                    }

                    // Lese und erstelle Polygone / Read and build polygones
                    if (Mesh.Vertices.Count > 0)
                    {
                        bool ende = false;
                        while (!ende)
                        {
                            short Coltype = s.ReadInt16();
                            if (!Coltype.IsInRange(0x40, 0x44))
                            {
                                for (int i = 1, loopTo1 = s.ReadUInt16(); i <= loopTo1; i++)
                                {
                                    var pol = new Triangle()
                                    {
                                        CollisionType = Conversions.ToByte(Coltype)
                                    };
                                    for (int iv = 0, loopTo2 = pol.Vertices.Count() - 1; iv <= loopTo2; iv++)
                                    {
                                        pol.Vertices[iv] = Mesh.Vertices[s.ReadInt16()];
                                    }
                                    if (ColtypesWithParams.Contains(Conversions.ToByte(Coltype)))
                                    {
                                        for (int ip = 0, loopTo3 = pol.ColParams.Count() - 1; ip <= loopTo3; ip++)
                                        {
                                            pol.ColParams[ip] = s.ReadByte();
                                        }
                                    }

                                    Mesh.Triangles.Add(pol);
                                }
                            }
                            else
                            {
                                ende = true;
                            }
                        }
                    }

                    break;

                case 0x41:     // E N D   O F   0 x 4 0   C O M M A N D
                    break;

                case 0x42:     // E N D   O F   C O L L I S I O N   D A T A
                    endlessOn = false;
                    break;

                case 0x43:     // S P E C I A L   O B J E C T
                    break;

                case 0x44:     // W A T E R   B O X E S
                    SpecialBoxes.AddRange(ReadBoxData(s));
                    break;

                case 0x33:     // M I S T               - Compatibility with old buggy RM versions
                    SpecialBoxes.AddRange(ReadBoxData(s));
                    break;

                case 0x32:     // T O X I C   H A Z E   - Compatibility with old buggy RM versions
                    SpecialBoxes.AddRange(ReadBoxData(s));
                    break;
                }
            }while (endlessOn);
            _Length = (int)(s.Position - dataOffset);
        }