コード例 #1
0
ファイル: RWGeometryStruct.cs プロジェクト: TGEnigma/Amicitia
        internal RWMeshStruct(RWNodeFactory.RWNodeInfo header, BinaryReader reader)
        : base(header)
        {
            _geoFlags = (RWGeometryFlags)reader.ReadUInt16();
            byte numTexCoord = reader.ReadByte();
            _nativeFlag = (RWGeometryNativeFlag)reader.ReadByte();
            int numTris = reader.ReadInt32();
            int numVerts = reader.ReadInt32();
            int numMorphTargets = reader.ReadInt32();

            if (numMorphTargets != SUPPORTED_MORPH_COUNT)
            {
                throw new NotImplementedException("More than 1 morph target are not implemented");
            }

            if (_geoFlags.HasFlagUnchecked(RWGeometryFlags.HasColors))
            {
                _clrArray = reader.ReadColorArray(numVerts);
            }

            if (_geoFlags.HasFlagUnchecked(RWGeometryFlags.HasTexCoord1) ||
               (_geoFlags.HasFlagUnchecked(RWGeometryFlags.HasTexCoord2)))
            {
                _texCoordSets = new Vector2[numTexCoord][];

                for (int i = 0; i < numTexCoord; i++)
                {
                    _texCoordSets[i] = reader.ReadVector2Array(numVerts);
                }
            }

            _triArray = new RWTriangle[numTris];
            for (int i = 0; i < numTris; i++)
            {
                _triArray[i] = new RWTriangle(reader);
            }

            _bSphere = new RWBoundingSphere(reader);

            if (_geoFlags.HasFlagUnchecked(RWGeometryFlags.HasVertices))
            {
                _posArray = reader.ReadVector3Array(numVerts);
            }

            if (_geoFlags.HasFlagUnchecked(RWGeometryFlags.HasNormals))
            {
                _nrmArray = reader.ReadVector3Array(numVerts);
            }
        }
コード例 #2
0
ファイル: RWGeometryStruct.cs プロジェクト: TGEnigma/Amicitia
        // TODO:
        // 1. Implement support for multiple texture coords for newly generated models
        // Priority isn't very high and requires some changes to how the optimizer works

        public RWMeshStruct(
            Vector3[] vertexPositions, Vector3[] vertexNormals, short[] triangleMaterialIDs,
            Vector2[][] textureCoordinateSets, Color[] vertexColors,
            ref byte[][] skinBoneIndices, ref float[][] skinBoneWeights)
            : base(RWNodeType.Struct)
        {
            _geoFlags =
                RWGeometryFlags.HasVertices   |
                RWGeometryFlags.HasNormals     |
                RWGeometryFlags.HasVertexLighting   |
                RWGeometryFlags.CanTriStrip         |
                RWGeometryFlags.ModulateMatColor;

            if (textureCoordinateSets != null)
            {
                if (textureCoordinateSets.Length >= 1)
                    _geoFlags |= RWGeometryFlags.HasTexCoord1;
                //if (uvs.Length >= 2)
                //    GeometryFlags |= RWGeometryFlags.HasTexCoord2;
            }

            if (vertexColors != null)
                _geoFlags |= RWGeometryFlags.HasColors;

            OptimizeData(
                vertexPositions, vertexNormals, 
                textureCoordinateSets != null ? textureCoordinateSets[0] : null, vertexColors,
                triangleMaterialIDs,
                ref skinBoneIndices, ref skinBoneWeights);

            _triArray = Triangles.OrderBy(tri => tri.MatID).ToArray();

            _bSphere = RWBoundingSphere.Calculate(_posArray);

            _nativeFlag = RWGeometryNativeFlag.Default;
        }