Esempio n. 1
0
        protected override void ReadVertex(BinaryReader reader, int v, CDC.Objects.ExportOptions options)
        {
            base.ReadVertex(reader, v, options);

            reader.BaseStream.Position += 0x02;

            _geometry.PositionsPhys[v]    = _geometry.PositionsRaw[v];
            _geometry.PositionsAltPhys[v] = _geometry.PositionsPhys[v];

            _geometry.Vertices[v].colourID = v;

            uint vColour = reader.ReadUInt32();

            if (options.IgnoreVertexColours)
            {
                _geometry.Colours[v] = 0xFFFFFFFF;
            }
            else
            {
                _geometry.Colours[v]    = vColour;
                _geometry.ColoursAlt[v] = _geometry.Colours[v];
            }

            _geometry.Vertices[v].UVID = v;

            Int16 vU = reader.ReadInt16();
            Int16 vV = reader.ReadInt16();

            _geometry.UVs[v].u = vU * 0.00024414062f;
            _geometry.UVs[v].v = vV * 0.00024414062f;

            reader.BaseStream.Position += 0x04;
        }
Esempio n. 2
0
        public String GetTextureName(int materialIndex, CDC.Objects.ExportOptions options)
        {
            String textureName = "";

            if (materialIndex >= 0 && materialIndex < MaterialCount)
            {
                Material material = Materials[materialIndex];
                if (material.textureUsed)
                {
                    //if (this is SR1Model)
                    //{
                    //    if (Platform == Platform.PSX)
                    //    {
                    //        textureName =
                    //            Name.TrimEnd(new char[] { '_' }).ToLower() + "_" +
                    //            string.Format("{0:D4}", material.textureID);
                    //    }
                    //    else
                    //    {
                    //        textureName = string.Format("Texture-{0:D5}", material.textureID);
                    //    }
                    //}
                    //else if (this is SR2Model)
                    //{
                    //    textureName =
                    //        Name.TrimEnd(new char[] { '_' }).ToLower() + "_" +
                    //        string.Format("{0:D4}", material.textureID);
                    //}
                    return(GetTextureName(this, materialIndex, options));
                }
            }

            return(textureName);
        }
        protected override void ReadTypeAVertex(BinaryReader xReader, int v, CDC.Objects.ExportOptions options)
        {
            base.ReadTypeAVertex(xReader, v, options);

            _geometry.PositionsPhys[v]    = _geometry.PositionsRaw[v];
            _geometry.PositionsAltPhys[v] = _geometry.PositionsPhys[v];

            _geometry.Vertices[v].colourID = v;

            //_colours[v] = xReader.ReadUInt32();
            //_coloursAlt[v] = _colours[v];
            uint vColour = xReader.ReadUInt32();

            if (options.IgnoreVertexColours)
            {
                _geometry.Colours[v] = 0xFFFFFFFF;
            }
            else
            {
                _geometry.Colours[v]    = vColour;
                _geometry.ColoursAlt[v] = _geometry.Colours[v];
            }

            _geometry.Vertices[v].UVID = v;

            UInt16 vU = xReader.ReadUInt16();
            UInt16 vV = xReader.ReadUInt16();

            _geometry.UVs[v].u = Utility.BizarreFloatToNormalFloat(vU);
            _geometry.UVs[v].v = Utility.BizarreFloatToNormalFloat(vV);
        }
Esempio n. 4
0
        public static String GetTextureName(SRModel srModel, int materialIndex, CDC.Objects.ExportOptions options)
        {
            CDC.Material material    = srModel.Materials[materialIndex];
            String       textureName = "";

            if (material.textureUsed)
            {
                if (srModel is SR1Model)
                {
                    if (srModel.Platform == CDC.Platform.PSX)
                    {
                        if (options.UseEachUniqueTextureCLUTVariation)
                        {
                            textureName = GetPlayStationTextureNameWithCLUT(srModel.Name, material.textureID, material.clutValue);
                        }
                        else
                        {
                            textureName = GetPlayStationTextureNameDefault(srModel.Name, material.textureID);
                        }
                    }
                    else
                    {
                        textureName = GetSoulReaverPCOrDreamcastTextureName(srModel.Name, material.textureID);
                    }
                }
                else if (srModel is SR2Model ||
                         srModel is DefianceModel)
                {
                    textureName = GetPS2TextureName(srModel.Name, material.textureID);
                }
            }

            return(textureName);
        }
