public void setData(AnimationDataHierarchal animdata, int keyIndex) { size = animdata.poseBase.Length; poseData = new animationTransformData[size]; for (int i = 0; i < size; i++) { KeyFrame key = animdata.poseBase[i].keyFrames[keyIndex]; animationTransformData newdata = new animationTransformData(key.keyPosition, Quaternion.Euler(key.keyRotation), key.scale); poseData[i] = newdata; } }
private void OnGUI() { curMode = currentHTRMode.HEADER; jointObject = EditorGUILayout.ObjectField("AnimationObject", jointObject, typeof(GameObject), true) as GameObject; animData = EditorGUILayout.ObjectField("AnimationData", animData, typeof(AnimationDataHierarchal), true) as AnimationDataHierarchal; path = EditorGUILayout.TextField("AssestPath", path); if (GUILayout.Button("Process")) { if (animData != null) { processFile(); } else { Debug.Log("scriptable object missing!"); } } }
//used for blending, given a joint with a transform data and the hierarchies do forward kinematics public static void setData(gameObjectMain objHierarchy, AnimationDataHierarchal animData, animationTransformData transformData, int jointID) { int parentIndex = animData.poseBase[jointID].parentNodeIndex; Vector3 localPosition = animData.poseBase[jointID].getLocalPosition(); Vector3 localRotation = animData.poseBase[jointID].getLocalRotationEuler(); //find delta change from localpose Matrix4x4 deltaMatrix = Matrix4x4.TRS(localPosition + transformData.localPosition, Quaternion.Euler(localRotation + transformData.localRotation.eulerAngles), new Vector4(1, 1, 1, 1)); if (parentIndex == -1) { //is root animData.poseBase[jointID].currentTransform = deltaMatrix; } else { //current transform = take the parent index current transform and multiply with delta matrix animData.poseBase[jointID].currentTransform = animData.poseBase[parentIndex].currentTransform * deltaMatrix; } animData.poseBase[jointID].updateNewPosition(objHierarchy.ObjectHierarchy[jointID]); }
private void OnGUI() { Rect rectangle = new Rect(new Vector2(xShift, lineBasePosY), new Vector2(lineMaxPosX, lineMaxPosY - lineBasePosY)); EditorGUI.DrawRect(rectangle, Color.gray); animData = EditorGUILayout.ObjectField("AnimationData", animData, typeof(AnimationDataHierarchal), true) as AnimationDataHierarchal; gameObjectHierarchy = EditorGUILayout.ObjectField("GameObjectHierarchy", gameObjectHierarchy, typeof(gameObjectMain), true) as gameObjectMain; if (!animData) { GUILayout.Label("Need AnimationData"); } else { createNewHierarchy = EditorGUILayout.Toggle("Create New Hierarchy", createNewHierarchy); if (createNewHierarchy) { newHierarchy(); } modifyAnimationData(); drawPrimaryKeys(); } }
// Update is called once per frame void Update() { sprint = Input.GetKey(KeyCode.LeftShift); idle = Input.GetKey(KeyCode.W); //check if different input, MovementStance updatedStance; if (!idle) { if (sprint) { updatedStance = MovementStance.RUNNING; } else { updatedStance = MovementStance.WALKING; } } else { updatedStance = MovementStance.IDLE; } if (updatedStance != currentStance) { transitionParameter = 0; lerpin = true; prevAnim = setAnimData(currentStance); currentAnim = setAnimData(updatedStance); currentStance = updatedStance; } //update framecount; //update to next frame timer += Time.deltaTime; if (timer >= currentAnim.framePerSecond) { currentFrame++; timer = 0; if (currentFrame > currentAnim.totalFrameDuration) { currentFrame = 0; } } if (lerpin) { transitionParameter += .1f; if (transitionParameter >= 1) { transitionParameter = 1; lerpin = false; } } else { transitionParameter = 1; } blendAnimation(); }
void Start() { currentStance = 0; currentAnim = idleAnim; prevAnim = idleAnim; }