public void Copy(ActorImage node, Actor resetActor) { base.Copy(node, resetActor); m_DrawOrder = node.m_DrawOrder; m_BlendMode = node.m_BlendMode; m_TextureIndex = node.m_TextureIndex; m_VertexCount = node.m_VertexCount; m_TriangleCount = node.m_TriangleCount; m_Vertices = node.m_Vertices; m_Triangles = node.m_Triangles; if (node.m_AnimationDeformedVertices != null) { m_AnimationDeformedVertices = (float[])node.m_AnimationDeformedVertices.Clone(); } if (node.m_BoneConnections != null) { m_BoneConnections = new BoneConnection[node.m_BoneConnections.Length]; for (int i = 0; i < node.m_BoneConnections.Length; i++) { BoneConnection bc = new BoneConnection(); bc.m_BoneIdx = node.m_BoneConnections[i].m_BoneIdx; Mat2D.Copy(bc.m_Bind, node.m_BoneConnections[i].m_Bind); Mat2D.Copy(bc.m_InverseBind, node.m_BoneConnections[i].m_InverseBind); m_BoneConnections[i] = bc; } } }
public override ActorComponent MakeInstance(Actor resetActor) { ActorImage instanceNode = new ActorImage(); instanceNode.Copy(this, resetActor); return(instanceNode); }
public virtual void Advance(float seconds) { if ((m_Flags & Flags.IsDirty) != 0) { const int MaxSteps = 100; int step = 0; int count = m_DependencyOrder.Count; while ((m_Flags & Flags.IsDirty) != 0 && step < MaxSteps) { m_Flags &= ~Flags.IsDirty; // Track dirt depth here so that if something else marks dirty, we restart. for (int i = 0; i < count; i++) { ActorComponent component = m_DependencyOrder[i]; m_DirtDepth = (uint)i; byte d = component.m_DirtMask; if (d == 0) { continue; } component.m_DirtMask = 0; component.Update(d); if (m_DirtDepth < i) { break; } } step++; } } if ((m_Flags & Flags.IsImageDrawOrderDirty) != 0) { m_Flags &= ~Flags.IsImageDrawOrderDirty; if (m_ImageNodes != null) { Array.Sort <ActorImage>(m_ImageNodes, sm_ImageDrawOrderComparer); // Mark draw index. for (int i = 0; i < m_ImageNodes.Length; i++) { m_ImageNodes[i].DrawIndex = i; } } } if ((m_Flags & Flags.IsVertexDeformDirty) != 0) { m_Flags &= ~Flags.IsVertexDeformDirty; for (int i = 0; i < m_ImageNodeCount; i++) { ActorImage imageNode = m_ImageNodes[i]; if (imageNode != null && imageNode.IsVertexDeformDirty) { imageNode.IsVertexDeformDirty = false; UpdateVertexDeform(imageNode); } } } }
public static ActorImage Read(Actor actor, BinaryReader reader, ActorImage node = null) { if (node == null) { node = new ActorImage(); } ActorNode.Read(actor, reader, node); bool isVisible = reader.ReadByte() != 0; if (isVisible) { node.m_BlendMode = (BlendModes)reader.ReadByte(); node.m_DrawOrder = (int)reader.ReadUInt16(); node.m_TextureIndex = (int)reader.ReadByte(); int numConnectedBones = (int)reader.ReadByte(); if (numConnectedBones != 0) { node.m_BoneConnections = new BoneConnection[numConnectedBones]; for (int i = 0; i < numConnectedBones; i++) { BoneConnection bc = new BoneConnection(); bc.m_BoneIdx = reader.ReadUInt16(); Actor.ReadFloat32Array(reader, bc.m_Bind.Values); Mat2D.Invert(bc.m_InverseBind, bc.m_Bind); node.m_BoneConnections[i] = bc; } Mat2D worldOverride = new Mat2D(); Actor.ReadFloat32Array(reader, worldOverride.Values); node.WorldTransformOverride = worldOverride; } uint numVertices = reader.ReadUInt32(); int vertexStride = numConnectedBones > 0 ? 12 : 4; node.m_VertexCount = (int)numVertices; node.m_Vertices = new float[numVertices * vertexStride]; Actor.ReadFloat32Array(reader, node.m_Vertices); uint numTris = reader.ReadUInt32(); node.m_Triangles = new ushort[numTris * 3]; node.m_TriangleCount = (int)numTris; Actor.ReadUInt16Array(reader, node.m_Triangles); } return(node); }
protected virtual void UpdateVertexDeform(ActorImage image) { }
public void Copy(Actor actor) { m_Animations = actor.m_Animations; m_Flags = actor.m_Flags; m_MaxTextureIndex = actor.m_MaxTextureIndex; m_ImageNodeCount = actor.m_ImageNodeCount; m_NodeCount = actor.m_NodeCount; if (actor.ComponentCount != 0) { m_Components = new ActorComponent[actor.ComponentCount]; } if (m_NodeCount != 0) // This will always be at least 1. { m_Nodes = new ActorNode[m_NodeCount]; } if (m_ImageNodeCount != 0) { m_ImageNodes = new ActorImage[m_ImageNodeCount]; } if (actor.ComponentCount != 0) { int idx = 0; int imgIdx = 0; int ndIdx = 0; foreach (ActorComponent component in actor.Components) { if (component == null) { m_Components[idx++] = null; continue; } ActorComponent instanceComponent = component.MakeInstance(this); m_Components[idx++] = instanceComponent; ActorNode nodeInstance = instanceComponent as ActorNode; if (nodeInstance != null) { m_Nodes[ndIdx++] = nodeInstance; } ActorImage imageInstance = instanceComponent as ActorImage; if (imageInstance != null) { m_ImageNodes[imgIdx++] = imageInstance; } } } m_Root = m_Components[0] as ActorNode; foreach (ActorComponent component in m_Components) { if (m_Root == component || component == null) { continue; } component.ResolveComponentIndices(m_Components); } foreach (ActorComponent component in m_Components) { if (m_Root == component || component == null) { continue; } component.CompleteResolve(); } SortDependencies(); }
private void ReadComponentsBlock(BlockReader block) { int componentCount = block.ReadUInt16(); m_Components = new ActorComponent[componentCount + 1]; m_Components[0] = m_Root; // Guaranteed from the exporter to be in index order. BlockReader nodeBlock = null; int componentIndex = 1; m_NodeCount = 1; while ((nodeBlock = block.ReadNextBlock()) != null) { ActorComponent component = null; if (Enum.IsDefined(typeof(BlockTypes), nodeBlock.BlockType)) { BlockTypes type = (BlockTypes)nodeBlock.BlockType; switch (type) { case BlockTypes.ActorNode: component = ActorNode.Read(this, nodeBlock); break; case BlockTypes.ActorBone: component = ActorBone.Read(this, nodeBlock); break; case BlockTypes.ActorRootBone: component = ActorRootBone.Read(this, nodeBlock); break; case BlockTypes.ActorImage: m_ImageNodeCount++; component = ActorImage.Read(this, nodeBlock, makeImageNode()); if ((component as ActorImage).TextureIndex > m_MaxTextureIndex) { m_MaxTextureIndex = (component as ActorImage).TextureIndex; } break; case BlockTypes.ActorIKTarget: component = ActorIKTarget.Read(this, nodeBlock); break; case BlockTypes.ActorEvent: component = ActorEvent.Read(this, nodeBlock); break; case BlockTypes.CustomIntProperty: component = CustomIntProperty.Read(this, nodeBlock); break; case BlockTypes.CustomFloatProperty: component = CustomFloatProperty.Read(this, nodeBlock); break; case BlockTypes.CustomStringProperty: component = CustomStringProperty.Read(this, nodeBlock); break; case BlockTypes.CustomBooleanProperty: component = CustomBooleanProperty.Read(this, nodeBlock); break; case BlockTypes.ActorColliderRectangle: component = ActorColliderRectangle.Read(this, nodeBlock); break; case BlockTypes.ActorColliderTriangle: component = ActorColliderTriangle.Read(this, nodeBlock); break; case BlockTypes.ActorColliderCircle: component = ActorColliderCircle.Read(this, nodeBlock); break; case BlockTypes.ActorColliderPolygon: component = ActorColliderPolygon.Read(this, nodeBlock); break; case BlockTypes.ActorColliderLine: component = ActorColliderLine.Read(this, nodeBlock); break; case BlockTypes.ActorNodeSolo: component = ActorNodeSolo.Read(this, nodeBlock); break; case BlockTypes.ActorJellyBone: component = ActorJellyBone.Read(this, nodeBlock); break; case BlockTypes.JellyComponent: component = JellyComponent.Read(this, nodeBlock); break; case BlockTypes.ActorIKConstraint: component = ActorIKConstraint.Read(this, nodeBlock); break; case BlockTypes.ActorDistanceConstraint: component = ActorDistanceConstraint.Read(this, nodeBlock); break; case BlockTypes.ActorTranslationConstraint: component = ActorTranslationConstraint.Read(this, nodeBlock); break; case BlockTypes.ActorScaleConstraint: component = ActorScaleConstraint.Read(this, nodeBlock); break; case BlockTypes.ActorRotationConstraint: component = ActorRotationConstraint.Read(this, nodeBlock); break; case BlockTypes.ActorTransformConstraint: component = ActorTransformConstraint.Read(this, nodeBlock); break; } } if (component is ActorNode) { m_NodeCount++; } m_Components[componentIndex] = component; if (component != null) { component.Idx = (ushort)(componentIndex); } componentIndex++; } m_ImageNodes = new ActorImage[m_ImageNodeCount]; m_Nodes = new ActorNode[m_NodeCount]; m_Nodes[0] = m_Root; // Resolve nodes. int imgIdx = 0; int anIdx = 0; ActorComponent[] components = m_Components; for (int i = 1; i <= componentCount; i++) { ActorComponent c = components[i]; // Nodes can be null if we read from a file version that contained nodes that we don't interpret in this runtime. if (c != null) { c.ResolveComponentIndices(components); } ActorImage ain = c as ActorImage; if (ain != null) { m_ImageNodes[imgIdx++] = ain; } ActorNode an = c as ActorNode; if (an != null) { m_Nodes[anIdx++] = an; } } for (int i = 1; i <= componentCount; i++) { ActorComponent c = components[i]; if (c != null) { c.CompleteResolve(); } } SortDependencies(); }
protected override void UpdateVertexDeform(ActorImage image) { GameActorImage actorImage = image as GameActorImage; actorImage.DeformVertexBuffer.SetData(actorImage.AnimationDeformedVertices); }