Esempio n. 5
0
        protected override void ReadVertices(BinaryReader xReader, CDC.Objects.ExportOptions options)
        {
            base.ReadVertices(xReader, options);

            ReadArmature(xReader);
            ApplyArmature();
        }
Esempio n. 6
0
        protected virtual void ReadData(BinaryReader reader, CDC.Objects.ExportOptions options)
        {
            // Get the normals
            _geometry.Normals = new Vector[s_aiNormals.Length / 3];
            for (int n = 0; n < _geometry.Normals.Length; n++)
            {
                _geometry.Normals[n].x = ((float)s_aiNormals[n, 0] / 4096.0f);
                _geometry.Normals[n].y = ((float)s_aiNormals[n, 1] / 4096.0f);
                _geometry.Normals[n].z = ((float)s_aiNormals[n, 2] / 4096.0f);
            }

            // Get the vertices
            _geometry.Vertices         = new Vertex[_vertexCount];
            _geometry.PositionsRaw     = new Vector[_vertexCount];
            _geometry.PositionsPhys    = new Vector[_vertexCount];
            _geometry.PositionsAltPhys = new Vector[_vertexCount];
            _geometry.Colours          = new UInt32[_vertexCount];
            _geometry.ColoursAlt       = new UInt32[_vertexCount];
            ReadVertices(reader, options);

            // Get the polygons
            _polygons     = new Polygon[_polygonCount];
            _geometry.UVs = new UV[_indexCount];
            ReadPolygons(reader, options);

            // Generate the output
            GenerateOutput();
        }
Esempio n. 7
0
        protected override void ReadTypeBVertex(BinaryReader reader, int v, CDC.Objects.ExportOptions options)
        {
            base.ReadTypeBVertex(reader, v, options);

            _extraGeometry.PositionsPhys[v]    = _extraGeometry.PositionsRaw[v];
            _extraGeometry.PositionsAltPhys[v] = _extraGeometry.PositionsPhys[v];

            _extraGeometry.Vertices[v].colourID = v;

            _extraGeometry.Vertices[v].UVID = v;

            reader.BaseStream.Position += 0x04;

            _extraGeometry.UVs[v].u = reader.ReadSingle();
            _extraGeometry.UVs[v].v = reader.ReadSingle();

            uint vColour = reader.ReadUInt32();

            if (options.IgnoreVertexColours)
            {
                _extraGeometry.Colours[v] = 0xFFFFFFFF;
            }
            else
            {
                _extraGeometry.Colours[v]    = vColour;
                _extraGeometry.ColoursAlt[v] = _extraGeometry.Colours[v];
            }

            // Spectral colours in here for this type of vertex.
            reader.BaseStream.Position += 0x1C;
        }
        protected virtual void ReadData(BinaryReader xReader, CDC.Objects.ExportOptions options)
        {
            // Get the normals
            _geometry.Normals = new Vector[s_aiNormals.Length / 3];
            for (int n = 0; n < _geometry.Normals.Length; n++)
            {
                // Are these wrong? Different on PC and PS2?
                _geometry.Normals[n].x = s_aiNormals[n, 0];
                _geometry.Normals[n].y = s_aiNormals[n, 1];
                _geometry.Normals[n].z = s_aiNormals[n, 2];

                //_normals[n].x = ((float)s_aiNormals[n, 0] / 4096.0f);
                //_normals[n].y = ((float)s_aiNormals[n, 1] / 4096.0f);
                //_normals[n].z = ((float)s_aiNormals[n, 2] / 4096.0f);
            }

            // Get the vertices
            _geometry.Vertices         = new Vertex[_vertexCount];
            _geometry.PositionsRaw     = new Vector[_vertexCount];
            _geometry.PositionsPhys    = new Vector[_vertexCount];
            _geometry.PositionsAltPhys = new Vector[_vertexCount];
            _geometry.Colours          = new UInt32[_vertexCount];
            _geometry.ColoursAlt       = new UInt32[_vertexCount];
            _geometry.UVs = new UV[_vertexCount];
            ReadVertices(xReader, options);

            // Get the polygons
            _polygons = new Polygon[_polygonCount];
            ReadPolygons(xReader, options);

            HandleDebugRendering(options);

            // Generate the output
            GenerateOutput();
        }
