Ejemplo n.º 1
0
        public override ActorComponent MakeInstance(Actor resetActor)
        {
            ActorIKConstraint instance = new ActorIKConstraint();

            instance.Copy(this, resetActor);
            return(instance);
        }
Ejemplo n.º 2
0
        public static ActorIKConstraint Read(Actor actor, BinaryReader reader, ActorIKConstraint component = null)
        {
            if (component == null)
            {
                component = new ActorIKConstraint();
            }
            ActorTargetedConstraint.Read(actor, reader, component);

            component.m_InvertDirection = reader.ReadByte() == 1;

            int numInfluencedBones = (int)reader.ReadByte();

            if (numInfluencedBones > 0)
            {
                component.m_InfluencedBones = new InfluencedBone[numInfluencedBones];

                for (int i = 0; i < numInfluencedBones; i++)
                {
                    InfluencedBone ib = new InfluencedBone();
                    ib.m_BoneIdx = reader.ReadUInt16();
                    component.m_InfluencedBones[i] = ib;
                }
            }

            return(component);
        }
Ejemplo n.º 3
0
        public override void ResolveComponentIndices(ActorComponent[] components)
        {
            base.ResolveComponentIndices(components);

            m_Constraint = new ActorIKConstraint(this);
            m_Constraint.ResolveComponentIndices(components);
            // if(m_InfluencedBones != null)
            // {
            //  for(int i = 0; i < m_InfluencedBones.Length; i++)
            //  {
            //      InfluencedBone ib = m_InfluencedBones[i];
            //      ib.m_Bone = components[ib.m_BoneIdx] as ActorBone;
            //      if(ib.m_Bone != null)
            //      {
            //          ib.m_Bone.AddDependent(this);
            //      }
            //  }

            //  if(m_InfluencedBones.Length > 0)
            //  {
            //      m_Bone1 = m_InfluencedBones[0].m_Bone;
            //      m_Bone2 = m_InfluencedBones[m_InfluencedBones.Length-1].m_Bone;

            //      ActorBone b1c = m_Bone2;
            //      ActorBone b1 = m_Bone1;
            //      if(m_InfluencedBones.Length > 1)
            //      {
            //          while(b1c != null && b1c.Parent != b1)
            //          {
            //              b1c = b1c.Parent as ActorBone;
            //          }
            //      }
            //      m_Bone1Child = b1c;
            //      int chainCount = 0;
            //      ActorBone end = m_Bone2;
            //      while(end != null && end != b1.Parent)
            //      {
            //          chainCount++;
            //          end = end.Parent as ActorBone;
            //      }

            //      m_Chain = new BoneChain[chainCount];
            //      end = m_Bone2;
            //      int chainIdx = 0;
            //      while(end != null && end != b1.Parent)
            //      {
            //          BoneChain bc = new BoneChain();
            //          bc.m_Bone = end;
            //          bc.m_Angle = 0.0f;
            //          bc.m_Included = DoesInfluence(end) || DoesInfluence(end.Parent as ActorBone);
            //          m_Chain[chainIdx++] = bc;
            //          end = end.Parent as ActorBone;
            //      }
            //  }
            // }
        }
Ejemplo n.º 4
0
        public void Copy(ActorIKConstraint node, Actor resetActor)
        {
            base.Copy(node, resetActor);

            m_InvertDirection = node.m_InvertDirection;
            if (node.m_InfluencedBones != null)
            {
                m_InfluencedBones = new InfluencedBone[node.m_InfluencedBones.Length];
                for (int i = 0; i < m_InfluencedBones.Length; i++)
                {
                    InfluencedBone ib = new InfluencedBone();
                    ib.m_BoneIdx         = node.m_InfluencedBones[i].m_BoneIdx;
                    m_InfluencedBones[i] = ib;
                }
            }
        }
Ejemplo n.º 5
0
        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();
        }