Exemple #1
0
		public void Read() {

			using( FileStream fs = File.OpenRead( mFilename ) ) {
				using( BinaryReader bin = new BinaryReader( fs ) ) {

					mConstant00 = bin.ReadInt32();
					int bCount = bin.ReadInt32();
					mBones = new List<Matrix>();
					for( int i = 0; i < bCount; i++ ) {
						mBones.Add( bin.ReadMatrix() );
					}

					int vCount = bin.ReadInt32();
					mVertices = new List<Vertice>();
					for( int i = 0; i < vCount; i++ ) {
						mVertices.Add( bin.ReadVertice() );
					}

					int fCount = bin.ReadInt32();
					mFaces = new List<Face>();
					for( int i = 0; i < fCount; i++ ) {
						mFaces.Add( bin.ReadFace() );
					}


				}
			}

		}
		public RoRsmMeshTransMatrix(BinaryReader bin, GenericFileFormatVersion version)
			: base(bin, version) {
			Matrix = bin.ReadMatrix();
			Position = bin.ReadVector3();
			RotationAngle = bin.ReadSingle();
			RotationAxis = bin.ReadVector3();
			Scale = bin.ReadVector3();
		}
 private static void ReadWMODoodadDefs(BinaryReader br, ExtractedWMO wmo)
 {
     var numSets = br.ReadInt32();
     var setList = new List<Dictionary<int, ExtractedWMOM2Definition>>(numSets);
     for (var i = 0; i < numSets; i++)
     {
         var numDefs = br.ReadInt32();
         var defDict = new Dictionary<int, ExtractedWMOM2Definition>(numDefs);
         for (var j = 0; j < numDefs; j++)
         {
             var key = br.ReadInt32();
             var def = new ExtractedWMOM2Definition {
                                                        FilePath = br.ReadString(),
                                                        Position = br.ReadVector3(),
                                                        Extents = br.ReadBoundingBox(),
                                                        WMOToModel = br.ReadMatrix(),
                                                        ModeltoWMO = br.ReadMatrix()
                                                    };
             defDict.Add(key, def);
         }
         setList.Add(defDict);
     }
     wmo.WMOM2Defs = setList;
 }
Exemple #4
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);
            m_Name = reader.ReadNameA4();

            int numSubMeshes = reader.ReadInt32();
            m_SubMeshes = new List<SubMesh>(numSubMeshes);
            for (int i = 0; i < numSubMeshes; i++)
            {
                m_SubMeshes.Add(new SubMesh(stream));
            }

            m_Shapes = new BlendShapeData(stream);

            int numBones = reader.ReadInt32();
            m_BindPose = new List<Matrix>(numBones);
            for (int i = 0; i < numBones; i++)
            {
                m_BindPose.Add(reader.ReadMatrix());
            }

            int numHashes = reader.ReadInt32();
            m_BoneNameHashes = new List<uint>(numHashes);
            for (int i = 0; i < numHashes; i++)
            {
                m_BoneNameHashes.Add(reader.ReadUInt32());
            }

            m_RootBoneNameHash = reader.ReadUInt32();
            m_MeshCompression = reader.ReadByte();
            m_StreamCompression = reader.ReadByte();
            m_IsReadable = reader.ReadBoolean();
            m_KeepVertices = reader.ReadBoolean();
            m_KeepIndices = reader.ReadBoolean();
            reader.BaseStream.Position += 3;

            int numIndexBytes = reader.ReadInt32();
            m_IndexBuffer = reader.ReadBytes(numIndexBytes);
            if ((numIndexBytes & 3) > 0)
            {
                reader.BaseStream.Position += 4 - (numIndexBytes & 3);
            }

            int numInfluences = reader.ReadInt32();
            m_Skin = new List<BoneInfluence>(numInfluences);
            for (int i = 0; i < numInfluences; i++)
            {
                m_Skin.Add(new BoneInfluence(stream));
            }

            m_VertexData = new VertexData(stream);
            m_CompressedMesh = new CompressedMesh(stream);
            m_LocalAABB = new AABB(stream);
            m_MeshUsageFlags = reader.ReadInt32();
        }
Exemple #5
0
 /// <summary>
 /// 行列を読み込みます。
 /// </summary>
 public void Read(BinaryReader reader)
 {
     reader.ReadMatrix(ref this.m);
 }
