Example #1
0
        private static void ExportSAModelModel(Stream stream, GeometryFormat format, string outFilePath)
        {
            using (var reader = new EndianBinaryReader(stream, Endianness.Little))
            {
                reader.SeekBegin(8);
                var rootNode = reader.ReadObjectOffset <Node>(new NodeReadContext(format));
                if (rootNode == null)
                {
                    Console.WriteLine("Invalid model file");
                    return;
                }

                if (format == GeometryFormat.Basic)
                {
                    BasicAssimpExporter.Animated.Export(rootNode, outFilePath);
                }
                else if (format == GeometryFormat.Chunk)
                {
                    ChunkAssimpExporter.Animated.Export(rootNode, outFilePath);
                }
                else
                {
                    Debug.Assert(false);
                }
            }
        }
Example #2
0
        protected override void writeStruct(Stream stream)
        {
            var world = FindParentById(SectionId.World) as RWWorld;

            if (world == null)
            {
                throw new InvalidDataException("RWAtomicSection has to be child of RWWorld");
            }
            GeometryFormat worldFormat = world.format;

            using BinaryWriter writer = new BinaryWriter(stream);
            writer.Write(matIdBase);
            writer.Write(triangles.Length);
            writer.Write(vertices.Length);
            writer.Write(bbox1);
            writer.Write(bbox2);
            writer.Write(0U);
            writer.Write(0U);

            Array.ForEach(vertices, writer.Write);

            if ((worldFormat & GeometryFormat.Normals) > 0)
            {
                foreach (Normal n in normals)
                {
                    n.Write(writer);
                }
            }

            if ((worldFormat & GeometryFormat.Prelit) > 0)
            {
                foreach (IColor c in colors)
                {
                    c.Write(writer);
                }
            }

            if ((worldFormat & GeometryFormat.Textured) > 0 ||
                (worldFormat & GeometryFormat.Textured2) > 0)
            {
                Array.ForEach(texCoords1, writer.Write);
            }

            if ((worldFormat & GeometryFormat.Textured2) > 0)
            {
                Array.ForEach(texCoords2, writer.Write);
            }

            foreach (VertexTriangle t in triangles)
            {
                t.Write(writer);
            }
        }
Example #3
0
 protected override void readStruct(Stream stream)
 {
     using BinaryReader reader = new BinaryReader(stream);
     rootIsWorldSector         = reader.ReadUInt32() > 0;
     origin          = reader.ReadVector3();
     ambient         = reader.ReadSingle();
     specular        = reader.ReadSingle();
     diffuse         = reader.ReadSingle();
     numTriangles    = reader.ReadUInt32();
     numVertices     = reader.ReadUInt32();
     numPlaneSectors = reader.ReadUInt32();
     numWorldSectors = reader.ReadUInt32();
     colSectorSize   = reader.ReadUInt32();
     format          = EnumUtils.intToFlags <GeometryFormat>(reader.ReadUInt32());
 }
