예제 #1
0
        public override ActorComponent MakeInstance(Actor resetActor)
        {
            ActorJellyBone instanceNode = new ActorJellyBone();

            instanceNode.Copy(this, resetActor);
            return(instanceNode);
        }
예제 #2
0
        private void UpdateJellies()
        {
            if (m_Bones == null)
            {
                return;
            }
            ActorBone bone = m_Parent as ActorBone;
            // We are in local bone space.
            Vec2D tipPosition = new Vec2D(bone.Length, 0.0f);

            if (FuzzyEquals(m_CachedTip, tipPosition) && FuzzyEquals(m_CachedOut, m_OutPoint) && FuzzyEquals(m_CachedIn, m_InPoint) && m_CachedScaleIn == m_ScaleIn && m_CachedScaleOut == m_ScaleOut)
            {
                return;
            }

            Vec2D.Copy(m_CachedTip, tipPosition);
            Vec2D.Copy(m_CachedOut, m_OutPoint);
            Vec2D.Copy(m_CachedIn, m_InPoint);
            m_CachedScaleIn  = m_ScaleIn;
            m_CachedScaleOut = m_ScaleOut;

            Vec2D q0 = new Vec2D();
            Vec2D q1 = m_InPoint;
            Vec2D q2 = m_OutPoint;
            Vec2D q3 = tipPosition;

            ForwardDiffBezier(q0[0], q1[0], q2[0], q3[0], m_JellyPoints, JellyMax, 0);
            ForwardDiffBezier(q0[1], q1[1], q2[1], q3[1], m_JellyPoints, JellyMax, 1);

            IList <Vec2D> normalizedPoints = NormalizeCurve(m_JellyPoints, m_Bones.Count);

            Vec2D lastPoint = m_JellyPoints[0];

            float scale    = m_ScaleIn;
            float scaleInc = (m_ScaleOut - m_ScaleIn) / (m_Bones.Count - 1);

            for (int i = 0; i < normalizedPoints.Count; i++)
            {
                ActorJellyBone jelly = m_Bones[i];
                Vec2D          p     = normalizedPoints[i];

                jelly.Translation = lastPoint;
                jelly.Length      = Vec2D.Distance(p, lastPoint);
                jelly.ScaleY      = scale;
                scale            += scaleInc;

                Vec2D diff = Vec2D.Subtract(new Vec2D(), p, lastPoint);
                jelly.Rotation = (float)Math.Atan2(diff[1], diff[0]);
                lastPoint      = p;
            }
        }
예제 #3
0
        public static ActorJellyBone Read(Actor actor, BinaryReader reader, ActorJellyBone node = null)
        {
            if (node == null)
            {
                node = new ActorJellyBone();
            }

            // The Jelly Bone has a specialized read that doesn't go down the typical node path, this is because majority of the transform properties
            // of the Jelly Bone are controlled by the Jelly Controller and are unnecessary for serialization.
            ActorComponent.Read(actor, reader, node);
            node.m_Opacity = reader.ReadSingle();
            node.m_IsCollapsedVisibility = reader.ReadByte() == 1;
            return(node);
        }
예제 #4
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();
        }