Exemple #6
0
        public override void loadbody(byte[] array)
        {
            data = array;
            var self = new BinaryReader(new MemoryStream(array));
            var bones = new Bone[self.ReadInt32()];
            var parentNames = new string[bones.Length];
            Bone root = null;

            for (int i = 0; i < bones.Length; i++)
            {
                bones[i] = new Bone();
                bones[i].Name = self.ReadPackString();
                parentNames[i] = self.ReadPackString();
                if (parentNames[i] == "-\0")
                {
                    root = bones[i];
                }
            }

            if (root == null)
            {
                throw new Exception("Root bone can not be null");
            }

            Root = root;
            this.bones = bones;

            map = new BoneMap(bones.Length);
            for (int i = 0; i < bones.Length; i++)
                map.Add(bones[i].Name, i);

            for (int i = 0; i < bones.Length; i++)
            {
                bones[i].BaseInverseMatrix = self.ReadMatrix();
                if (bones[i] != root)
                    bones[i].Parent = bones[IndexOf(parentNames[i])];

            }

            HeadIndex = self.ReadInt32();
            WeaponIndex = self.ReadInt32();

            HeadMatrix = self.ReadMatrix();
            WeaponMatrix = self.ReadMatrix();

            RootIndex = self.ReadInt32();
            TopRootIndex = self.ReadInt32();
            BottomRootIndex = self.ReadInt32();
            botomindexes = new int[self.ReadInt32()];
            for (int i = 0; i < botomindexes.Length; i++)
                botomindexes[i] = self.ReadInt32();

            topindexes = new int[self.ReadInt32()];
            for (int i = 0; i < topindexes.Length; i++)
                topindexes[i] = self.ReadInt32();
        }
Exemple #7
0
        public static Skeleton FromStream(BinaryReader stream)
        {
            var bones = new Bone[stream.ReadInt32()];
            var parentNames = new string[bones.Length];
            Bone root = null;

            for (int i = 0; i < bones.Length; i++)
            {
                bones[i] = new Bone();
                bones[i].index = i;
                bones[i].Name = stream.ReadPackString();
                parentNames[i] = stream.ReadPackString();
                if (parentNames[i] == "-\0")
                    root = bones[i];
            }

            if (root == null)
                throw new Exception("Root bone can not be null");

            var skeleton = new Skeleton();
            skeleton.Init(root, bones);
            for (int i = 0; i < bones.Length; i++)
            {
                bones[i].BaseMatrix = stream.ReadMatrix();
                if (bones[i] != root)
                    bones[i].Parent = bones[skeleton.IndexOf(parentNames[i])];
            }
            foreach (Bone b in bones)
            {
                List<Bone> chl = new List<Bone>();
                for (int i = 0; i < bones.Length; i++)
                    if (bones[i].Parent == b)
                        chl.Add(bones[i]);
                b.Childrens = chl.ToArray();
            }

            return skeleton;
        }
Exemple #8
0
 /// <summary>
 /// メッシュを読み込みます。
 /// </summary>
 public void Read(BinaryReader reader)
 {
     this.name = reader.ReadCString().Replace(":", "_colon_").Replace("#", "_sharp_"); //should be compatible with directx naming conventions
     reader.ReadMatrix(ref this.transform_matrix);
     this.unknown1 = reader.ReadUInt32();
     UInt32 mesh_count = reader.ReadUInt32();
     this.sub_meshes = new TSOSubMesh[mesh_count];
     for (int i = 0; i < mesh_count; i++)
     {
         TSOSubMesh sub_mesh = new TSOSubMesh();
         sub_mesh.Read(reader);
         this.sub_meshes[i] = sub_mesh;
     }
 }
Exemple #9
0
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR"));

            string identifier = reader.ReadString(7);

            if (string.Compare(identifier, FILE_IDENTIFIER, false) != 0) {
                throw new FileIdentifierMismatchException(FilePath, FILE_IDENTIFIER, identifier);
            }

            ProjectionType = (ProjectionType)reader.ReadInt32();

            ModelView = reader.ReadMatrix();
            Projection = reader.ReadMatrix();

            FieldOfView = reader.ReadSingle();
            AspectRatio = reader.ReadSingle();
            NearPlane = reader.ReadSingle();
            FarPlane = reader.ReadSingle();

            Eye = reader.ReadVector3();
            Center = reader.ReadVector3();
            Up = reader.ReadVector3();
        }