Esempio n. 9
0
        //protected virtual void ReadPolygon(BinaryReader xReader, int p, CDC.Objects.ExportOptions options)
        //{
        //    UInt32 uPolygonPosition = (UInt32)xReader.BaseStream.Position;
        //    // struct _MFace

        //    // struct _Face face
        //    _polygons[p].v1 = _vertices[xReader.ReadUInt16()];
        //    _polygons[p].v2 = _vertices[xReader.ReadUInt16()];
        //    _polygons[p].v3 = _vertices[xReader.ReadUInt16()];

        //    _polygons[p].material = new Material();
        //    _polygons[p].material.visible = true;

        //    _polygons[p].material.textureUsed = (Boolean)(((int)xReader.ReadUInt16() & 0x0200) != 0);

        //    //// unsigned char normal
        //    //byte polygonNormal = xReader.ReadByte();

        //    //// unsigned char flags
        //    //byte flags = xReader.ReadByte();

        //    //_polygons[p].material.textureUsed = true;


        //    if (_polygons[p].material.textureUsed)
        //    {
        //        // WIP
        //        UInt32 uMaterialPosition = _dataStart + xReader.ReadUInt32();
        //        if ((((uMaterialPosition - _materialStart) % 0x10) != 0) &&
        //             ((uMaterialPosition - _materialStart) % 0x18) == 0)
        //        {
        //            _platform = Platform.Dreamcast;
        //        }

        //        xReader.BaseStream.Position = uMaterialPosition;
        //        ReadMaterial(xReader, p, options);

        //        if (_platform == Platform.Dreamcast)
        //        {
        //            xReader.BaseStream.Position += 0x06;
        //        }
        //        else
        //        {
        //            xReader.BaseStream.Position += 0x02;
        //        }

        //        _polygons[p].material.colour = xReader.ReadUInt32();
        //        //_polygons[p].material.colour |= 0xFF000000;   //2019-12-22

        //    }
        //    else
        //    {
        //        _polygons[p].material.colour = xReader.ReadUInt32() | 0xFF000000;
        //    }

        //    Utility.FlipRedAndBlue(ref _polygons[p].material.colour);

        //    xReader.BaseStream.Position = uPolygonPosition + 0x0C;
        //}

        protected override void HandleMaterialRead(BinaryReader xReader, int p, CDC.Objects.ExportOptions options, byte flags, UInt32 colourOrMaterialPosition)
        {
            // WIP
            UInt32 uMaterialPosition = _dataStart + colourOrMaterialPosition;

            if ((((uMaterialPosition - _materialStart) % 0x10) != 0) &&
                ((uMaterialPosition - _materialStart) % 0x18) == 0)
            {
                _platform = Platform.Dreamcast;
            }

            xReader.BaseStream.Position = uMaterialPosition;
            ReadMaterial(xReader, p, options, false);

            if (_platform == Platform.Dreamcast)
            {
                xReader.BaseStream.Position += 0x06;
            }
            else
            {
                xReader.BaseStream.Position += 0x02;
            }

            _polygons[p].material.colour = xReader.ReadUInt32();
            //_polygons[p].material.colour |= 0xFF000000;   //2019-12-22
        }
Esempio n. 10
0
        protected virtual void ReadData(BinaryReader reader, CDC.Objects.ExportOptions options)
        {
            // Get the vertices
            _geometry.Vertices         = new Vertex[_vertexCount];
            _geometry.PositionsRaw     = new Vector[_vertexCount];
            _geometry.PositionsPhys    = new Vector[_vertexCount];
            _geometry.PositionsAltPhys = new Vector[_vertexCount];
            _geometry.Normals          = new Vector[s_aiNormals.Length / 3];
            _geometry.Colours          = new UInt32[_vertexCount];
            _geometry.ColoursAlt       = new UInt32[_vertexCount];
            _geometry.UVs = new UV[_vertexCount];
            ReadTypeAVertices(reader, options);

            // Get the extra vertices
            _extraGeometry.Vertices         = new Vertex[_extraVertexCount];
            _extraGeometry.PositionsRaw     = new Vector[_extraVertexCount];
            _extraGeometry.PositionsPhys    = new Vector[_extraVertexCount];
            _extraGeometry.PositionsAltPhys = new Vector[_extraVertexCount];
            _extraGeometry.Normals          = new Vector[s_aiNormals.Length / 3];
            _extraGeometry.Colours          = new UInt32[_extraVertexCount];
            _extraGeometry.ColoursAlt       = new UInt32[_extraVertexCount];
            _extraGeometry.UVs = new UV[_extraVertexCount];
            ReadTypeBVertices(reader, options);

            // Get the polygons
            _polygons = new Polygon[_polygonCount];
            ReadPolygons(reader, options);

            HandleDebugRendering(options);

            // Generate the output
            GenerateOutput();
        }
