/// <summary> /// Initializes a new instance of the <see cref="ScaleKeyFrame"/> struct. /// </summary> /// <param name="reader">The reader.</param> public ScaleKeyFrame(IBinaryReader reader) { Frame = reader.Int32(); Sx = reader.Float(); Sy = reader.Float(); Sz = reader.Float(); Data = reader.Float(); }
/// <summary> /// Initializes a new instance of the <see cref="PosKeyFrame"/> struct. /// </summary> /// <param name="reader">The reader.</param> public PosKeyFrame(IBinaryReader reader) { Frame = reader.Int32(); X = reader.Float(); Y = reader.Float(); Z = reader.Float(); Data = reader.Int32(); }
private Rsm(IBinaryReader reader) { int count; Header = new RsmHeader(reader); AnimationLength = reader.Int32(); ShadeType = reader.Int32(); Alpha = 0xFF; if (Version >= 1.4) { Alpha = reader.Byte(); } if (Version >= 2.3) { FrameRatePerSecond = reader.Float(); count = reader.Int32(); for (int i = 0; i < count; i++) { MainMeshNames.Add(reader.String(reader.Int32(), '\0')); } count = reader.Int32(); } else if (Version >= 2.2) { FrameRatePerSecond = reader.Float(); int numberOfTextures = reader.Int32(); for (int i = 0; i < numberOfTextures; i++) { _textures.Add(reader.String(reader.Int32(), '\0')); } count = reader.Int32(); for (int i = 0; i < count; i++) { MainMeshNames.Add(reader.String(reader.Int32(), '\0')); } count = reader.Int32(); } else { Reserved = reader.Bytes(16); count = reader.Int32(); for (int i = 0; i < count; i++) { _textures.Add(reader.String(40, '\0')); } MainMeshNames.Add(reader.String(40, '\0')); count = reader.Int32(); } for (int i = 0; i < count; i++) { _meshes.Add(new Mesh(this, reader)); } // Resolve parent/child associations if (MainMeshNames.Count == 0) { MainMeshNames.Add(_meshes[0].Name); } MainMesh = _meshes.FirstOrDefault(m => m.Name == MainMeshNames[0]) ?? _meshes[0]; _setParents(); foreach (Mesh mesh in _meshes) { if (String.IsNullOrEmpty(mesh.ParentName)) { _parents.Add(mesh); } else { var meshParent = _meshes.FirstOrDefault(p => p.Name == mesh.ParentName); if (meshParent == null) { // no parent _parents.Add(mesh); } else { mesh.Parent = meshParent; } } } if (Version < 1.6) { count = reader.Int32(); for (int i = 0; i < count; i++) { _scaleKeyFrames.Add(new ScaleKeyFrame { Frame = reader.Int32(), Sx = reader.Float(), Sy = reader.Float(), Sz = reader.Float(), Data = reader.Float() }); } } count = reader.CanRead ? reader.Int32() : 0; if (Version >= 1.3) { for (int i = 0; i < count; i++) { VolumeBoxes.Add(new VolumeBox(reader)); } } else { for (int i = 0; i < count; i++) { VolumeBoxes.Add(new VolumeBox(reader, true)); } } _uniqueTextures(); Box = new BoundingBox(); }
/// <summary> /// Initializes a new instance of the <see cref="TextureKeyFrame"/> struct. /// </summary> /// <param name="reader">The reader.</param> public TextureKeyFrame(IBinaryReader reader) { Frame = reader.Int32(); Offset = reader.Float(); }
/// <summary> /// Initializes a new instance of the <see cref="Mesh"/> class. /// </summary> /// <param name="rsm">The RSM.</param> /// <param name="reader">The reader.</param> /// <param name="version">The version.</param> public Mesh(Rsm rsm, IBinaryReader reader, double version) { int count; Model = rsm; if (version >= 2.2) { Name = reader.String(reader.Int32(), '\0'); ParentName = reader.String(reader.Int32(), '\0'); } else { Name = reader.String(40, '\0'); ParentName = reader.String(40, '\0'); } if (version >= 2.3) { count = reader.Int32(); for (int i = 0; i < count; i++) { Textures.Add(reader.String(reader.Int32(), '\0')); } _textureIndexes.Capacity = count; for (int i = 0; i < count; i++) { _textureIndexes.Add(i); } } else { _textureIndexes.Capacity = count = reader.Int32(); for (int i = 0; i < count; i++) { _textureIndexes.Add(reader.Int32()); } } for (int i = 0; i < 9; i++) { _transformationMatrix[i] = reader.Float(); } Position_ = new Vertex(reader); if (version >= 2.2) { Position = new Vertex(0, 0, 0); RotAngle = 0; RotAxis = new Vertex(0, 0, 0); Scale = new Vertex(1, 1, 1); } else { Position = new Vertex(reader); RotAngle = reader.Float(); RotAxis = new Vertex(reader); Scale = new Vertex(reader); } _vertices.Capacity = count = reader.Int32(); for (int i = 0; i < count; i++) { _vertices.Add(new Vertex(reader)); } _tvertices.Capacity = count = reader.Int32(); for (int i = 0; i < count; i++) { _tvertices.Add(new TextureVertex { Color = version >= 1.2 ? reader.UInt32() : 0xFFFFFFFF, U = reader.Float(), V = reader.Float() }); } _faces.Capacity = count = reader.Int32(); for (int i = 0; i < count; i++) { Face face = new Face(); int len = -1; if (version >= 2.2) { len = reader.Int32(); } face.VertexIds = reader.ArrayUInt16(3); face.TextureVertexIds = reader.ArrayUInt16(3); face.TextureId = reader.UInt16(); face.Padding = reader.UInt16(); face.TwoSide = reader.Int32(); if (version >= 1.2) { face.SmoothGroup[0] = face.SmoothGroup[1] = face.SmoothGroup[2] = reader.Int32(); if (len > 24) { face.SmoothGroup[1] = reader.Int32(); } if (len > 28) { face.SmoothGroup[2] = reader.Int32(); } } _faces.Add(face); } if (version >= 1.6) { _scaleKeyFrames.Capacity = count = reader.Int32(); for (int i = 0; i < count; i++) { _scaleKeyFrames.Add(new ScaleKeyFrame { Frame = reader.Int32(), Sx = reader.Float(), Sy = reader.Float(), Sz = reader.Float(), Data = reader.Float() }); } } _rotFrames.Capacity = count = reader.Int32(); for (int i = 0; i < count; i++) { _rotFrames.Add(new RotKeyFrame { Frame = reader.Int32(), Quaternion = new TkQuaternion(reader.Float(), reader.Float(), reader.Float(), reader.Float()) }); } if (version >= 2.2) { _posKeyFrames.Capacity = count = reader.Int32(); for (int i = 0; i < count; i++) { _posKeyFrames.Add(new PosKeyFrame { Frame = reader.Int32(), X = reader.Float(), Y = reader.Float(), Z = reader.Float(), Data = reader.Int32() }); } } if (version >= 2.3) { count = reader.Int32(); for (int i = 0; i < count; i++) { int textureId = reader.Int32(); int amountTextureAnimations = reader.Int32(); for (int j = 0; j < amountTextureAnimations; j++) { int type = reader.Int32(); int amountFrames = reader.Int32(); for (int k = 0; k < amountFrames; k++) { _textureKeyFrameGroup.AddTextureKeyFrame(textureId, type, new TextureKeyFrame { Frame = reader.Int32(), Offset = reader.Float() }); } } } } _uniqueTextures(); }
/// <summary> /// Initializes a new instance of the <see cref="RotKeyFrame"/> struct. /// </summary> /// <param name="reader">The reader.</param> public RotKeyFrame(IBinaryReader reader) { Frame = reader.Int32(); Quaternion = new TkQuaternion(reader.Float(), reader.Float(), reader.Float(), reader.Float()); }