Exemple #10
0
        /// <summary>
        /// 指定ストリームから読み込みます。
        /// </summary>
        /// <param name="source_stream">ストリーム</param>
        public void Load(Stream source_stream)
        {
            BinaryReader reader = new BinaryReader(source_stream, System.Text.Encoding.Default);

            byte[] magic = reader.ReadBytes(4);

            if (magic[0] != (byte)'T' || magic[1] != (byte)'S' || magic[2] != (byte)'O' || magic[3] != (byte)'1')
                throw new Exception("File is not TSO");

            int node_count = reader.ReadInt32();
            nodes = new TSONode[node_count];
            for (int i = 0; i < node_count; i++)
            {
                nodes[i] = new TSONode(i);
                nodes[i].Read(reader);
            }

            GenerateNodemapAndTree();

            int node_matrix_count = reader.ReadInt32();
            Matrix m = Matrix.Identity;
            for (int i = 0; i < node_matrix_count; i++)
            {
                reader.ReadMatrix(ref m);
                nodes[i].TransformationMatrix = m;
            }
            for (int i = 0; i < node_matrix_count; i++)
            {
                nodes[i].ComputeOffsetMatrix();
            }

            UInt32 texture_count = reader.ReadUInt32();
            textures = new TSOTex[texture_count];
            for (int i = 0; i < texture_count; i++)
            {
                textures[i] = new TSOTex();
                textures[i].Read(reader);
            }

            UInt32 script_count = reader.ReadUInt32();
            scripts = new TSOScript[script_count];
            for (int i = 0; i < script_count; i++)
            {
                scripts[i] = new TSOScript();
                scripts[i].Read(reader);
            }

            UInt32 sub_script_count = reader.ReadUInt32();
            sub_scripts = new TSOSubScript[sub_script_count];
            for (int i = 0; i < sub_script_count; i++)
            {
                sub_scripts[i] = new TSOSubScript();
                sub_scripts[i].Read(reader);
                sub_scripts[i].GenerateShader();
            }

            UInt32 mesh_count = reader.ReadUInt32();
            meshes = new TSOMesh[mesh_count];
            for (int i = 0; i < mesh_count; i++)
            {
                meshes[i] = new TSOMesh();
                meshes[i].Read(reader);
                meshes[i].LinkBones(nodes);

                //Console.WriteLine("mesh name {0} len {1}", mesh.name, mesh.sub_meshes.Length);
            }
        }
Exemple #11
0
        public sviParser(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            version = reader.ReadInt32();
            if (version != 100)
            {
                throw new Exception("SVI bad beginning: 0x" + version.ToString("X"));
            }
            meshName = reader.ReadName();
            submeshIdx = reader.ReadInt32();
            int numIndices = reader.ReadInt32();
            indices = reader.ReadUInt16Array(numIndices);

            positionsPresent = reader.ReadByte();
            if (positionsPresent == 1)
            {
                positions = reader.ReadVector3Array(numIndices);
            }

            bonesPresent = reader.ReadByte();
            if (bonesPresent == 1)
            {
                boneWeights3 = new float[numIndices][];
                for (ushort i = 0; i < numIndices; i++)
                {
                    boneWeights3[i] = reader.ReadSingleArray(3);
                }
                boneIndices = new byte[numIndices][];
                for (ushort i = 0; i < numIndices; i++)
                {
                    boneIndices[i] = reader.ReadBytes(4);
                }

                int numBones = reader.ReadInt32();
                bones = new sviBone[numBones];
                for (int i = 0; i < numBones; i++)
                {
                    bones[i] = new sviBone();
                    bones[i].name = reader.ReadName();
                    bones[i].boneIdx = reader.ReadInt32();
                    bones[i].matrix = reader.ReadMatrix();
                }
            }

            normalsPresent = reader.ReadByte();
            if (normalsPresent == 1)
            {
                normals = reader.ReadVector3Array(numIndices);
            }

            uvsPresent = reader.ReadByte();
            if (uvsPresent == 1)
            {
                uvs = reader.ReadVector2Array(numIndices);
            }

            futureSectionPresent = reader.ReadByte();
            if (futureSectionPresent != 0)
            {
                throw new Exception("SVI future section present");
            }
        }