Esempio n. 11
0
        protected virtual void ReadVertices(BinaryReader reader, CDC.Objects.ExportOptions options)
        {
            if (_vertexStart == 0 || _vertexCount == 0)
            {
                return;
            }

            reader.BaseStream.Position = _vertexStart;

            for (int v = 0; v < _vertexCount; v++)
            {
                ReadVertex(reader, v, options);
            }

            for (int n = 0; n < _geometry.Normals.Length; n++)
            {
                // Are these wrong? Different on PC and PS2?
                _geometry.Normals[n].x = s_aiNormals[n, 0];
                _geometry.Normals[n].y = s_aiNormals[n, 1];
                _geometry.Normals[n].z = s_aiNormals[n, 2];

                //_normals[n].x = ((float)s_aiNormals[n, 0] / 4096.0f);
                //_normals[n].y = ((float)s_aiNormals[n, 1] / 4096.0f);
                //_normals[n].z = ((float)s_aiNormals[n, 2] / 4096.0f);
            }

            return;
        }
Esempio n. 12
0
 public void ExportCurrentScene(string fileName, ExportOptions options)
 {
     if (CurrentScene != null)
     {
         ExportResourceCDC(CurrentScene.Name, fileName, options);
     }
 }
Esempio n. 13
0
 public void ExportCurrentObject(string fileName, ExportOptions options)
 {
     if (CurrentObject != null)
     {
         ExportResourceCDC(CurrentObject.Name, fileName, options);
     }
 }
Esempio n. 14
0
        protected void ReadVertexColours(BinaryReader reader, CDC.Objects.ExportOptions options)
        {
            if (_vertexColourStart == 0 || _vertexColourCount == 0)
            {
                return;
            }

            reader.BaseStream.Position = _vertexColourStart;

            for (int c = 0; c < _vertexColourCount; c++)
            {
                uint vColour = reader.ReadUInt32() | 0xFF000000;
                if (options.IgnoreVertexColours)
                {
                    _geometry.Colours[c] = 0xFFFFFFFF;
                }
                else
                {
                    _geometry.Colours[c] = vColour;
                }

                Utility.FlipRedAndBlue(ref _geometry.Colours[c]);

                _geometry.ColoursAlt[c] = _geometry.Colours[c];
            }

            return;
        }
Esempio n. 15
0
        protected override void ReadVertex(BinaryReader reader, int v, CDC.Objects.ExportOptions options)
        {
            base.ReadVertex(reader, v, options);

            _geometry.PositionsPhys[v]    = _geometry.PositionsRaw[v];
            _geometry.PositionsAltPhys[v] = _geometry.PositionsPhys[v];

            _geometry.Vertices[v].colourID = v;

            reader.BaseStream.Position += 2;
            uint vColour = reader.ReadUInt32() | 0xFF000000;

            if (options.IgnoreVertexColours)
            {
                _geometry.Colours[v] = 0xFFFFFFFF;
            }
            else
            {
                _geometry.Colours[v] = vColour;
            }

            if (_platform != Platform.Dreamcast)
            {
                Utility.FlipRedAndBlue(ref _geometry.Colours[v]);
            }

            _geometry.ColoursAlt[v] = _geometry.Colours[v];
        }
