/// <summary> /// Initializes the texture dictionary and lists of the <see cref="RmdScene"/>. /// </summary> private void InitializeMembers() { mTextureDictionary = null; mClumps = new List <RwClumpNode>(); mNodeLinks = new RmdNodeLinkListNode(); mAnimations = new List <RmdAnimation>(); mMiscNodes = new List <RwNode>(); }
/// <summary> /// Inherited from <see cref="RwNode"/>. Writes the data beyond the header. /// </summary> /// <param name="writer">The <see cref="BinaryWriter"/> to write the data with.</param> protected internal override void WriteBody(BinaryWriter writer) { // Create and write the animation set count node (if there are any animation sets if (AnimationCount > 0) { RmdAnimationCountNode animCount = new RmdAnimationCountNode((short)AnimationCount); animCount.Write(writer); } // Write the misc nodes first foreach (RwNode miscNode in mMiscNodes) { miscNode.Write(writer); } // Then the texture dictionary (if it's present) if (mTextureDictionary != null) { mTextureDictionary.Write(writer); } // After that the scenes foreach (RwClumpNode scene in mClumps) { scene.Write(writer); } // Aaaand the attach frame list (well, only if there are any entries in the list) if (NodeLinkCount > 0) { // Create a new frame link list and write it. RmdNodeLinkListNode nodeLink = new RmdNodeLinkListNode(mNodeLinks); nodeLink.Write(writer); } // And last but not least- the animation sets! foreach (RmdAnimation animationSet in mAnimations) { // don't call Write(writer) as that would include the node header (which animation sets aren't supposed to have) animationSet.WriteBody(writer); } }
/// <summary> /// Read the <see cref="RmdScene"/> from a <see cref="Stream"/> using a <see cref="BinaryReader"/>. /// </summary> /// <param name="reader">The <see cref="BinaryReader"/> attached to a <see cref="Stream"/> containing <see cref="RmdScene"/> data.</param> protected internal override void ReadBody(BinaryReader reader) { List <RwNode> unfilteredNodes = new List <RwNode>(); // Initial pass, read all nodes into a list and filter the animation set count, texture dictionary, scenes and attach frame list out. while (reader.BaseStream.Position < reader.BaseStream.Length) { RwNode node = RwNodeFactory.GetNode(this, reader); switch (node.Id) { case RwNodeId.RmdAnimationCountNode: // skip this node as its entirely redundant break; case RwNodeId.RwTextureDictionaryNode: mTextureDictionary = (RwTextureDictionaryNode)node; break; case RwNodeId.RwClumpNode: mClumps.Add((RwClumpNode)node); break; case RwNodeId.RmdNodeLinkListNode: // Retrieve the list of frame links from the node and skip the node itself mNodeLinks = (RmdNodeLinkListNode)node; break; case RwNodeId.RmdAuthor: // pass through break; default: unfilteredNodes.Add(node); break; } } // Second pass, sort the remaining nodes into misc nodes and animation sets for (int i = 0; i < unfilteredNodes.Count; i++) { switch (unfilteredNodes[i].Id) { case RwNodeId.RwAnimationNode: case RwNodeId.RwUVAnimationDictionaryNode: case RwNodeId.RmdAnimationPlaceholderNode: case RwNodeId.RmdAnimationInstanceNode: case RwNodeId.RmdAnimationTerminatorNode: case RwNodeId.RmdTransformOverrideNode: case RwNodeId.RmdVisibilityAnimNode: case RwNodeId.RmdParticleAnimationNode: // Read an animation set, this function will increment the loop iterator variable mAnimations.Add(CreateAnimationSet(unfilteredNodes, ref i)); break; default: mMiscNodes.Add(unfilteredNodes[i]); break; } } }