Пример #1
0
        private void ParseMeshes(Stream stream, long modelPosition, mstudiomodel_t model)
        {
            if (model.meshCount >= 0)
            {
                long nextMeshPosition = modelPosition + model.meshOffset;
                model.theMeshes = new mstudiomesh_t[model.meshCount];

                for (int i = 0; i < model.theMeshes.Length; i++)
                {
                    stream.Position = nextMeshPosition;
                    long meshPosition = nextMeshPosition;

                    model.theMeshes[i] = new mstudiomesh_t();

                    model.theMeshes[i].materialIndex    = DataParser.ReadInt(stream);
                    model.theMeshes[i].modelOffset      = DataParser.ReadInt(stream);
                    model.theMeshes[i].vertexCount      = DataParser.ReadInt(stream);
                    model.theMeshes[i].vertexIndexStart = DataParser.ReadInt(stream);
                    model.theMeshes[i].flexCount        = DataParser.ReadInt(stream);
                    model.theMeshes[i].flexOffset       = DataParser.ReadInt(stream);
                    model.theMeshes[i].materialType     = DataParser.ReadInt(stream);
                    model.theMeshes[i].materialParam    = DataParser.ReadInt(stream);
                    model.theMeshes[i].id     = DataParser.ReadInt(stream);
                    model.theMeshes[i].center = new Vector3(DataParser.ReadFloat(stream), DataParser.ReadFloat(stream), DataParser.ReadFloat(stream));

                    model.theMeshes[i].vertexData = new mstudio_meshvertexdata_t();
                    model.theMeshes[i].vertexData.modelVertexDataP = DataParser.ReadInt(stream);
                    model.theMeshes[i].vertexData.lodVertexCount   = new int[8];
                    for (int j = 0; j < model.theMeshes[i].vertexData.lodVertexCount.Length; j++)
                    {
                        model.theMeshes[i].vertexData.lodVertexCount[j] = DataParser.ReadInt(stream);
                    }

                    model.theMeshes[i].unused = new int[8];
                    for (int j = 0; j < model.theMeshes[i].unused.Length; j++)
                    {
                        model.theMeshes[i].unused[j] = DataParser.ReadInt(stream);
                    }

                    if (model.theMeshes[i].materialType == 1)
                    {
                        model.theEyeballs[model.theMeshes[i].materialParam].theTextureIndex = model.theMeshes[i].materialIndex;
                    }

                    nextMeshPosition = stream.Position;

                    if (model.theMeshes[i].flexCount > 0 && model.theMeshes[i].flexOffset != 0)
                    {
                        ParseFlexes(meshPosition, model.theMeshes[i]);
                    }

                    //stream.Position = model.theMeshes[i].vertexData.modelVertexDataP + model.theMeshes[i].vertexIndexStart;
                    //model.theMeshes[i].vertices = new Vector3[model.theMeshes[i].vertexCount];
                    //for (int j = 0; j < model.theMeshes[i].vertices.Length; j++)
                    //{
                    //    model.theMeshes[i].vertices[j] = new Vector3(FileReader.readFloat(stream), FileReader.readFloat(stream), FileReader.readFloat(stream));
                    //    if (j >= 0 && j < 100) Debug.Log("Mesh " + i + ": V" + j + " " + model.theMeshes[i].vertices[j]);
                    //}
                }
            }
        }