Esempio n. 16
0
        protected override void ReadPolygons(BinaryReader reader, CDC.Objects.ExportOptions options)
        {
            if (_polygonStart == 0 || _polygonCount == 0)
            {
                return;
            }

            reader.BaseStream.Position = _polygonStart;

            for (UInt16 p = 0; p < _polygonCount; p++)
            {
                ReadPolygon(reader, p, options);
            }

            HandleDebugRendering(options);

            MaterialList xMaterialsList = null;

            for (UInt16 p = 0; p < _polygonCount; p++)
            {
                if (xMaterialsList == null)
                {
                    xMaterialsList = new MaterialList(_polygons[p].material);
                    _materialsList.Add(_polygons[p].material);
                }
                else
                {
                    Material newMaterial = xMaterialsList.AddToList(_polygons[p].material);
                    if (_polygons[p].material != newMaterial)
                    {
                        _polygons[p].material = newMaterial;
                    }
                    else
                    {
                        _materialsList.Add(_polygons[p].material);
                    }
                }
            }

            _materialCount = (UInt32)_materialsList.Count;

            for (UInt32 t = 0; t < _groupCount; t++)
            {
                _trees[t]                   = new Tree();
                _trees[t].mesh              = new Mesh();
                _trees[t].mesh.indexCount   = _indexCount;
                _trees[t].mesh.polygonCount = _polygonCount;
                _trees[t].mesh.polygons     = _polygons;
                _trees[t].mesh.vertices     = _geometry.Vertices;

                _trees[t].mesh.vertices = new Vertex[_indexCount];
                for (UInt16 poly = 0; poly < _polygonCount; poly++)
                {
                    _trees[t].mesh.vertices[(3 * poly) + 0] = _polygons[poly].v1;
                    _trees[t].mesh.vertices[(3 * poly) + 1] = _polygons[poly].v2;
                    _trees[t].mesh.vertices[(3 * poly) + 2] = _polygons[poly].v3;
                }
            }
        }
Esempio n. 17
0
 public void ExportResourceCDC(string resourceName, string filename, ExportOptions options)
 {
     if (resourceName != "" && Resources.ContainsKey(resourceName))
     {
         RenderResourceCDC renderResource = (RenderResourceCDC)Resources[resourceName];
         renderResource.ExportToFile(filename, options);
     }
 }
Esempio n. 18
0
        protected virtual void ReadVertex(BinaryReader reader, int v, CDC.Objects.ExportOptions options)
        {
            _geometry.Vertices[v].positionID = v;

            // Read the local coordinates
            _geometry.PositionsRaw[v].x = (float)reader.ReadInt16();
            _geometry.PositionsRaw[v].y = (float)reader.ReadInt16();
            _geometry.PositionsRaw[v].z = (float)reader.ReadInt16();
        }
Esempio n. 19
0
        protected override void ReadVertex(BinaryReader xReader, int v, CDC.Objects.ExportOptions options)
        {
            base.ReadVertex(xReader, v, options);

            _geometry.PositionsPhys[v]    = _geometry.PositionsRaw[v];
            _geometry.PositionsAltPhys[v] = _geometry.PositionsPhys[v];

            _geometry.Vertices[v].normalID = xReader.ReadUInt16();
        }
        protected virtual void ReadTypeBVertex(BinaryReader xReader, int v, CDC.Objects.ExportOptions options)
        {
            _extraGeometry.Vertices[v].positionID = v;

            // Read the local coordinates
            _extraGeometry.PositionsRaw[v].x = (float)xReader.ReadInt16();
            _extraGeometry.PositionsRaw[v].y = (float)xReader.ReadInt16();
            _extraGeometry.PositionsRaw[v].z = (float)xReader.ReadInt16();
            xReader.BaseStream.Position     += 0x02;
        }
Esempio n. 21
0
        protected virtual void ReadSpectralData(BinaryReader reader, CDC.Objects.ExportOptions options)
        {
            if (m_uSpectralColourStart != 0)
            {
                // Spectral Colours
                reader.BaseStream.Position = m_uSpectralColourStart;
                for (int v = 0; v < _vertexCount; v++)
                {
                    if (reader.BaseStream.Position >= reader.BaseStream.Length)
                    {
                        Console.WriteLine(string.Format("Error: reached end of file after reading {0}/{1} Spectral colours", v + 1, _vertexCount));
                        break;
                    }
                    UInt32 uShiftColour = reader.ReadUInt16();
                    UInt32 uAlpha       = _geometry.ColoursAlt[v] & 0xFF000000;
                    UInt32 uRed         = ((uShiftColour >> 0) & 0x1F) << 0x13;
                    UInt32 uGreen       = ((uShiftColour >> 5) & 0x1F) << 0x0B;
                    UInt32 uBlue        = ((uShiftColour >> 10) & 0x1F) << 0x03;
                    _geometry.ColoursAlt[v] = uAlpha | uRed | uGreen | uBlue;
                }
            }

            if (m_uSpectralVertexStart != 0)
            {
                // Spectral Verticices
                reader.BaseStream.Position = m_uSpectralVertexStart + 0x06;
                int sVertex = reader.ReadInt16();
                reader.BaseStream.Position = m_uSpectralVertexStart;
                int sVertexCount = 0;
                while (sVertex != 0xFFFF)
                {
                    if (reader.BaseStream.Position >= reader.BaseStream.Length)
                    {
                        Console.WriteLine(string.Format("Error: reached end of file after reading reading {0} Spectral vertices", sVertexCount));
                        break;
                    }
                    ShiftVertex xShiftVertex;
                    xShiftVertex.basePos.x = (float)reader.ReadInt16();
                    xShiftVertex.basePos.y = (float)reader.ReadInt16();
                    xShiftVertex.basePos.z = (float)reader.ReadInt16();
                    sVertex = reader.ReadUInt16();

                    if (sVertex == 0xFFFF)
                    {
                        break;
                    }

                    xShiftVertex.offset.x = (float)reader.ReadInt16();
                    xShiftVertex.offset.y = (float)reader.ReadInt16();
                    xShiftVertex.offset.z = (float)reader.ReadInt16();
                    _geometry.PositionsAltPhys[sVertex] = xShiftVertex.offset + xShiftVertex.basePos;
                    sVertexCount++;
                }
            }
        }