Example #4
0
        protected override void readStruct(Stream stream)
        {
            using BinaryReader reader = new BinaryReader(stream);
            format    = EnumUtils.intToFlags <GeometryFormat>(reader.ReadUInt32());
            triangles = new VertexTriangle[reader.ReadUInt32()];
            UInt32 vertexCount = reader.ReadUInt32();

            morphTargets = new MorphTarget[reader.ReadUInt32()];
            ambient      = reader.ReadSingle();
            specular     = reader.ReadSingle();
            diffuse      = reader.ReadSingle();

            if ((format & GeometryFormat.Native) == 0)
            {
                if ((format & GeometryFormat.Prelit) > 0)
                {
                    colors = new IColor[vertexCount];
                    for (int i = 0; i < colors.Length; i++)
                    {
                        colors[i] = IColor.ReadNew(reader);
                    }
                }

                if ((format & GeometryFormat.Textured) > 0 ||
                    (format & GeometryFormat.Textured2) > 0)
                {
                    int texCount = (((int)format) >> 16) & 0xff;
                    if (texCount == 0)
                    {
                        texCount = ((format & GeometryFormat.Textured2) > 0 ? 2 : 1);
                    }

                    texCoords = new Vector2[texCount][];
                    for (int i = 0; i < texCount; i++)
                    {
                        texCoords[i] = new Vector2[vertexCount];
                        for (int j = 0; j < vertexCount; j++)
                        {
                            texCoords[i][j] = reader.ReadVector2();
                        }
                    }
                }

                for (int i = 0; i < triangles.Length; i++)
                {
                    // Triangle members are ordered differently in RWGeometry...
                    triangles[i].v2 = reader.ReadUInt16();
                    triangles[i].v1 = reader.ReadUInt16();
                    triangles[i].m  = reader.ReadUInt16();
                    triangles[i].v3 = reader.ReadUInt16();
                }
            } // no native format

            for (int i = 0; i < morphTargets.Length; i++)
            {
                morphTargets[i] = new MorphTarget();
                morphTargets[i].bsphereCenter = reader.ReadVector3();
                morphTargets[i].bsphereRadius = reader.ReadSingle();
                morphTargets[i].vertices      = new Vector3[0];
                morphTargets[i].normals       = new Vector3[0];
                bool hasVertices = reader.ReadUInt32() > 0;
                bool hasNormals  = reader.ReadUInt32() > 0;
                if (hasVertices)
                {
                    morphTargets[i].vertices = new Vector3[vertexCount];
                    for (uint j = 0; j < vertexCount; j++)
                    {
                        morphTargets[i].vertices[j] = reader.ReadVector3();
                    }
                }
                if (hasNormals)
                {
                    morphTargets[i].normals = new Vector3[vertexCount];
                    for (uint j = 0; j < vertexCount; j++)
                    {
                        morphTargets[i].normals[j] = reader.ReadVector3();
                    }
                }
            }
        }
Example #5
0
        protected override void readStruct(Stream stream)
        {
            var world = FindParentById(SectionId.World) as RWWorld;

            if (world == null)
            {
                throw new InvalidDataException("RWAtomicSection has to be child of RWWorld");
            }
            GeometryFormat worldFormat = world.format;

            using BinaryReader reader = new BinaryReader(stream);
            matIdBase = reader.ReadUInt32();
            triangles = new VertexTriangle[reader.ReadUInt32()];
            vertices  = new Vector3[reader.ReadUInt32()];
            bbox1     = reader.ReadVector3();
            bbox2     = reader.ReadVector3();
            reader.ReadUInt32(); // unused
            reader.ReadUInt32();

            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i] = reader.ReadVector3();
            }

            if ((worldFormat & GeometryFormat.Normals) > 0)
            {
                normals = new Normal[vertices.Length];
                for (int i = 0; i < normals.Length; i++)
                {
                    normals[i] = Normal.ReadNew(reader);
                }
            }

            if ((worldFormat & GeometryFormat.Prelit) > 0)
            {
                colors = new IColor[vertices.Length];
                for (int i = 0; i < colors.Length; i++)
                {
                    colors[i] = IColor.ReadNew(reader);
                }
            }

            if ((worldFormat & GeometryFormat.Textured) > 0 ||
                (worldFormat & GeometryFormat.Textured2) > 0)
            {
                texCoords1 = new Vector2[vertices.Length];
                for (int i = 0; i < texCoords1.Length; i++)
                {
                    texCoords1[i] = reader.ReadVector2();
                }
            }

            if ((worldFormat & GeometryFormat.Textured2) > 0)
            {
                texCoords2 = new Vector2[vertices.Length];
                for (int i = 0; i < texCoords2.Length; i++)
                {
                    texCoords2[i] = reader.ReadVector2();
                }
            }

            for (int i = 0; i < triangles.Length; i++)
            {
                triangles[i] = VertexTriangle.ReadNew(reader);
            }
        }
Example #6
0
 public GeometryInformation(GeometryFormat format, string filePath)
 {
     Format   = format;
     FilePath = filePath;
 }