Exemple #12
0
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR"));

            int blockCount = reader.ReadInt32();

            for (int i = 0; i < blockCount; i++) {
                MapBlockType type = (MapBlockType)reader.ReadInt32();

                if (!Enum.IsDefined(typeof(MapBlockType), type)) {
                    throw new InvalidMapBlockTypeException((int)type);
                }

                int offset = reader.ReadInt32();
                long nextBlock = stream.Position;

                stream.Seek(offset, SeekOrigin.Begin);

                if (type == MapBlockType.MapInformation) {
                    MapPosition = new IntVector2(reader.ReadInt32(), reader.ReadInt32());
                    ZonePosition = new IntVector2(reader.ReadInt32(), reader.ReadInt32());
                    World = reader.ReadMatrix();
                    Name = reader.ReadString();
                }else if(type == MapBlockType.WaterPatch){
                    WaterPatches = new MapWaterPatches();
                    WaterPatches.Read(reader);
                } else {
                    if (type == MapBlockType.WaterPlane) {
                        WaterSize = reader.ReadSingle();
                    }

                    int entryCount = reader.ReadInt32();
                    Type classType = type.GetAttributeValue<MapBlockTypeAttribute, Type>(x => x.Type);

                    for (int j = 0; j < entryCount; j++) {
                        IMapBlock block = (IMapBlock)Activator.CreateInstance(classType);
                        block.Read(reader);

                        switch (type) {
                            case MapBlockType.Object:
                                Objects.Add((MapObject)block);
                                break;
                            case MapBlockType.NPC:
                                NPCs.Add((MapNPC)block);
                                break;
                            case MapBlockType.Building:
                                Buildings.Add((MapBuilding)block);
                                break;
                            case MapBlockType.Sound:
                                Sounds.Add((MapSound)block);
                                break;
                            case MapBlockType.Effect:
                                Effects.Add((MapEffect)block);
                                break;
                            case MapBlockType.Animation:
                                Animations.Add((MapAnimation)block);
                                break;
                            case MapBlockType.MonsterSpawn:
                                MonsterSpawns.Add((MapMonsterSpawn)block);
                                break;
                            case MapBlockType.WaterPlane:
                                WaterPlanes.Add((MapWaterPlane)block);
                                break;
                            case MapBlockType.WarpPoint:
                                WarpPoints.Add((MapWarpPoint)block);
                                break;
                            case MapBlockType.CollisionObject:
                                CollisionObjects.Add((MapCollisionObject)block);
                                break;
                            case MapBlockType.EventObject:
                                EventObjects.Add((MapEventObject)block);
                                break;
                        }
                    }
                }

                if (i < blockCount - 1) {
                    stream.Seek(nextBlock, SeekOrigin.Begin);
                }
            }
        }
 private static void ReadWMODefs(BinaryReader br, ExtractedADT adt)
 {
     var count = br.ReadInt32();
     var wmoDefList = new List<ExtractedWMODefinition>(count);
     for (var i = 0; i < count; i++)
     {
         var def = new ExtractedWMODefinition {
                                                  UniqueId = br.ReadUInt32(),
                                                  FilePath = br.ReadString(),
                                                  Extents = br.ReadBoundingBox(),
                                                  Position = br.ReadVector3(),
                                                  DoodadSetId = br.ReadUInt16(),
                                                  WorldToWMO = br.ReadMatrix(),
                                                  WMOToWorld = br.ReadMatrix()
                                              };
         wmoDefList.Add(def);
     }
     adt.WMODefs = wmoDefList;
 }
 private static void ReadMapM2Defs(BinaryReader br, ExtractedADT adt)
 {
     var count = br.ReadInt32();
     var m2DefList = new List<ExtractedMapM2Definition>(count);
     for (var i = 0; i < count; i++)
     {
         var def = new ExtractedMapM2Definition {
                                                    UniqueId = br.ReadUInt32(),
                                                    FilePath = br.ReadString(),
                                                    Extents = br.ReadBoundingBox(),
                                                    Position = br.ReadVector3(),
                                                    WorldToModel = br.ReadMatrix(),
                                                    ModelToWorld = br.ReadMatrix()
                                                };
         m2DefList.Add(def);
     }
     adt.M2Defs = m2DefList;
 }