Esempio n. 22
0
        protected override void ReadPolygons(BinaryReader reader, CDC.Objects.ExportOptions options)
        {
            if (_polygonStart == 0 || _polygonCount == 0)
            {
                return;
            }

            reader.BaseStream.Position = _polygonStart;

            for (UInt16 p = 0; p < _polygonCount; p++)
            {
                ReadPolygon(reader, p, options);
            }

            List <Mesh>   xMeshes        = new List <Mesh>();
            List <int>    xMeshPositions = new List <int>();
            List <UInt32> treePolygons   = new List <UInt32>((Int32)_vertexCount * 3);

            _trees[0] = ReadBSPTree(reader, treePolygons, m_uBspTreeStart, _trees[0], xMeshes, xMeshPositions, 0);

            HandleDebugRendering(options);

            MaterialList xMaterialsList = null;

            for (UInt16 p = 0; p < _polygonCount; p++)
            {
                if (xMaterialsList == null)
                {
                    xMaterialsList = new MaterialList(_polygons[p].material);
                    _materialsList.Add(_polygons[p].material);
                }
                else
                {
                    Material newMaterial = xMaterialsList.AddToList(_polygons[p].material);
                    if (_polygons[p].material != newMaterial)
                    {
                        _polygons[p].material = newMaterial;
                    }
                    else
                    {
                        _materialsList.Add(_polygons[p].material);
                    }
                }
            }

            _materialCount = (UInt32)_materialsList.Count;

            int currentPosition = 0;

            for (int m = 0; m < xMeshes.Count; m++)
            {
                FinaliseMesh(treePolygons, currentPosition, xMeshes[m]);
                currentPosition = xMeshPositions[m];
            }
        }
Esempio n. 23
0
        public void BuildModel(RenderResource resource, int modelIndex, CDC.Objects.ExportOptions options)
        {
            _srModel = _srFile.Models[modelIndex];
            String modelName = _objectName + "-" + modelIndex.ToString();

            #region Materials

            for (int materialIndex = 0; materialIndex < _srModel.MaterialCount; materialIndex++)
            {
                Material material = new Material();
                material.Visible = _srModel.Materials[materialIndex].visible;
                // Breaks early SR1 builds.
                //material.BlendMode = _srModel.Materials[materialIndex].blendMode;
                //int sortPush = unchecked((sbyte)_srModel.Materials[materialIndex].sortPush);
                //sortPush = 128 - sortPush;
                //material.DepthBias = (1.0f / 100000.0f) * sortPush;
                // Maybe use a hack for warpgates WARPGATE_DrawWarpGateRim indicates tree 3 should have lower priority.
                Color colorDiffuse = Color.FromArgb((int)unchecked (_srModel.Materials[materialIndex].colour));
                material.Diffuse         = colorDiffuse;
                material.TextureFileName = CDC.Objects.Models.SRModel.GetTextureName(_srModel, materialIndex, options);
                Materials.Add(material);
            }

            #endregion

            #region Groups
            for (int groupIndex = 0; groupIndex < _srModel.Groups.Length; groupIndex++)
            {
                Tree   srGroup   = _srModel.Groups[groupIndex];
                String groupName = String.Format("{0}-{1}-group-{2}", _objectName, modelIndex, groupIndex);
                if (srGroup != null && srGroup.mesh != null &&
                    srGroup.mesh.indexCount > 0 && srGroup.mesh.polygonCount > 0)
                {
                    ModelNode    group      = new ModelNode();
                    SRMeshParser meshParser = new SRMeshParser(_objectName, _srFile);
                    meshParser.BuildMesh(resource, modelIndex, groupIndex, 0);
                    foreach (SubMesh subMesh in meshParser.SubMeshes)
                    {
                        // If the mesh parser knew the total submeshes for the model,
                        // then this could be done inside BuildMesh.
                        subMesh.MeshIndex = Meshes.Count;
                        group.SubMeshIndices.Add(SubMeshes.Count);
                        SubMeshes.Add(subMesh);
                    }
                    Meshes.Add(meshParser.Mesh);
                    group.Name = groupName;
                    Groups.Add(group);
                }
            }
            #endregion

            ModelName = modelName;
            Model     = new Model(this);
        }
