Ejemplo n.º 1
0
        public void readObjects()
        {
            int          reference; //used for storing the reference to structs in files
            BinaryReader file = headerFile.openReader();

            //If the level is outdoors, read the models and the terrain mesh, otherwise just read in the models
            //      the file is layed out differently for outdoors and indoor environments
            models = new List <BiowareModel>();
            lights = new List <Light>();;
            GenericList objectList;

            //If this is an outdoor level read in the terrain
            if (environmentStruct.type == GFFSTRUCTTYPE.ENV_WORLD_TERRAIN)
            {
                models.AddRange(readTerrainModels());
            }

            //then make the generic list for lights and models

            //get to the beginning of the data block
            file.BaseStream.Seek(headerFile.dataOffset, SeekOrigin.Begin);

            //seek to the reference to the terrain world reference (first field in the struct) then go there
            file.BaseStream.Seek(headerFile.structs[TOP_LEVEL_STRUCT_INDEX].fields[0].index, SeekOrigin.Current);

            //seek to the list of objects in the environment struct and go there
            file.BaseStream.Seek(environmentStruct.fields[ENVIRONMENT_LIST_INDEX].index, SeekOrigin.Current);
            reference = file.ReadInt32();
            file.BaseStream.Seek(headerFile.dataOffset + reference, SeekOrigin.Begin);

            //make the list of objects
            objectList = new GenericList(file);

            //If this is an outdoor level this is the list of models and lights
            if (environmentStruct.type == GFFSTRUCTTYPE.ENV_WORLD_TERRAIN)
            {
                lightmapModels.AddRange(readPropModels(objectList, new Vector3(), new Quaternion(), 0));
                lights.AddRange(readLights(objectList, new Vector3(), new Quaternion(), 0));
            }
            //if its an indoor room we have to go farther into the data
            else if (environmentStruct.type == GFFSTRUCTTYPE.ENV_WORLD_ROOM)
            {
                //get to the area struct data
                file.BaseStream.Seek(headerFile.dataOffset + objectList[0], SeekOrigin.Begin);


                //Get the layout name
                file.BaseStream.Seek(areaStruct.fields[AREA_PROPERTY_INDEX].index + propertyStruct.fields[PROPERTY_CHILDREN_INDEX].index, SeekOrigin.Current);
                reference = file.ReadInt32();
                file.BaseStream.Seek(headerFile.dataOffset + reference, SeekOrigin.Begin);
                GenericList propertyList = new GenericList(file);

                file.BaseStream.Seek(headerFile.dataOffset + propertyList[AREA_LAYOUT_NAME_INDEX] + propertyStruct.fields[PROPERTY_VALUE_INDEX].index, SeekOrigin.Begin);
                layoutName = IOUtilities.readECString(file, headerFile.dataOffset + file.ReadInt32());

                //now get the reference to the room list and make it
                file.BaseStream.Seek(headerFile.dataOffset + objectList[0], SeekOrigin.Begin);

                file.BaseStream.Seek(areaStruct.fields[AREA_LIST_INDEX].index, SeekOrigin.Current);
                reference = file.ReadInt32();
                file.BaseStream.Seek(headerFile.dataOffset + reference, SeekOrigin.Begin);
                GenericList roomList = new GenericList(file);


                //for each room in the list
                for (int i = 0; i < roomList.length; i++)
                {
                    if (headerFile.structs[(int)roomList.type[i].id].type == GFFSTRUCTTYPE.EVN_ROOM)
                    {
                        //get the room position
                        file.BaseStream.Seek(headerFile.dataOffset + roomList[i] + roomStruct.fields[ROOM_POSITION_INDEX].index, SeekOrigin.Begin);
                        Vector3 position = new Vector3(file.ReadSingle(), file.ReadSingle(), file.ReadSingle());

                        //get the room orientation
                        file.BaseStream.Seek(headerFile.dataOffset + roomList[i] + roomStruct.fields[ROOM_ROTATION_INDEX].index, SeekOrigin.Begin);
                        Quaternion orientation = new Quaternion(file.ReadSingle(), file.ReadSingle(), file.ReadSingle(), file.ReadSingle());

                        //get the room id
                        file.BaseStream.Seek(headerFile.dataOffset + roomList[i] + roomStruct.fields[ROOM_ID_INDEX].index, SeekOrigin.Begin);
                        int id = file.ReadInt32();

                        //seek to the object list
                        file.BaseStream.Seek(headerFile.dataOffset + roomList[i] + roomStruct.fields[ROOM_OBJECT_LIST_INDEX].index, SeekOrigin.Begin);
                        reference = file.ReadInt32();
                        file.BaseStream.Seek(headerFile.dataOffset + reference, SeekOrigin.Begin);
                        //Make the list of objects in the room
                        objectList = new GenericList(file);
                        //Add the models and lights to the lists
                        lightmapModels.AddRange(readPropModels(objectList, position, orientation, id));
                        lights.AddRange(readLights(objectList, position, orientation, id));
                    }
                }
            }
            generatePatches(baseModels);

            file.Close();
        }
