Beispiel #1
0
        /// <summary>
        /// Tests the load method.
        /// </summary>
        private void TestLoadMethod(string filePath)
        {
            Stream stream = File.OpenRead(filePath);

            stream.Seek(0, SeekOrigin.End);
            long fileSize = stream.Position;

            stream.Seek(0, SeekOrigin.Begin);

            ModelFile modelFile = new ModelFile();

            modelFile.Load(stream);

            long streamPosition = stream.Position;

            stream.Close();

            Assert.AreEqual(fileSize, streamPosition, "Not all of the file was read");
        }
Beispiel #2
0
        private static void ExtractWarpGates(List <string> warpList, int mapId, MapDataFile ifo)
        {
            const string warpStb         = "./3DDATA/stb/warp.stb";
            const string zoneStb         = "./3DDATA/stb/list_zone.stb";
            const string warpGateModel   = "./3DDATA/special/warp_gate01/warp.zms";
            const string decoSpecialList = "./3DDATA/special/list_deco_special.zsc";

            var zoneDataFile = new DataFile();

            zoneDataFile.Load(zoneStb);

            var warpDataFile = new DataFile();

            warpDataFile.Load(warpStb);
            var destCoords = Vector3.Zero;

            ModelListFile modelListFile = new ModelListFile();

            modelListFile.Load(decoSpecialList);

            ModelFile modelFile = new ModelFile();

            modelFile.Load(warpGateModel);
            var vertices = modelFile.Vertices;

            foreach (var warpGate in ifo.WarpPoints)
            {
                var destMapId = int.Parse(warpDataFile[warpGate.WarpID][2]);
                if (zoneDataFile[destMapId][2].ToString().Contains(".zon"))
                {
                    ZoneFile zoneFile = new ZoneFile();
                    zoneFile.Load(zoneDataFile[destMapId][2].ToString()); // Load the zon file

                    foreach (var spawnPoint in zoneFile.SpawnPoints)
                    {
                        if (spawnPoint.Name != warpDataFile[warpGate.WarpID][3].ToString())
                        {
                            continue;
                        }

                        // rose is stupid and we need to do this to get the right coords
                        destCoords = new Vector3(((spawnPoint.Position.X + 520000.00f) / 100.0f), ((spawnPoint.Position.Z + 520000.00f) / 100.0f), ((spawnPoint.Position.Y) / 100.0f));
                        break;
                    }
                }

                var position = new Vector3(((warpGate.Position.X + 520000.00f) / 100.0f), ((warpGate.Position.Y + 520000.00f) / 100.0f), ((warpGate.Position.Z) / 100.0f));

                var rot   = Matrix.RotationQuaternion(modelListFile.Objects[1].Parts[0].Rotation);
                var scale = Matrix.Scaling(modelListFile.Objects[1].Parts[0].Scale);
                var trans = Matrix.Translation(modelListFile.Objects[1].Parts[0].Position);

                var world    = rot * scale * trans;
                var objRot   = Matrix.RotationQuaternion(warpGate.Rotation);
                var objScale = Matrix.Scaling(warpGate.Scale);
                var objTrans = Matrix.Translation(position);

                var objectWorld = objRot * objScale * objTrans;

                Vector3[] vectorPositions = new Vector3[vertices.Count];
                for (int i = 0; i < vertices.Count; i++)
                {
                    vectorPositions[i] = (Vector3)Vector3.Transform(vertices[i].Position, world * objectWorld);
                }

                var boundingBox = BoundingBox.FromPoints(vectorPositions);

                warpList.Add("warp_gate(\"\", "
                             + warpDataFile[warpGate.WarpID][2].ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (destCoords.X).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (destCoords.Y).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (destCoords.Z).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + mapId.ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (boundingBox.Minimum.X).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (boundingBox.Minimum.Y).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (boundingBox.Minimum.Z).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (boundingBox.Maximum.X).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (boundingBox.Maximum.Y).ToString("G", CultureInfo.InvariantCulture) + ", "
                             + (boundingBox.Maximum.Z).ToString("G", CultureInfo.InvariantCulture) + ");\n");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Tests the save method.
        /// </summary>
        private void TestSaveMethod(string filePath)
        {
            ModelFile modelFile = new ModelFile();

            modelFile.Load(filePath);

            MemoryStream savedStream = new MemoryStream();

            modelFile.Save(savedStream);

            savedStream.Seek(0, SeekOrigin.Begin);

            ModelFile savedModelFile = new ModelFile();

            savedModelFile.Load(savedStream);

            savedStream.Close();

            Assert.AreEqual(modelFile.Pool, savedModelFile.Pool, "Pool values do not match");
            Assert.AreEqual(modelFile.BoneTable.Count, savedModelFile.BoneTable.Count, "Bone table counts do not match");

            for (int i = 0; i < modelFile.BoneTable.Count; i++)
            {
                Assert.AreEqual(modelFile.BoneTable[i], savedModelFile.BoneTable[i], "Bone table values do not match");
            }

            Assert.AreEqual(modelFile.Vertices.Count, savedModelFile.Vertices.Count, "Vertex counts do not match");

            for (int i = 0; i < modelFile.Vertices.Count; i++)
            {
                Assert.AreEqual(modelFile.Vertices[i].Position, savedModelFile.Vertices[i].Position, "Vertex position values do not match");
                Assert.AreEqual(modelFile.Vertices[i].Normal, savedModelFile.Vertices[i].Normal, "Vertex normal values do not match");
                Assert.AreEqual(modelFile.Vertices[i].Colour, savedModelFile.Vertices[i].Colour, "Vertex colour values do not match");
                Assert.AreEqual(modelFile.Vertices[i].BoneWeights, savedModelFile.Vertices[i].BoneWeights, "Vertex bone weight values do not match");
                Assert.AreEqual(modelFile.Vertices[i].BoneIndices, savedModelFile.Vertices[i].BoneIndices, "Vertex bone index values do not match");
                Assert.AreEqual(modelFile.Vertices[i].TextureCoordinates[0], savedModelFile.Vertices[i].TextureCoordinates[0], "Vertex texture coordinate values do not match");
                Assert.AreEqual(modelFile.Vertices[i].TextureCoordinates[1], savedModelFile.Vertices[i].TextureCoordinates[1], "Vertex texture coordinate values do not match");
                Assert.AreEqual(modelFile.Vertices[i].TextureCoordinates[2], savedModelFile.Vertices[i].TextureCoordinates[2], "Vertex texture coordinate values do not match");
                Assert.AreEqual(modelFile.Vertices[i].TextureCoordinates[3], savedModelFile.Vertices[i].TextureCoordinates[3], "Vertex texture coordinate values do not match");
                Assert.AreEqual(modelFile.Vertices[i].Tangent, savedModelFile.Vertices[i].Tangent, "Vertex tangent values do not match");
            }

            Assert.AreEqual(modelFile.Indices.Count, savedModelFile.Indices.Count, "Index counts do not match");

            for (int i = 0; i < modelFile.Indices.Count; i++)
            {
                Assert.AreEqual(modelFile.Indices[i], savedModelFile.Indices[i], "Index values do not match");
            }

            Assert.AreEqual(modelFile.Materials.Count, savedModelFile.Materials.Count, "Material counts do not match");

            for (int i = 0; i < modelFile.Materials.Count; i++)
            {
                Assert.AreEqual(modelFile.Materials[i], savedModelFile.Materials[i], "Material values do not match");
            }

            Assert.AreEqual(modelFile.Strips.Count, savedModelFile.Strips.Count, "Strip counts do not match");

            for (int i = 0; i < modelFile.Strips.Count; i++)
            {
                Assert.AreEqual(modelFile.Strips[i], savedModelFile.Strips[i], "Strip values do not match");
            }
        }