Esempio n. 24
0
        protected override void ReadPolygons(BinaryReader reader, CDC.Objects.ExportOptions options)
        {
            Material xMaterial = new Material();

            xMaterial.textureID = 0;
            xMaterial.colour    = 0xFFFFFFFF;
            _materialsList.Add(xMaterial);

            List <Mesh>        xMeshes        = new List <Mesh>();
            List <int>         xMeshPositions = new List <int>();
            List <TreePolygon> treePolygons   = new List <TreePolygon>((Int32)_vertexCount * 3);

            for (UInt32 t = 0; t < m_uOctTreeCount; t++)
            {
                reader.BaseStream.Position = m_uOctTreeStart + (t * 0xB0);

                reader.BaseStream.Position += 0x24;
                UInt32 uOctID = reader.ReadUInt32();
                reader.BaseStream.Position += 0x1C;
                UInt32 uDataPos = reader.ReadUInt32();
                reader.BaseStream.Position += 0x48;
                UInt32 materialListPos = reader.ReadUInt32();

                reader.BaseStream.Position = materialListPos;
                UInt32             uNumMaterials = reader.ReadUInt32();
                List <TRLMaterial> materials     = new List <TRLMaterial>();

                for (UInt32 m = 0; m < uNumMaterials; m++)
                {
                    TRLMaterial material = new TRLMaterial();
                    ReadMaterial(reader, ref material);
                    materials.Add(material);
                }

                _trees[t] = ReadOctTree(reader, treePolygons, uDataPos, _trees[t], xMeshes, xMeshPositions, 0, materials);
            }

            _polygonCount = (UInt32)treePolygons.Count;
            _polygons     = new Polygon[_polygonCount];

            int currentPosition = 0, currentPolygon = 0;

            for (int m = 0; m < xMeshes.Count; m++)
            {
                FinaliseMesh(treePolygons, currentPosition, xMeshes[m], xMaterial, ref currentPolygon);
                currentPosition = xMeshPositions[m];
            }

            _materialCount = (UInt32)_materialsList.Count;

            return;
        }
        protected override void ReadObjectData(BinaryReader xReader, CDC.Objects.ExportOptions options)
        {
            // Object name
            xReader.BaseStream.Position = _dataStart + 0x00000024;
            xReader.BaseStream.Position = _dataStart + xReader.ReadUInt32();
            String strModelName = new String(xReader.ReadChars(8));

            _name = Utility.CleanName(strModelName);

            // Texture type
            xReader.BaseStream.Position = _dataStart + 0x44;
            if (options.ForcedPlatform == CDC.Platform.None)
            {
                if (xReader.ReadUInt64() != 0xFFFFFFFFFFFFFFFF)
                {
                    _platform = Platform.PSX;
                }
                else
                {
                    _platform = Platform.PC;
                }
            }
            else
            {
                _platform = options.ForcedPlatform;
            }

            // Model data
            xReader.BaseStream.Position = _dataStart + 0x00000008;
            _modelCount = xReader.ReadUInt16();
            _animCount  = xReader.ReadUInt16();
            _modelStart = _dataStart + xReader.ReadUInt32();
            _animStart  = _dataStart + xReader.ReadUInt32();

            _models = new SR1Model[_modelCount];
            Platform ePlatform = _platform;

            for (UInt16 m = 0; m < _modelCount; m++)
            {
                Console.WriteLine(string.Format("Debug: reading object model {0} / {1}", m, (_modelCount - 1)));
                _models[m] = SR1ObjectModel.Load(xReader, _dataStart, _modelStart, _name, _platform, m, _version, options);
                if ((options.ForcedPlatform == CDC.Platform.None) && (_models[m].Platform == Platform.Dreamcast))
                {
                    ePlatform = _models[m].Platform;
                }
            }
            if (options.ForcedPlatform == CDC.Platform.None)
            {
                _platform = ePlatform;
            }
        }
        protected virtual void ReadSpectralData(BinaryReader xReader, CDC.Objects.ExportOptions options)
        {
            if (m_uSpectralColourStart != 0)
            {
                // Spectral Colours
                xReader.BaseStream.Position = m_uSpectralColourStart;
                for (int v = 0; v < _vertexCount; v++)
                {
                    UInt32 uShiftColour = xReader.ReadUInt32();
                    UInt32 uAlpha       = _geometry.ColoursAlt[v] & 0xFF000000;
                    UInt32 uRGB         = uShiftColour & 0x00FFFFFF;
                    if (options.IgnoreVertexColours)
                    {
                        _geometry.ColoursAlt[v] = 0xFFFFFFFF;
                    }
                    else
                    {
                        _geometry.ColoursAlt[v] = uAlpha | uRGB;
                    }
                }
            }

            if (m_uSpectralVertexStart != 0)
            {
                // Spectral vertices
                xReader.BaseStream.Position = _modelData + 0x2C;
                UInt32 uCurrentIndexPosition  = xReader.ReadUInt32();
                UInt32 uCurrentSpectralVertex = m_uSpectralVertexStart;
                while (true)
                {
                    xReader.BaseStream.Position = uCurrentIndexPosition;
                    Int32 iVertex = xReader.ReadInt32();
                    uCurrentIndexPosition = (UInt32)xReader.BaseStream.Position;

                    if (iVertex == -1)
                    {
                        break;
                    }

                    xReader.BaseStream.Position = uCurrentSpectralVertex;
                    ShiftVertex xShiftVertex;
                    xShiftVertex.basePos.x = (float)xReader.ReadInt16();
                    xShiftVertex.basePos.y = (float)xReader.ReadInt16();
                    xShiftVertex.basePos.z = (float)xReader.ReadInt16();
                    uCurrentSpectralVertex = (UInt32)xReader.BaseStream.Position;

                    _geometry.PositionsAltPhys[iVertex] = xShiftVertex.basePos;
                }
            }
        }
        protected override void ReadHeaderData(BinaryReader xReader, CDC.Objects.ExportOptions options)
        {
            _dataStart = 0;

            xReader.BaseStream.Position = 0x000000AC;
            if (xReader.ReadUInt32() == 0x04C2046E)
            {
                _asset = Asset.Unit;
            }
            else
            {
                _asset = Asset.Object;
            }
        }