Ejemplo n.º 2
0
        public void readData()
        {
            BinaryReader file = binaryFile.openReader();
            int          reference;

            //Get the name of the mmh file
            file.BaseStream.Seek(binaryFile.dataOffset + binaryFile.structs[0].fields[MMH_NAME_INDEX].index, SeekOrigin.Begin);
            mmhName = IOUtilities.readECString(file, binaryFile.dataOffset + file.ReadInt32()).ToLower();

            //Get the name of the msh file
            file.BaseStream.Seek(binaryFile.dataOffset + binaryFile.structs[0].fields[MSH_NAME_INDEX].index, SeekOrigin.Begin);
            mshName = IOUtilities.readECString(file, binaryFile.dataOffset + file.ReadInt32()).ToLower();

            //Get the total number of bones in the mmh
            file.BaseStream.Seek(binaryFile.dataOffset + binaryFile.structs[0].fields[TOTAL_BONES_INDEX].index, SeekOrigin.Begin);
            numBones = file.ReadInt32();

            //Apparently fx models have an extra field...
            isFXModel = binaryFile.structs[0].fields.Length == 8;
            if (isFXModel)
            {
                file.Close();
                return;
            }

            //Get the children list (should only contain GOB)
            file.BaseStream.Seek(binaryFile.dataOffset + binaryFile.structs[0].fields[TOP_LEVEL_CHILDREN_INDEX].index, SeekOrigin.Begin);
            reference = file.ReadInt32();
            file.BaseStream.Seek(binaryFile.dataOffset + reference, SeekOrigin.Begin);
            GenericList childrenList = new GenericList(file);

            //Get the children of the GOB object
            //Sometimes its a node struct, sometimes its a mshh struct . . .

            if ((int)(childrenList.type[0].id) == nodeStructIndex)
            {
                file.BaseStream.Seek(binaryFile.dataOffset + childrenList[0] + nodeStruct.fields[GOB_CHILDREN_INDEX].index, SeekOrigin.Begin);
            }
            else if ((int)(childrenList.type[0].id) == meshChunkInfoIndex)
            {
                file.BaseStream.Seek(binaryFile.dataOffset + childrenList[0] + meshChunkInfoStruct.fields[MSH_CHUNK_CHILDREN_INDEX].index, SeekOrigin.Begin);
            }

            reference = file.ReadInt32();
            file.BaseStream.Seek(binaryFile.dataOffset + reference, SeekOrigin.Begin);
            childrenList = new GenericList(file);


            //Find the mesh
            GFF temp = ResourceManager.findFile <GFF>(mshName);

            //If its not there throw an exception cause we need it
            if (temp == null)
            {
                Console.WriteLine("Could not find mesh file \"{0}\".", mshName);
                file.Close();
                return;
                //throw new Exception("COULD NOT FIND MESH FILE, LOOK AT CONSOLE!!!!!!");
            }

            loadedMesh = true;

            //Make the mesh
            mesh = new ModelMesh(temp);

            //For each thing in the child list
            for (int i = 0; i < childrenList.length; i++)
            {
                //If the child is a mesh chunk info struct
                if ((int)childrenList.type[i].id == meshChunkInfoIndex)
                {
                    //Fill in the missing mesh chunk info
                    updateChunk(file, binaryFile.dataOffset + childrenList[i], new Vector3(), new Quaternion());
                }
            }
            file.Close();
        }