示例#1
0
        /// <summary>
        /// Primary blend funciton, will always use the terminating state's mandible muscle force and target offset.
        /// This is to retain compatability with animations that rely on this blend funciton to work.
        /// </summary>
        /// <param name="targetState"></param>
        /// <param name="blendFactor"></param>
        public void blend(MusclePosition targetState, float blendFactor)
        {
            float modifiedBlendFactor = blendFactor;

            if (blendFactor < 1.0f)
            {
                EasingFunctions.Ease(targetState.Easing, 0, 1, blendFactor, 1);
            }

            if (MuscleController.MovingTarget != null) //If this is null then the whole mandible simulation is invalid and its better to do nothing
            {
                MuscleController.changeForce("MovingMuscleDynamic", targetState.muscleForce);
                MuscleController.MovingTarget.Offset = targetState.movingTargetPosition;

                ControlPointBehavior leftCP = ControlPointController.getControlPoint("LeftCP");
                float delta = targetState.leftCPPosition - leftCPPosition;
                leftCP.setLocation(leftCPPosition + delta * modifiedBlendFactor);

                ControlPointBehavior rightCP = ControlPointController.getControlPoint("RightCP");
                delta = targetState.rightCPPosition - rightCPPosition;
                rightCP.setLocation(rightCPPosition + delta * modifiedBlendFactor);
            }

            FKRoot pelvis;

            if (pelvisChainState != null && targetState.pelvisChainState != null && PoseableObjectsManager.tryGetFkChainRoot("Pelvis", out pelvis))
            {
                //This creates garbage, but it is unknown if this has negative effects
                FKChainState blendedState = new FKChainState();
                blendedState.setToBlendOf(pelvisChainState, targetState.pelvisChainState, modifiedBlendFactor);
                pelvis.applyChainState(blendedState);
            }
        }
示例#2
0
        public void captureState()
        {
            MuscleBehavior movingMuscle = MuscleController.getMuscle("MovingMuscleDynamic");

            if (movingMuscle != null)
            {
                muscleForce = movingMuscle.getForce();
            }
            if (MuscleController.MovingTarget != null)
            {
                movingTargetPosition = MuscleController.MovingTarget.Offset;
            }
            ControlPointBehavior leftCP  = ControlPointController.getControlPoint("LeftCP");
            ControlPointBehavior rightCP = ControlPointController.getControlPoint("RightCP");

            if (leftCP != null)
            {
                leftCPPosition = leftCP.CurrentLocation;
            }
            if (rightCP != null)
            {
                rightCPPosition = rightCP.CurrentLocation;
            }

            //Setup the pelvis fk chain if available
            FKRoot pelvis;

            if (PoseableObjectsManager.tryGetFkChainRoot("Pelvis", out pelvis))
            {
                pelvisChainState = new FKChainState();
                pelvis.addToChainState(pelvisChainState);
            }
            else
            {
                pelvisChainState = null;
            }
        }
        protected override void constructed()
        {
            boneObject = Owner.getOtherSimObject(boneSimObject);
            if (boneObject != null)
            {
                SceneNodeElement node = boneObject.getElement(boneNode) as SceneNodeElement;
                if (node != null)
                {
                    Entity entity = node.getNodeObject(boneEntity) as Entity;
                    if (entity != null)
                    {
                        if (entity.hasSkeleton())
                        {
                            SkeletonInstance skeleton = entity.getSkeleton();
                            if (skeleton.hasBone(targetBone))
                            {
                                bone = skeleton.getBone(targetBone);
                            }
                            else
                            {
                                blacklist("Entity {0} does not have a bone named {1}.", boneEntity, targetBone);
                            }
                        }
                        else
                        {
                            blacklist("Entity {0} does not have a skeleton.", boneEntity);
                        }
                    }
                    else
                    {
                        blacklist("Could not find Entity {0}.", boneEntity);
                    }
                }
                else
                {
                    blacklist("Could not find target SceneNodeElement {0}.", boneNode);
                }
            }
            else
            {
                blacklist("Could not find Target SimObject {0}.", boneSimObject);
            }
            SimObject discSimObject = Owner.getOtherSimObject(discObject);

            if (discSimObject != null)
            {
                disc = discSimObject.getElement(discName) as Disc;
                if (disc == null)
                {
                    blacklist("Could not find Disc {0} in SimObject {1}.", discName, discObject);
                }
            }
            else
            {
                blacklist("Could not find Disc SimObject {0}.", discObject);
            }
            joint = Owner.getElement(jointName) as Generic6DofConstraintElement;
            if (joint == null)
            {
                blacklist("Could not find joint {0}.", jointName);
            }

            ControlPointController.addControlPoint(this);
        }
 protected override void destroy()
 {
     ControlPointController.removeControlPoint(this);
 }