Esempio n. 28
0
        protected override void ReadTypeAVertices(BinaryReader xReader, CDC.Objects.ExportOptions options)
        {
            base.ReadTypeAVertices(xReader, options);

            xReader.BaseStream.Position = m_uColourStart;
            for (UInt16 v = 0; v < _vertexCount; v++)
            {
                _geometry.Colours[v]    = xReader.ReadUInt32();
                _geometry.ColoursAlt[v] = _geometry.Colours[v];
            }

            ReadArmature(xReader);
            ApplyArmature();
        }
Esempio n. 29
0
        public void ExportToFile(string fileName, CDC.Objects.ExportOptions options)
        {
            string filePath = Path.GetFullPath(fileName);

            DeleteExistingFile(filePath);
            File.ExportToFile(fileName, options);
            string baseExportDirectory = Path.GetDirectoryName(fileName);

            foreach (string textureFileName in _TexturesAsPNGs.Keys)
            {
                string texturePath = Path.Combine(baseExportDirectory, textureFileName);
                DeleteExistingFile(texturePath);
                _TexturesAsPNGs[textureFileName].Save(texturePath, ImageFormat.Png);
            }
        }
Esempio n. 30
0
        protected virtual void ReadVertices(BinaryReader reader, CDC.Objects.ExportOptions options)
        {
            if (_vertexStart == 0 || _vertexCount == 0)
            {
                return;
            }

            reader.BaseStream.Position = _vertexStart;

            for (int v = 0; v < _vertexCount; v++)
            {
                ReadVertex(reader, v, options);
            }

            return;
        }