/// <summary> /// Creates a <see cref="RmdAnimation"/> from a list of nodes and an index into the list to start parsing at. /// </summary> /// <param name="nodes">List of nodes to go through.</param> /// <param name="startIndex">Index into the list to start parsing at.</param> /// <returns>A new <see cref="RmdAnimation"/>parsed from the list of nodes.</returns> private RmdAnimation CreateAnimationSet(List <RwNode> nodes, ref int startIndex) { List <RwNode> animNodes = new List <RwNode>(); while (true) { // Check if the index is outside the list bounds if (startIndex == nodes.Count) { break; } RwNode node = nodes[startIndex]; // Check the if the node is a terminator and break out of the loop if it is if (node.Id == RwNodeId.RmdAnimationTerminatorNode) { break; } else { // Else just increment the index and add it to the node list startIndex++; animNodes.Add(node); } } return(new RmdAnimation(animNodes, this)); }
public RwAnimationNode(RwNode parent = null) : base(RwNodeId.RwAnimationNode, parent) { Version = VERSION; KeyFrameType = RwKeyFrameType.Uncompressed; KeyFrames = new List <RwKeyFrame>(); Flags = 0; }
/// <summary> /// Initialize a new instance of <see cref="RwRasterStructNode"/> using a width, height, palette, pixel indices and pixel format. /// </summary> /// <param name="width">Width of the texture.</param> /// <param name="height">Height of the texture.</param> /// <param name="palette">Palette colors of the texture.</param> /// <param name="indices">Per-pixel palette color indices of the texture.</param> /// <param name="pixelFormat">PS2 pixel format of the given data.</param> /// <param name="parent">Parent of this <see cref="RwRasterStructNode"/> node. Value is null if not specified.</param> public RwRasterStructNode(int width, int height, Color[] palette, byte[] indices, PS2.Graphics.PS2PixelFormat pixelFormat, RwNode parent = null) : base(RwNodeId.RwStructNode, parent) { InfoStructNode = new RwRasterInfoStructNode(width, height, pixelFormat); DataStructNode = new RwRasterDataStructNode(palette, indices, pixelFormat); }
public RwTextureReferenceStruct(RwNode parent = null) : base(RwNodeId.RwStructNode, parent) { FilterMode = PS2FilterMode.Linear; HorizontalAdressingMode = PS2AddressingMode.Wrap; VerticalAdressingMode = PS2AddressingMode.Wrap; HasMipMaps = false; }
// Constructors public RwTextureNativeStructNode(RwNode parent = null) : base(RwNodeId.RwStructNode, parent) { PlatformId = RwPlatformId.PS2; FilterMode = PS2FilterMode.Linear; HorizontalAddressingMode = PS2AddressingMode.Wrap; VerticalAddressingMode = PS2AddressingMode.Wrap; }
public RwGeometryListNode(IList <RwGeometryNode> geoList, RwNode parent = null) : base(RwNodeId.RwGeometryListNode, parent) { mGeometryList = geoList.ToList(); foreach (var geometry in mGeometryList) { geometry.Parent = this; } }
public RwAnimationNode(RwNode parent, RwKeyFrameType keyFrameType, float duration) : base(RwNodeId.RwAnimationNode, parent) { Version = VERSION; KeyFrameType = keyFrameType; KeyFrames = new List <RwKeyFrame>(); Flags = 0; Duration = duration; }
public RwExtensionNode(RwNode parent, params RwNode[] plugins) : base(RwNodeId.RwExtensionNode) { Children = plugins.ToList(); foreach (var child in Children) { child.Parent = this; } }
public RwClumpNode(RwNode parent) : base(RwNodeId.RwClumpNode, parent) { Atomics = new List <RwAtomicNode>(); FrameList = new RwFrameListNode(this); GeometryList = new RwGeometryListNode(this); mExtensionNodeNode = new RwExtensionNode(this); mStructNode = new RwClumpStructNode(this); }
/// <summary> /// Initialize RenderWare material data with default properties. /// </summary> public RwMaterialStructNode(RwNode parent = null) : base(RwNodeId.RwStructNode, parent) { Color = Color.White; IsTextured = true; Ambient = 1.0f; Specular = 1.0f; Diffuse = 1.0f; }
internal static RwNodeHeader ReadHeader(BinaryReader reader, RwNode parent) { return(new RwNodeHeader { Id = ( RwNodeId )reader.ReadUInt32(), Size = reader.ReadUInt32(), Version = reader.ReadUInt32(), Parent = parent }); }
public RwTextureNativeStructNode( RwPlatformId rwPlatformId, PS2FilterMode filterMode, PS2AddressingMode horizontalAddrMode, PS2AddressingMode verticalAddrMode, RwNode parent = null) : base(RwNodeId.RwStructNode, parent) { PlatformId = rwPlatformId; FilterMode = filterMode; HorizontalAddressingMode = horizontalAddrMode; VerticalAddressingMode = verticalAddrMode; }
public RwTextureReferenceStruct( PS2FilterMode filterMode, PS2AddressingMode horizontalAddrMode, PS2AddressingMode verticalAddrMode, bool hasMipMaps, RwNode parent = null) : base(RwNodeId.RwStructNode, parent) { FilterMode = filterMode; HorizontalAdressingMode = horizontalAddrMode; VerticalAdressingMode = verticalAddrMode; HasMipMaps = hasMipMaps; }
public RwMaterialListNode(RwNode parent, Assimp.Material material) : base(RwNodeId.RwMaterialListNode, parent) { mMaterials = new List <RwMaterial>(); string textureName = null; if (material.HasTextureDiffuse) { textureName = Path.GetFileNameWithoutExtension(material.TextureDiffuse.FilePath); } mMaterials.Add(new RwMaterial(material.Name, textureName, this)); mStructNode = new RwMaterialListStructNode(this); }
private static RwNode GetStructNodeParentIsStruct(RwNodeHeader header, BinaryReader reader) { RwNode grandParent = header.Parent.Parent; // If the grandparent is null then I don't know what kind of node this is. if (grandParent == null) { return(new RwNode(header, reader)); } switch (grandParent.Id) { case RwNodeId.RwTextureNativeNode: return(GetStructNodeParentIsStructGrandParentIsTextureNative(header, reader)); default: throw new NotImplementedException(); } }
public RwClumpNode(Stream stream, bool leaveOpen = false) : base(RwNodeId.RwClumpNode) { var node = (RwClumpNode)RwNode.Load(stream, leaveOpen); mStructNode = node.mStructNode; mStructNode.Parent = this; FrameList = node.FrameList; FrameList.Parent = this; GeometryList = node.GeometryList; GeometryList.Parent = this; Atomics = node.Atomics; foreach (var atomicNode in Atomics) { atomicNode.Parent = this; } mExtensionNodeNode = node.mExtensionNodeNode; mExtensionNodeNode.Parent = this; }
/// <summary> /// Initialize an empty RenderWare UV animation dictionary. /// </summary> /// <param name="parent">The parent of the uv animation dictionary node. Value is null if not specified.</param> public RwUVAnimationDictionary(RwNode parent = null) : base(RwNodeId.RwUVAnimationDictionaryNode, parent) { _uvAnimations = new List <RwNode>(); }
/// <summary> /// Initialize a RenderWare UV animation dictionary using a list of uv animations. /// </summary> /// <param name="uvAnimations">The list of uv animations to initialize the uv animation dictionary with.</param> /// <param name="parent">The parent of the uv animation dictionary node. Value is null if not specified.</param> public RwUVAnimationDictionary(IList <RwNode> uvAnimations, RwNode parent = null) : base(RwNodeId.RwUVAnimationDictionaryNode, parent) { _uvAnimations = uvAnimations.ToList(); }
/// <summary> /// Initialize a new <see cref="RwMeshListNode"/> using a <see cref="RwGeometryNode"/> and the primitive id for the split data. /// </summary> /// <param name="geometryNode"></param> /// <param name="primitiveType"></param> public RwMeshListNode(RwGeometryNode geometryNode, RwPrimitiveType primitiveType = RwPrimitiveType.TriangleStrip, RwNode parent = null) : base(RwNodeId.RwMeshListNode, parent) { // set id and prim count mPrimitiveType = primitiveType; //mPrimitiveCount = geometryNode.TriangleCount; // pass 1: order the triangles by ascending material id var sortedTriangles = geometryNode.Triangles.OrderBy(tri => tri.MatId); // pass 2: split the indices List <ushort>[] matSplitsIndices = new List <ushort> [geometryNode.MaterialCount]; List <ushort> curMatSplitIndices = null; int curMatIdx = -1; foreach (var tri in sortedTriangles) { if (tri.MatId != curMatIdx) { if (curMatIdx != -1) { matSplitsIndices[curMatIdx] = curMatSplitIndices; } curMatIdx = tri.MatId; curMatSplitIndices = new List <ushort>(); } curMatSplitIndices.Add(tri.A); curMatSplitIndices.Add(tri.B); curMatSplitIndices.Add(tri.C); } matSplitsIndices[curMatIdx] = curMatSplitIndices; // pass 3: create the split data mMeshes = new RwMesh[geometryNode.MaterialCount]; for (int i = 0; i < mMeshes.Length; i++) { ushort[] matSplitIndices = matSplitsIndices[i].ToArray(); int triangleCount; if (primitiveType == RwPrimitiveType.TriangleStrip) { if (NvTriStripUtility.GenerateStrips(matSplitIndices, out PrimitiveGroup[] primitives) && primitives[0].Type == ManagedNvTriStrip.PrimitiveType.TriangleStrip)
public RwAtomicSector(RwNode parent) : base(RwNodeId.RwAtomicSector, parent) { }
public RwPlaneSectorHeader(RwNode parent) : base(RwNodeId.RwStructNode, parent) { }
public RWUVAnimationDictionaryStructNode(RwNode parent, int count) : base(RwNodeId.RwStructNode, parent) { UvAnimationCount = count; }
public RWUVAnimationDictionaryStructNode(int uvAnimationCount, RwNode parent = null) : base(RwNodeId.RwStructNode, parent) { UvAnimationCount = uvAnimationCount; }
public RwWorldHeader(RwNode parent) : base(RwNodeId.RwStructNode, parent) { }
public RwExtensionNode(RwNode parent = null) : base(RwNodeId.RwExtensionNode, parent) { Children = new List <RwNode>(); }
public RwAtomicStructNode(int frameIndex, int geometryIndex, int flag1, int flag2, RwNode parent = null) : base(RwNodeId.RwStructNode, parent) { mFrameIndex = frameIndex; mGeometryIndex = geometryIndex; mFlag1 = flag1; mFlag2 = flag2; }
public static RwAnimationNode FromAssimpScene(RwNode parent, RwFrameListNode frameList, string path) { var aiContext = new Assimp.AssimpContext(); var aiScene = aiContext.ImportFile(path); var aiAnimation = aiScene.Animations.FirstOrDefault(); RwAnimationNode animationNode; if (aiAnimation != null) { animationNode = new RwAnimationNode(parent, RwKeyFrameType.Uncompressed, ( float )(aiAnimation.DurationInTicks / aiAnimation.TicksPerSecond)); var nodeNameToHAnimId = aiAnimation.NodeAnimationChannels.ToDictionary(x => x.NodeName, x => frameList.GetNameIdByName(x.NodeName)); var nodeKeyframeTimes = aiAnimation.NodeAnimationChannels.SelectMany(x => x.PositionKeys) .Select(x => x.Time) .Concat(aiAnimation.NodeAnimationChannels.SelectMany(x => x.RotationKeys.Select(y => y.Time))) .Distinct() .OrderBy(x => x) .ToList(); var previousKeyFrames = new Dictionary <int, RwKeyFrame>(); var nodeKeyFrames = new Dictionary <int, List <RwKeyFrame> >(); // Add initial pose foreach (var hierarchyNode in frameList.AnimationRootNode.HAnimFrameExtensionNode.Hierarchy.Nodes) { var frame = frameList[frameList.GetFrameIndexByNameId(hierarchyNode.NodeId)]; var firstRotation = Quaternion.CreateFromRotationMatrix(frame.Transform); var firstTranslation = frame.Transform.Translation; var channel = aiAnimation.NodeAnimationChannels.FirstOrDefault(x => nodeNameToHAnimId[x.NodeName] == hierarchyNode.NodeId); if (channel != null) { if (channel.HasRotationKeys) { firstRotation = ToQuaternion(channel.RotationKeys.First().Value); } if (channel.HasPositionKeys) { firstTranslation = ToVector3(channel.PositionKeys.First().Value); } } var keyFrame = new RwKeyFrame(0, firstRotation, firstTranslation, null); animationNode.KeyFrames.Add(keyFrame); previousKeyFrames[hierarchyNode.NodeId] = keyFrame; nodeKeyFrames[hierarchyNode.NodeId] = new List <RwKeyFrame>(); } foreach (var keyFrameTime in nodeKeyframeTimes) { if (keyFrameTime == 0.0f) { continue; } foreach (var channel in aiAnimation.NodeAnimationChannels) { if (!channel.HasPositionKeys && !channel.HasRotationKeys) { continue; } if (!channel.RotationKeys.Any(x => x.Time == keyFrameTime) || !channel.PositionKeys.Any(x => x.Time == keyFrameTime)) { continue; } var hierarchAnimNodeId = nodeNameToHAnimId[channel.NodeName]; var previousKeyFrame = previousKeyFrames[hierarchAnimNodeId]; var rotation = previousKeyFrame.Rotation; var translation = previousKeyFrame.Translation; var rotationKeys = channel.RotationKeys.Where(x => x.Time == keyFrameTime); if (rotationKeys.Any()) { var aiRotation = rotationKeys.First().Value; rotation = new Quaternion(aiRotation.X, aiRotation.Y, aiRotation.Z, aiRotation.W); } var translationKeys = channel.PositionKeys.Where(x => x.Time == keyFrameTime); if (translationKeys.Any()) { var aiTranslation = translationKeys.First().Value; translation = new Vector3(aiTranslation.X, aiTranslation.Y, aiTranslation.Z); } var keyFrame = new RwKeyFrame(( float )(keyFrameTime / aiAnimation.TicksPerSecond), rotation, translation, previousKeyFrame); nodeKeyFrames[hierarchAnimNodeId].Add(keyFrame); previousKeyFrames[hierarchAnimNodeId] = keyFrame; } } while (!nodeKeyFrames.All(x => x.Value.Count == 0)) { foreach (var kvp in nodeKeyFrames) { if (animationNode.KeyFrames.Count == 0) { continue; } var keyFrame = kvp.Value.First(); animationNode.KeyFrames.Add(keyFrame); kvp.Value.Remove(keyFrame); if (animationNode.KeyFrames.Count == 0) { var previousKeyFrame = previousKeyFrames[kvp.Key]; if (previousKeyFrame.Time != animationNode.Duration) { var lastRotation = previousKeyFrame.Rotation; var lastTranslation = previousKeyFrame.Translation; var channel = aiAnimation.NodeAnimationChannels.SingleOrDefault(x => nodeNameToHAnimId[x.NodeName] == kvp.Key); if (channel != null) { if (channel.HasRotationKeys) { lastRotation = ToQuaternion(channel.RotationKeys.Last().Value); } if (channel.HasPositionKeys) { lastTranslation = ToVector3(channel.PositionKeys.Last().Value); } } animationNode.KeyFrames.Add(new RwKeyFrame(animationNode.Duration, lastRotation, lastTranslation, previousKeyFrame)); } } } } } else { animationNode = new RwAnimationNode(null, RwKeyFrameType.Uncompressed, 0f); } return(animationNode); }
public RwPlaneSector(RwNode parent) : base(RwNodeId.RwPlaneSector, parent) { }
// Constructors public RwFrameListStructNode(RwNode parent) : base(RwNodeId.RwStructNode, parent) { FrameList = new List <RwFrame>(); }
/// <summary> /// Initialize a new instance of <see cref="RwRasterStructNode"/> using a bitmap to encode using the given pixel format. /// </summary> /// <param name="bitmap">Bitmap to encode to the specified pixel format.</param> /// <param name="pixelFormat">Pixel format to encode the bitmap to.</param> /// <param name="parent">Parent of this <see cref="RwRasterStructNode"/> node. Value is null if not specified.</param> public RwRasterStructNode(Bitmap bitmap, PS2.Graphics.PS2PixelFormat pixelFormat, RwNode parent = null) : base(RwNodeId.RwStructNode, parent) { InfoStructNode = new RwRasterInfoStructNode(bitmap.Width, bitmap.Height, pixelFormat); DataStructNode = new RwRasterDataStructNode(bitmap, pixelFormat); }