protected override void link() { base.link(); SimObject entitySimObject = Owner.getOtherSimObject(anatomySimObjectName); if (entitySimObject == null) { blacklist("Cannot find Anatomy SimObject named '{0}'", anatomySimObjectName); } anatomy = entitySimObject.getElement(anatomyName) as AnatomyIdentifier; if (anatomy == null) { blacklist("Cannot find AnatomyIdentifier '{0}' on Anatomy SimObject '{1}'", anatomyName, anatomySimObjectName); } SimObject poseHandlerSimObject = Owner.getOtherSimObject(poseHandlerSimObjectName); if (poseHandlerSimObject == null) { blacklist("Cannot find PoseHandler SimObject named '{0}'", poseHandlerSimObjectName); } poseHandler = poseHandlerSimObject.getElement(poseHandlerName) as PoseHandler; if (poseHandler == null) { blacklist("Cannot find PoseHandler '{0}' in SimObject '{1}'", poseHandlerName, poseHandlerSimObjectName); } PoseableObjectsManager.add(this); }
private bool findDragTarget(Ray3 cameraRay) { var matches = PoseableObjectsManager.findPoseable(cameraRay); foreach (var match in matches.Results) { var bone = match.PoseableIdentifier.PoseHandler.Bone; if (bone != null) { if (bone.Pinned) { repinBone = true; bone.Pinned = false; } else { repinBone = false; } dragControl.TargetBone = bone; hitDistance = match.Distance; Vector3 hitPosition = cameraRay.Direction * hitDistance + cameraRay.Origin; dragControl.LinearMotor.Offset = (hitPosition - bone.Owner.Translation).toBepuVec3(); dragControl.LinearMotor.TargetPosition = hitPosition.toBepuVec3(); ikScene.addExternalControl(dragControl); poseStartPosition = new MusclePosition(true); currentHandler = match.PoseableIdentifier.PoseHandler; currentHandler.posingStarted(activeModes); return(true); } } return(false); }
/// <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); } }
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 destroy() { PoseableObjectsManager.remove(this); base.destroy(); }
protected override void destroy() { base.destroy(); PoseableObjectsManager.removeFkChainRoot(this); }
protected override void link() { base.link(); PoseableObjectsManager.addFkChainRoot(this); }