Пример #2
0
        private void ParseEyeballs(Stream stream, long modelPosition, mstudiomodel_t model)
        {
            if (model.eyeballCount >= 0 && model.eyeballOffset != 0)
            {
                model.theEyeballs = new mstudioeyeball_t[model.eyeballCount];

                long nextEyeballPosition = modelPosition + model.eyeballOffset;
                for (int i = 0; i < model.theEyeballs.Length; i++)
                {
                    stream.Position = nextEyeballPosition;
                    long eyeballPosition = nextEyeballPosition;

                    model.theEyeballs[i] = new mstudioeyeball_t();

                    model.theEyeballs[i].nameOffset = DataParser.ReadInt(stream);
                    model.theEyeballs[i].boneIndex  = DataParser.ReadInt(stream);
                    model.theEyeballs[i].org        = new Vector3(DataParser.ReadFloat(stream), DataParser.ReadFloat(stream), DataParser.ReadFloat(stream));
                    model.theEyeballs[i].zOffset    = DataParser.ReadFloat(stream);
                    model.theEyeballs[i].radius     = DataParser.ReadFloat(stream);
                    model.theEyeballs[i].up         = new Vector3(DataParser.ReadFloat(stream), DataParser.ReadFloat(stream), DataParser.ReadFloat(stream));
                    model.theEyeballs[i].forward    = new Vector3(DataParser.ReadFloat(stream), DataParser.ReadFloat(stream), DataParser.ReadFloat(stream));
                    model.theEyeballs[i].texture    = DataParser.ReadInt(stream);

                    model.theEyeballs[i].unused1   = DataParser.ReadInt(stream);
                    model.theEyeballs[i].irisScale = DataParser.ReadFloat(stream);
                    model.theEyeballs[i].unused2   = DataParser.ReadInt(stream);

                    model.theEyeballs[i].upperFlexDesc = new int[3];
                    model.theEyeballs[i].lowerFlexDesc = new int[3];
                    model.theEyeballs[i].upperTarget   = new double[3];
                    model.theEyeballs[i].lowerTarget   = new double[3];

                    model.theEyeballs[i].upperFlexDesc[0] = DataParser.ReadInt(stream);
                    model.theEyeballs[i].upperFlexDesc[1] = DataParser.ReadInt(stream);
                    model.theEyeballs[i].upperFlexDesc[2] = DataParser.ReadInt(stream);
                    model.theEyeballs[i].lowerFlexDesc[0] = DataParser.ReadInt(stream);
                    model.theEyeballs[i].lowerFlexDesc[1] = DataParser.ReadInt(stream);
                    model.theEyeballs[i].lowerFlexDesc[2] = DataParser.ReadInt(stream);
                    model.theEyeballs[i].upperTarget[0]   = DataParser.ReadFloat(stream);
                    model.theEyeballs[i].upperTarget[1]   = DataParser.ReadFloat(stream);
                    model.theEyeballs[i].upperTarget[2]   = DataParser.ReadFloat(stream);
                    model.theEyeballs[i].lowerTarget[0]   = DataParser.ReadFloat(stream);
                    model.theEyeballs[i].lowerTarget[1]   = DataParser.ReadFloat(stream);
                    model.theEyeballs[i].lowerTarget[2]   = DataParser.ReadFloat(stream);

                    model.theEyeballs[i].upperLidFlexDesc = DataParser.ReadInt(stream);
                    model.theEyeballs[i].lowerLidFlexDesc = DataParser.ReadInt(stream);

                    model.theEyeballs[i].unused = new int[4];
                    for (int j = 0; j < model.theEyeballs[i].unused.Length; j++)
                    {
                        model.theEyeballs[i].unused[j] = DataParser.ReadInt(stream);
                    }

                    model.theEyeballs[i].eyeballIsNonFacs = DataParser.ReadByte(stream);

                    model.theEyeballs[i].unused3 = new char[3];
                    for (int j = 0; j < model.theEyeballs[i].unused3.Length; j++)
                    {
                        model.theEyeballs[i].unused3[j] = DataParser.ReadChar(stream);
                    }
                    model.theEyeballs[i].unused4 = new int[7];
                    for (int j = 0; j < model.theEyeballs[i].unused4.Length; j++)
                    {
                        model.theEyeballs[i].unused4[j] = DataParser.ReadInt(stream);
                    }

                    //Set the default value to -1 to distinguish it from value assigned to it by ReadMeshes()
                    model.theEyeballs[i].theTextureIndex = -1;

                    nextEyeballPosition = stream.Position;

                    if (model.theEyeballs[i].nameOffset != 0)
                    {
                        stream.Position = eyeballPosition + model.theEyeballs[i].nameOffset;

                        model.theEyeballs[i].name = DataParser.ReadNullTerminatedString(stream);
                    }
                    else
                    {
                        model.theEyeballs[i].name = "";
                    }
                }
            }
        }