public Node(Stream mdlStream, Stream mdxStream, Type nodeType, AuroraModel model) { byte[] buffer = new byte[78]; mdlStream.Read(buffer, 0, 78); this.nodeType = nodeType; model.nodes.Add(this); superIndex = BitConverter.ToUInt16(buffer, 0); ushort nameIndex = BitConverter.ToUInt16(buffer, 2); name = (nameIndex < model.nodeNames.Length) ? model.nodeNames[nameIndex] : ""; //get the node's position, flip the y and z co-ordinates to align with Unity axes position = new Vector3(BitConverter.ToSingle(buffer, 14), BitConverter.ToSingle(buffer, 22), BitConverter.ToSingle(buffer, 18)); //get the node's orientation, and invert align with Unity axes Quaternion rot = new Quaternion(BitConverter.ToSingle(buffer, 30), BitConverter.ToSingle(buffer, 34), BitConverter.ToSingle(buffer, 38), BitConverter.ToSingle(buffer, 26)); Quaternion inv = new Quaternion(-rot.x, -rot.z, -rot.y, rot.w); rotation = inv; uint childArrayOffset = BitConverter.ToUInt32(buffer, 42), childArrayCount = BitConverter.ToUInt32(buffer, 46), childArrayCapacity = BitConverter.ToUInt32(buffer, 50); uint curveKeyArrayOffset = BitConverter.ToUInt32(buffer, 54), curveKeyArrayCount = BitConverter.ToUInt32(buffer, 58), curveKeyArrayCapacity = BitConverter.ToUInt32(buffer, 62); uint curveDataArrayOffset = BitConverter.ToUInt32(buffer, 66), curveDataArrayCount = BitConverter.ToUInt32(buffer, 70), curveDataArrayCapacity = BitConverter.ToUInt32(buffer, 74); long pos = mdlStream.Position; //an array of offsets into the node list for each child of this node uint[] childArray = new uint[childArrayCount]; mdlStream.Position = model.modelDataOffset + childArrayOffset; buffer = new byte[4 * childArrayCount]; mdlStream.Read(buffer, 0, 4 * (int)childArrayCount); for (int i = 0; i < childArrayCount; i++) { childArray[i] = BitConverter.ToUInt32(buffer, 4 * i); } //curve data stores animated properties on the node curves = model.ReadAnimationCurves(mdlStream, curveKeyArrayCount, curveKeyArrayOffset, curveDataArrayCount, curveDataArrayOffset, this); children = new Node[childArrayCount]; for (int i = 0; i < childArrayCount; i++) { mdlStream.Position = model.modelDataOffset + childArray[i]; children[i] = model.CreateNode(mdlStream, mdxStream, this); } mdlStream.Position = pos; }