void Start() { jointPoints = new JointPoint[PositionIndex.Count.Int()]; for (var i = 0; i < PositionIndex.Count.Int(); i++) { jointPoints[i] = new JointPoint(); } anim = UnityChan.GetComponent <Animator>(); VideoPlayStart(); texture = new Texture2D(videoTexture.width, videoTexture.height); // Clip size videoWidth = texture.width; videoHeight = texture.height; float padWidth = (videoWidth < videoHeight) ? 0 : (videoHeight - videoWidth) / 2; float padHeight = (videoWidth < videoHeight) ? (videoWidth - videoHeight) / 2 : 0; var w = (videoWidth + padWidth * 2f) * 0.15f; padWidth += w; padHeight += w; clipRect = new UnityEngine.Rect(-padWidth, -padHeight, videoWidth + padWidth * 2, videoHeight + padHeight * 2); InitONNX(); Init(); }
/* * Sets a joint point as the new start position. Removes all saved virtual paths and intersections. * */ public void setStartPosition(JointPoint joint) { startJoint = joint; intersections = new List <VirtualIntersection>(); paths = new List <VirtualPath>(); VirtualIntersection intersection = CreateInstance <VirtualIntersection>(); intersection.init(joint.getPosition(), joint, "" + intersections.Count); intersections.Add(intersection); intersection.setWalkingStartPosition(0, joint.getWalkingStartPosition(0)); intersection.setWalkingStartPosition(1, joint.getWalkingStartPosition(1)); intersection.setWalkingStartPosition(2, joint.getWalkingStartPosition(2)); intersection.setWalkingStartPosition(3, joint.getWalkingStartPosition(3)); #if UNITY_EDITOR SceneView.RepaintAll(); AssetDatabase.AddObjectToAsset(intersection, this); EditorUtility.SetDirty(this); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); #endif Debug.Log("Set new start position"); }
/* * Initializes jointpoints and curves by using the defined positions. In the future * it might be comfortable to automatically generate the positions by using the size of the * tracking space. * */ public void initJointsAndCurves(Vector3 jointAPosition, Vector3 jointBPosition, Vector3 jointCPosition, float walkingZoneRadius) { // Set three joint points (real world) jointPointA = CreateInstance <JointPoint>(); jointPointA.init(jointAPosition, "A", walkingZoneRadius); jointPointB = CreateInstance <JointPoint>(); jointPointB.init(jointBPosition, "B", walkingZoneRadius); jointPointC = CreateInstance <JointPoint>(); jointPointC.init(jointCPosition, "C", walkingZoneRadius); #if UNITY_EDITOR AssetDatabase.AddObjectToAsset(jointPointA, this); AssetDatabase.AddObjectToAsset(jointPointB, this); AssetDatabase.AddObjectToAsset(jointPointC, this); EditorUtility.SetDirty(this); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); #endif // Specify curves with small radii (real world) curveABsmallRadius = createSmallCurve(jointPointA, jointPointB); curveACsmallRadius = createSmallCurve(jointPointC, jointPointA); curveBCsmallRadius = createSmallCurve(jointPointB, jointPointC); // Specify curves with large radii (real world) curveABlargeRadius = createLargeCurve(jointPointA, jointPointB, jointPointC); curveAClargeRadius = createLargeCurve(jointPointC, jointPointA, jointPointB); curveBClargeRadius = createLargeCurve(jointPointB, jointPointC, jointPointA); #if UNITY_EDITOR SceneView.RepaintAll(); #endif Debug.Log("Initialized joints and curves"); }
public void UpdateJointPoint(JointPoint point) { using (var dbContextScope = DbContextScopeFactory.Create()) { _jointPointRepository.Update(point); dbContextScope.SaveChanges(); } }
public void init(Vector3 position, JointPoint jointPoint, string label) { this.position = position; this.jointPoint = jointPoint; this.label = label; this.paths = new VirtualPath[4]; this.walkingStartPositions = new Vector3[4]; }
public JointPoint getOtherJointPoint(JointPoint joint) { if (joint.Equals(endPoints[0])) { return(endPoints[1]); } return(endPoints[0]); }
private void DrawConnectionJoint(JointPoint senderJoint, JointPoint nearJoint) { if (_shownDrawConnectionObject == null) { _shownDrawConnectionObject = Instantiate(nearJoint.JointBehaviour.ConnectionPreview); } TransformToJoint(_shownDrawConnectionObject, nearJoint, senderJoint); _shownDrawConnectionObject.transform.SetParent(senderJoint.transform); _shownDrawConnectionObject.SetActive(true); }
/* * Stops the redirection at the given intersection. * Sets current intersection and current joint to the next point. * If this intersection is not the same intersection the user started, the rotation angle is added (bool addAngle). * */ private void stopRedirection(VirtualIntersection intersection, bool addAngle) { currentIntersection = intersection; currentJoint = currentIntersection.getJoint(); if (addAngle) { oldRotation += Mathf.Rad2Deg * -redirectionDirection * (angleWalkedOnRealCircle - angleWalkedOnVirtualCircle); //(Mathf.Abs(currentCurve.getAngle()) - Mathf.Abs(currentPath.getAngle())) * -redirectionDirection; } redirectionStarted = false; Debug.Log("Redirection stopped at joint: " + currentJoint.getLabel() + ", intersection: " + currentIntersection.getLabel() + " (old rotation: " + oldRotation + ")"); }
void Rotate(JointPoint _selectedJointPoint, bool _isClockwise) { if (_isClockwise) { _selectedJointPoint.RotateClockwise(); } else { _selectedJointPoint.RotateCounterClockwise(); } }
private IEnumerator RestoreJointsOnNextFrame(Dictionary <int, JointData> joints) { JointBehaviour.IsTempConnectionCreated = true; yield return(new WaitForEndOfFrame()); Debug.Log("<Color=Olive>Restore joints started!</Color>"); var jointsScene = FindObjectsOfType <JointBehaviour>(); foreach (JointBehaviour joint in jointsScene) { joint.UnLockAndDisconnectPoints(); } foreach (var joint in joints) { int instanseId = joint.Key; JointData jointData = joint.Value; ObjectController objectController = GameStateData.GetObjectInLocation(instanseId); if (objectController == null) { continue; } JointBehaviour jointBehaviour = objectController.RootGameObject.GetComponent <JointBehaviour>(); if (jointBehaviour == null) { continue; } var jointPoints = Helper.GetJointPoints(objectController.RootGameObject); foreach (var jointConnectionsData in jointData.JointConnetionsData) { int pointId = jointConnectionsData.Key; JointPoint myJointPoint = jointPoints[pointId]; JointConnetionsData connectionData = jointConnectionsData.Value; ObjectController otherObjectController = GameStateData.GetObjectInLocation(connectionData.ConnectedObjectInstanceId); var otherJointPoints = Helper.GetJointPoints(otherObjectController.RootGameObject); JointPoint otherJointPoint = otherJointPoints[connectionData.ConnectedObjectJointPointId]; jointBehaviour.ConnectToJointPoint(myJointPoint, otherJointPoint); myJointPoint.IsForceLocked = connectionData.ForceLocked; otherJointPoint.IsForceLocked = connectionData.ForceLocked; } } yield return(new WaitForEndOfFrame()); JointBehaviour.IsTempConnectionCreated = false; yield return(true); }
public void ConnectToJointPoint(JointPoint myPoint, JointPoint otherPoint) { TransformToJoint(gameObject, myPoint, otherPoint); otherPoint.Connect(gameObject, myPoint); OnConnect?.Invoke(); otherPoint.JointBehaviour.OnConnect?.Invoke(); if (AutoLock) { otherPoint.Lock(); } }
void Start() { Debug.Log("Application started"); if (data == null) { this.loadPathLayout(pathLayoutAsset); } else { currentIntersection = data.intersections [0]; currentJoint = currentIntersection.getJoint(); } }
private void JointPointOnJointExit(JointPoint senderJoint, JointPoint nearJoint) { if (IsGrabbed) { return; } HideConnectionJoint(); _senderJointPoint = null; _nearJointBehaviour = null; _nearJointPoint = null; Debug.Log($"Joint exit! {senderJoint} {nearJoint}"); }
//Moves and rotates the given limb to attach to this mite //Attaches the limb to this gameobject public void connectLimb(MiteLimb limb, JointPoint myConPt) { JointPoint limbPt = limb.conPt; Vector3 posDelta = myConPt.transform.position - limbPt.transform.position; //move limb into place (note connection point is usually offset from obj origin) limb.gameObject.transform.position = limb.gameObject.transform.position + posDelta; //rotate to match orientation Quaternion rot = limbPt.matchDirection(getCenter(), limb.gameObject.transform.position); limb.gameObject.transform.rotation = rot; //parent the limb limb.gameObject.transform.parent = gameObject.transform; }
/* * Loads path layout asset with the specified name from a resources folder. * */ public void loadPathLayout(string layoutName) { pathLayoutAsset = layoutName; // Load data structure object (created by tool) from disk data = (RedirectionDataStructure)Resources.LoadAll(pathLayoutAsset)[0] as RedirectionDataStructure; if (data != null) { //Debug.Log("Label: " + data.jointPointA.getLabel()); currentIntersection = data.intersections[0]; currentJoint = currentIntersection.getJoint(); } else { Debug.Log("Data is null"); } }
public static void ReloadJointConnections(ObjectController objectController, JointData saveJointData) { JointBehaviour jointBehaviour = objectController.RootGameObject.GetComponent <JointBehaviour>(); var jointPoints = GetJointPoints(objectController.RootGameObject); foreach (var jointConnectionsData in saveJointData.JointConnetionsData) { int pointId = jointConnectionsData.Key; JointPoint myJointPoint = jointPoints[pointId]; JointConnetionsData connectionData = jointConnectionsData.Value; ObjectController otherObjectController = GameStateData.GetObjectInLocation(connectionData.ConnectedObjectInstanceId); var otherJointPoints = GetJointPoints(otherObjectController.RootGameObject); JointPoint otherJointPoint = otherJointPoints[connectionData.ConnectedObjectJointPointId]; jointBehaviour.ConnectToJointPoint(myJointPoint, otherJointPoint); myJointPoint.IsForceLocked = connectionData.ForceLocked; otherJointPoint.IsForceLocked = connectionData.ForceLocked; } }
public void UpdateJointPoint(JointPointDto point) { // TODO: null-possibility should rather be checked in Buisness logic, and here just try-catch-toFaultConv if (point == null) { var fault = new ArgumentFault { Message = "Argumnet is null", ArgumentName = nameof(point) }; throw new FaultException <ArgumentFault>(fault); } JointPoint pointEntity = Mapper.Map <JointPoint>(point); _robotProgramBusinessLogic.UpdateJointPoint(pointEntity); }
void Start() { jointPoints = new JointPoint[PositionIndex.Count.Int()]; for (var i = 0; i < PositionIndex.Count.Int(); i++) { jointPoints[i] = new JointPoint(); } anim = UnityChan.GetComponent <Animator>(); if (UseWebCam) { CameraPlayStart(); } else { VideoPlayStart(); } // Clip size videoWidth = texture.width; videoHeight = texture.height; float padWidth = (videoWidth < videoHeight) ? 0 : (videoHeight - videoWidth) / 2; float padHeight = (videoWidth < videoHeight) ? (videoWidth - videoHeight) / 2 : 0; if (clipScale == 0f) { clipScale = 0.001f; } var w = (videoWidth + padWidth * 2f) * clipScale; padWidth += w; padHeight += w; clipRect = new UnityEngine.Rect(-padWidth, -padHeight, videoWidth + padWidth * 2, videoHeight + padHeight * 2); #if UNITY_WEBGL && !UNITY_EDITOR getFilePath_Coroutine = GetFilePath(); StartCoroutine(getFilePath_Coroutine); #else model_filepath = Utils.getFilePath("MobileNet3D2.onnx"); InitONNX(); Init(); #endif }
protected virtual void Start() { jointPoints = new JointPoint[PositionIndex.Count.Int()]; for (var i = 0; i < PositionIndex.Count.Int(); i++) { jointPoints[i] = new JointPoint(); } if (Texture_Mode == TextureMode.VideoClip) { SetupVideo_Mode(); } else if (Texture_Mode == TextureMode.Image) { SetupImage_Mode(); } else { SetupCamera_Mode(); } // Clip size videoWidth = texture.width; videoHeight = texture.height; float padWidth = (videoWidth < videoHeight) ? 0 : (videoHeight - videoWidth) / 2; float padHeight = (videoWidth < videoHeight) ? (videoWidth - videoHeight) / 2 : 0; if (OptimizerScale == 0f) { OptimizerScale = 0.001f; } var w = (videoWidth + padWidth * 2f) * OptimizerScale; padWidth += w; padHeight += w; clipRect = new UnityEngine.Rect(-padWidth, -padHeight, videoWidth + padWidth * 2, videoHeight + padHeight * 2); Onnx = Net.ReadNetFromONNX(Application.dataPath + @"\Training Data\MobileNet3D2.onnx"); for (var i = 0; i < 4; i++) { outputs[i] = new Mat(); } }
private void JointPointOnJointEnter(JointPoint senderJoint, JointPoint nearJoint) { _senderJointPoint = senderJoint; _nearJointPoint = nearJoint; _nearJointBehaviour = nearJoint.JointBehaviour; if (!IsGrabbed || !senderJoint.IsFree || !nearJoint.IsFree) { return; } if (IsGrabbed && nearJoint.JointBehaviour.IsGrabbed) { //ToDo case 3 here return; } nearJoint.JointBehaviour.DrawConnectionJoint(nearJoint, senderJoint); Debug.Log($"Joint enter! {senderJoint} {nearJoint}"); }
/* * Returns the direction (left or right) to that the current path is bent. * -1 is left, 1 is right. * */ private int getRedirectionDirection(JointPoint joint, Curve curve) { if (joint.Equals(data.jointPointA)) { JointPoint endJoint = curve.getOtherJointPoint(joint); if (endJoint.Equals(data.jointPointB)) { return(-1); } if (endJoint.Equals(data.jointPointC)) { return(1); } } if (joint.Equals(data.jointPointB)) { JointPoint endJoint = curve.getOtherJointPoint(joint); if (endJoint.Equals(data.jointPointA)) { return(1); } if (endJoint.Equals(data.jointPointC)) { return(-1); } } if (joint.Equals(data.jointPointC)) { JointPoint endJoint = curve.getOtherJointPoint(joint); if (endJoint.Equals(data.jointPointB)) { return(1); } if (endJoint.Equals(data.jointPointA)) { return(-1); } } return(0); }
private static void TransformToJoint(GameObject go, JointPoint nearJointPoint, JointPoint senderJoint) { GameObject temp = new GameObject("temp"); Transform saveTransform = go.transform.parent; var var = nearJointPoint.transform; temp.transform.position = var.position; temp.transform.rotation = var.rotation; var o = nearJointPoint.JointBehaviour.gameObject; go.transform.position = o.transform.position; go.transform.rotation = o.transform.rotation; go.transform.SetParent(temp.transform); var var2 = senderJoint.transform; temp.transform.position = var2.position; temp.transform.rotation = var2.rotation; temp.transform.Rotate(new Vector3(180, 0, 0)); go.transform.SetParent(saveTransform); Destroy(temp); }
void RotateCommand(bool _isClockwise) { JointPoint selectedJointPoint = selectedJoint.GetComponent <JointPoint>(); Rotate(selectedJointPoint, _isClockwise); if (CheckIfMarkableHexagonsExist()) { SuccessfulMoveRoutine(true); } else { Rotate(selectedJointPoint, _isClockwise); if (CheckIfMarkableHexagonsExist()) { SuccessfulMoveRoutine(true); } else { Rotate(selectedJointPoint, _isClockwise); } } }
/* * Creates a curve from joint1 to joint2 with the center between both points (plus offset for real walking area at joint point). * */ private Curve createSmallCurve(JointPoint joint1, JointPoint joint2) { Vector3 circleCenter = Vector3.Lerp(joint1.getPosition(), joint2.getPosition(), 0.5f); float radius = 0.5f * Vector3.Magnitude(joint1.getPosition() - joint2.getPosition()); List <JointPoint> endPoints = new List <JointPoint>(); endPoints.Add(joint1); endPoints.Add(joint2); Curve curve = CreateInstance <Curve>(); curve.init(circleCenter, radius, endPoints, true); #if UNITY_EDITOR AssetDatabase.AddObjectToAsset(curve, this); EditorUtility.SetDirty(this); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); #endif return(curve); }
void Start() { jointPoints = new JointPoint[PositionIndex.Count.Int()]; for (var i = 0; i < PositionIndex.Count.Int(); i++) { jointPoints[i] = new JointPoint(); } anim = UnityChan.GetComponent <Animator>(); if (UseWebCam) { CameraPlayStart(); } else { VideoPlayStart(); } // Clip size videoWidth = texture.width; videoHeight = texture.height; float padWidth = (videoWidth < videoHeight) ? 0 : (videoHeight - videoWidth) / 2; float padHeight = (videoWidth < videoHeight) ? (videoWidth - videoHeight) / 2 : 0; if (clipScale == 0f) { clipScale = 0.001f; } var w = (videoWidth + padWidth * 2f) * clipScale; padWidth += w; padHeight += w; clipRect = new UnityEngine.Rect(-padWidth, -padHeight, videoWidth + padWidth * 2, videoHeight + padHeight * 2); InitONNX(); Init(); }
/* * Returns the sign for the angle (curve to the right 1 or left -1?) * */ public int getSignOfCurve(JointPoint startJointPoint, JointPoint endJointPoint) { if (startJointPoint.Equals(jointPointA)) { if (endJointPoint.Equals(jointPointB)) { return(-1); } if (endJointPoint.Equals(jointPointC)) { return(1); } } if (startJointPoint.Equals(jointPointB)) { if (endJointPoint.Equals(jointPointA)) { return(1); } if (endJointPoint.Equals(jointPointC)) { return(-1); } } if (startJointPoint.Equals(jointPointC)) { if (endJointPoint.Equals(jointPointB)) { return(1); } if (endJointPoint.Equals(jointPointA)) { return(-1); } } return(-1); }
public List <JointBehaviour> GetAllConnectedJoints(JointPoint jointPoint, List <JointBehaviour> sender = null) { if (jointPoint == null) { return(null); } var result = sender ?? new List <JointBehaviour>() { this }; if (jointPoint.IsFree) { return(result); } JointBehaviour candidate = jointPoint.ConnectedJointPoint.JointBehaviour; result.Add(candidate); jointPoint.ConnectedJointPoint.JointBehaviour.GetAllConnectedJoints(result); return(result); }
private Quaternion GetInverse(JointPoint p1, JointPoint p2, Vector3 forward) { return(Quaternion.Inverse(Quaternion.LookRotation(p1.Transform.position - p2.Transform.position, forward))); }
public JointPoint[] Init(int inputImageSize) { movementScale = 0.01f * 224f / inputImageSize; centerTall = inputImageSize * 0.75f; tall = inputImageSize * 0.75f; prevTall = inputImageSize * 0.75f; jointPoints = new JointPoint[PositionIndex.Count.Int()]; for (var i = 0; i < PositionIndex.Count.Int(); i++) { jointPoints[i] = new JointPoint(); jointPoints[i].Index = (PositionIndex)i; jointPoints[i].UpperBody = false; } anim = ModelObject.GetComponent <Animator>(); jointPoints[PositionIndex.hip.Int()].Transform = transform; // Right Arm jointPoints[PositionIndex.rShldrBend.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.RightUpperArm); jointPoints[PositionIndex.rForearmBend.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.RightLowerArm); jointPoints[PositionIndex.rHand.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.RightHand); jointPoints[PositionIndex.rThumb2.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.RightThumbIntermediate); jointPoints[PositionIndex.rMid1.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.RightMiddleProximal); // Left Arm jointPoints[PositionIndex.lShldrBend.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.LeftUpperArm); jointPoints[PositionIndex.lForearmBend.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.LeftLowerArm); jointPoints[PositionIndex.lHand.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.LeftHand); jointPoints[PositionIndex.lThumb2.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.LeftThumbIntermediate); jointPoints[PositionIndex.lMid1.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.LeftMiddleProximal); // Face jointPoints[PositionIndex.lEar.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.Head); jointPoints[PositionIndex.lEye.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.LeftEye); jointPoints[PositionIndex.rEar.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.Head); jointPoints[PositionIndex.rEye.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.RightEye); jointPoints[PositionIndex.Nose.Int()].Transform = Nose.transform; // Right Leg jointPoints[PositionIndex.rThighBend.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.RightUpperLeg); jointPoints[PositionIndex.rShin.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.RightLowerLeg); jointPoints[PositionIndex.rFoot.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.RightFoot); jointPoints[PositionIndex.rToe.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.RightToes); // Left Leg jointPoints[PositionIndex.lThighBend.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.LeftUpperLeg); jointPoints[PositionIndex.lShin.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.LeftLowerLeg); jointPoints[PositionIndex.lFoot.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.LeftFoot); jointPoints[PositionIndex.lToe.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.LeftToes); // etc jointPoints[PositionIndex.abdomenUpper.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.Spine); jointPoints[PositionIndex.head.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.Head); jointPoints[PositionIndex.hip.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.Hips); jointPoints[PositionIndex.neck.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.Neck); jointPoints[PositionIndex.spine.Int()].Transform = anim.GetBoneTransform(HumanBodyBones.Spine); // UpperBody Settings jointPoints[PositionIndex.hip.Int()].UpperBody = true; // Right Arm jointPoints[PositionIndex.rShldrBend.Int()].UpperBody = true; jointPoints[PositionIndex.rForearmBend.Int()].UpperBody = true; jointPoints[PositionIndex.rHand.Int()].UpperBody = true; jointPoints[PositionIndex.rThumb2.Int()].UpperBody = true; jointPoints[PositionIndex.rMid1.Int()].UpperBody = true; // Left Arm jointPoints[PositionIndex.lShldrBend.Int()].UpperBody = true; jointPoints[PositionIndex.lForearmBend.Int()].UpperBody = true; jointPoints[PositionIndex.lHand.Int()].UpperBody = true; jointPoints[PositionIndex.lThumb2.Int()].UpperBody = true; jointPoints[PositionIndex.lMid1.Int()].UpperBody = true; // Face jointPoints[PositionIndex.lEar.Int()].UpperBody = true; jointPoints[PositionIndex.lEye.Int()].UpperBody = true; jointPoints[PositionIndex.rEar.Int()].UpperBody = true; jointPoints[PositionIndex.rEye.Int()].UpperBody = true; jointPoints[PositionIndex.Nose.Int()].UpperBody = true; // etc jointPoints[PositionIndex.spine.Int()].UpperBody = true; jointPoints[PositionIndex.neck.Int()].UpperBody = true; // Parent and Child Settings // Right Arm jointPoints[PositionIndex.rShldrBend.Int()].Child = jointPoints[PositionIndex.rForearmBend.Int()]; jointPoints[PositionIndex.rForearmBend.Int()].Child = jointPoints[PositionIndex.rHand.Int()]; jointPoints[PositionIndex.rForearmBend.Int()].Parent = jointPoints[PositionIndex.rShldrBend.Int()]; //jointPoints[PositionIndex.rHand.Int()].Parent = jointPoints[PositionIndex.rForearmBend.Int()]; // Left Arm jointPoints[PositionIndex.lShldrBend.Int()].Child = jointPoints[PositionIndex.lForearmBend.Int()]; jointPoints[PositionIndex.lForearmBend.Int()].Child = jointPoints[PositionIndex.lHand.Int()]; jointPoints[PositionIndex.lForearmBend.Int()].Parent = jointPoints[PositionIndex.lShldrBend.Int()]; //jointPoints[PositionIndex.lHand.Int()].Parent = jointPoints[PositionIndex.lForearmBend.Int()]; // Fase // Right Leg jointPoints[PositionIndex.rThighBend.Int()].Child = jointPoints[PositionIndex.rShin.Int()]; jointPoints[PositionIndex.rShin.Int()].Child = jointPoints[PositionIndex.rFoot.Int()]; jointPoints[PositionIndex.rFoot.Int()].Child = jointPoints[PositionIndex.rToe.Int()]; jointPoints[PositionIndex.rFoot.Int()].Parent = jointPoints[PositionIndex.rShin.Int()]; // Left Leg jointPoints[PositionIndex.lThighBend.Int()].Child = jointPoints[PositionIndex.lShin.Int()]; jointPoints[PositionIndex.lShin.Int()].Child = jointPoints[PositionIndex.lFoot.Int()]; jointPoints[PositionIndex.lFoot.Int()].Child = jointPoints[PositionIndex.lToe.Int()]; jointPoints[PositionIndex.lFoot.Int()].Parent = jointPoints[PositionIndex.lShin.Int()]; // etc jointPoints[PositionIndex.spine.Int()].Child = jointPoints[PositionIndex.neck.Int()]; jointPoints[PositionIndex.neck.Int()].Child = jointPoints[PositionIndex.head.Int()]; //jointPoints[PositionIndex.head.Int()].Child = jointPoints[PositionIndex.Nose.Int()]; //jointPoints[PositionIndex.hip.Int()].Child = jointPoints[PositionIndex.spine.Int()]; // Line Child Settings // Right Arm AddSkeleton(PositionIndex.rShldrBend, PositionIndex.rForearmBend, true); AddSkeleton(PositionIndex.rForearmBend, PositionIndex.rHand, true); AddSkeleton(PositionIndex.rHand, PositionIndex.rThumb2, true); AddSkeleton(PositionIndex.rHand, PositionIndex.rMid1, true); // Left Arm AddSkeleton(PositionIndex.lShldrBend, PositionIndex.lForearmBend, true); AddSkeleton(PositionIndex.lForearmBend, PositionIndex.lHand, true); AddSkeleton(PositionIndex.lHand, PositionIndex.lThumb2, true); AddSkeleton(PositionIndex.lHand, PositionIndex.lMid1, true); // Face //AddSkeleton(PositionIndex.lEar, PositionIndex.lEye); //AddSkeleton(PositionIndex.lEye, PositionIndex.Nose); //AddSkeleton(PositionIndex.rEar, PositionIndex.rEye); //AddSkeleton(PositionIndex.rEye, PositionIndex.Nose); AddSkeleton(PositionIndex.lEar, PositionIndex.Nose, true); AddSkeleton(PositionIndex.rEar, PositionIndex.Nose, true); // Right Leg AddSkeleton(PositionIndex.rThighBend, PositionIndex.rShin, false); AddSkeleton(PositionIndex.rShin, PositionIndex.rFoot, false); AddSkeleton(PositionIndex.rFoot, PositionIndex.rToe, false); // Left Leg AddSkeleton(PositionIndex.lThighBend, PositionIndex.lShin, false); AddSkeleton(PositionIndex.lShin, PositionIndex.lFoot, false); AddSkeleton(PositionIndex.lFoot, PositionIndex.lToe, false); // etc AddSkeleton(PositionIndex.spine, PositionIndex.neck, true); AddSkeleton(PositionIndex.neck, PositionIndex.head, true); AddSkeleton(PositionIndex.head, PositionIndex.Nose, true); AddSkeleton(PositionIndex.neck, PositionIndex.rShldrBend, true); AddSkeleton(PositionIndex.neck, PositionIndex.lShldrBend, true); AddSkeleton(PositionIndex.rThighBend, PositionIndex.rShldrBend, true); AddSkeleton(PositionIndex.lThighBend, PositionIndex.lShldrBend, true); AddSkeleton(PositionIndex.rShldrBend, PositionIndex.abdomenUpper, true); AddSkeleton(PositionIndex.lShldrBend, PositionIndex.abdomenUpper, true); AddSkeleton(PositionIndex.rThighBend, PositionIndex.abdomenUpper, true); AddSkeleton(PositionIndex.lThighBend, PositionIndex.abdomenUpper, true); AddSkeleton(PositionIndex.lThighBend, PositionIndex.rThighBend, true); // Set Inverse var forward = TriangleNormal(jointPoints[PositionIndex.hip.Int()].Transform.position, jointPoints[PositionIndex.lThighBend.Int()].Transform.position, jointPoints[PositionIndex.rThighBend.Int()].Transform.position); foreach (var jointPoint in jointPoints) { if (jointPoint.Transform != null) { jointPoint.InitRotation = jointPoint.Transform.rotation; } if (jointPoint.Child != null) { jointPoint.Inverse = GetInverse(jointPoint, jointPoint.Child, forward); jointPoint.InverseRotation = jointPoint.Inverse * jointPoint.InitRotation; } } var hip = jointPoints[PositionIndex.hip.Int()]; initPosition = transform.position; //initPosition = jointPoints[PositionIndex.hip.Int()].Transform.position; hip.Inverse = Quaternion.Inverse(Quaternion.LookRotation(forward)); hip.InverseRotation = hip.Inverse * hip.InitRotation; // For Head Rotation var head = jointPoints[PositionIndex.head.Int()]; head.InitRotation = jointPoints[PositionIndex.head.Int()].Transform.rotation; var gaze = jointPoints[PositionIndex.Nose.Int()].Transform.position - jointPoints[PositionIndex.head.Int()].Transform.position; head.Inverse = Quaternion.Inverse(Quaternion.LookRotation(gaze)); head.InverseRotation = head.Inverse * head.InitRotation; var lHand = jointPoints[PositionIndex.lHand.Int()]; var lf = TriangleNormal(lHand.Pos3D, jointPoints[PositionIndex.lMid1.Int()].Pos3D, jointPoints[PositionIndex.lThumb2.Int()].Pos3D); lHand.InitRotation = lHand.Transform.rotation; lHand.Inverse = Quaternion.Inverse(Quaternion.LookRotation(jointPoints[PositionIndex.lThumb2.Int()].Transform.position - jointPoints[PositionIndex.lMid1.Int()].Transform.position, lf)); lHand.InverseRotation = lHand.Inverse * lHand.InitRotation; var rHand = jointPoints[PositionIndex.rHand.Int()]; var rf = TriangleNormal(rHand.Pos3D, jointPoints[PositionIndex.rThumb2.Int()].Pos3D, jointPoints[PositionIndex.rMid1.Int()].Pos3D); rHand.InitRotation = jointPoints[PositionIndex.rHand.Int()].Transform.rotation; rHand.Inverse = Quaternion.Inverse(Quaternion.LookRotation(jointPoints[PositionIndex.rThumb2.Int()].Transform.position - jointPoints[PositionIndex.rMid1.Int()].Transform.position, rf)); rHand.InverseRotation = rHand.Inverse * rHand.InitRotation; jointPoints[PositionIndex.hip.Int()].score3D = 1f; jointPoints[PositionIndex.neck.Int()].score3D = 1f; jointPoints[PositionIndex.Nose.Int()].score3D = 1f; jointPoints[PositionIndex.head.Int()].score3D = 1f; jointPoints[PositionIndex.spine.Int()].score3D = 1f; return(JointPoints); }
private Quaternion GetInverse(JointPoint p1, JointPoint p2) { return(Quaternion.Inverse(Quaternion.LookRotation(p1.Transform.position - p2.Transform.position))); }