コード例 #1
0
    //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]);
    }
コード例 #2
0
    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();
        }
    }
コード例 #3
0
    void processFile()
    {
        done = false;

        StreamReader reader = new StreamReader(path);

        //read header
        curMode = 0;
        Debug.Log(reader.ReadLine());
        Debug.Log(reader.ReadLine());
        Debug.Log(reader.ReadLine());
        Debug.Log(reader.ReadLine());
        Debug.Log(reader.ReadLine());
        Debug.Log(reader.ReadLine());
        animData.createBase(readToSpaceInt(reader.ReadLine()));            // number of segments
        animData.generateFrames(readToSpaceInt(reader.ReadLine()));        //number of frames
        animData.setFramePerSecond(readToSpaceInt(reader.ReadLine()));     //frame rate
        Debug.Log(reader.ReadLine());                                      //rotation order
        animData.setCalibrationUnit(readToSpaceString(reader.ReadLine())); //calibration units
        Debug.Log(reader.ReadLine());                                      //rotation units
        Debug.Log(reader.ReadLine());                                      //globalaxisofGravity
        Debug.Log(reader.ReadLine());                                      //bone length axis
        animData.scaleFactor = readToSpaceFloat(reader.ReadLine());        //scale factor
        //end of header

        //for setting hierarchy
        int            jointCount       = 0;                   //keep track of the where the index it is putting in the basepose
        List <string>  jointIndexList   = new List <string>(); //keeps track of the string names for easier hierarchy building/checking
        string         currentJoint     = "";                  //for keyframing
        gameObjectMain mainObjStructure = null;

        while (!done)
        {
            string textLine = "";
            if (readLine(ref textLine, ref reader, ref currentJoint))
            {
                if (curMode == currentHTRMode.SEGMENTHIERARCHY)
                {
                    string first = "", second = "";
                    parseTextToTwoBetweenTab(ref first, ref second, textLine); //find the two strings

                    //add and update joint
                    animData.poseBase[jointCount].name = first;
                    jointIndexList.Add(first);

                    //generate parent index using the jointIndexList
                    if (second != "GLOBAL")
                    {
                        animData.poseBase[jointCount].parentNodeIndex = jointIndexList.IndexOf(second);
                    }
                    else
                    {
                        animData.poseBase[jointCount].parentNodeIndex = -1;
                    }

                    jointCount++;
                }
                else if (curMode == currentHTRMode.BASE_POSITION)
                {
                    //create base pose
                    DataInput data  = superParseDataIntoInputBase(textLine);
                    int       index = jointIndexList.IndexOf(data.name);
                    animData.poseBase[index].boneLength = data.boneLength;

                    //generate local matrix using pared data
                    Matrix4x4 localMat = Matrix4x4.TRS(data.transform, Quaternion.Euler(data.rotation), new Vector4(1, 1, 1, 1));
                    animData.poseBase[index].localBaseTransform = localMat;

                    //do forward kinematics
                    int parentIndex = animData.poseBase[index].parentNodeIndex;

                    GameObject parentObj = null;
                    if (parentIndex == -1)
                    {
                        //is root
                        animData.poseBase[index].globalBaseTransform = localMat;

                        //generate joint in scene (test) https://answers.unity.com/questions/402280/how-to-decompose-a-trs-matrix.html
                        GameObject newJoint = Instantiate(jointObject, animData.poseBase[index].globalBaseTransform.GetColumn(3), Quaternion.Euler((animData.poseBase[index].globalBaseTransform.GetRow(1))));
                        newJoint.name = data.name;

                        newJoint.AddComponent <gameObjectMain>();
                        mainObjStructure = newJoint.GetComponent <gameObjectMain>();
                        mainObjStructure.newList();
                        mainObjStructure.addObject(newJoint);
                    }
                    else
                    {
                        //create global transform by taking the parent's transform and multiply with the local matrix
                        animData.poseBase[index].globalBaseTransform = (animData.poseBase[parentIndex].globalBaseTransform * localMat);
                        parentObj = mainObjStructure.getObject(parentIndex);

                        //generate joint in scene (test) https://answers.unity.com/questions/402280/how-to-decompose-a-trs-matrix.html
                        GameObject newJoint = Instantiate(jointObject, animData.poseBase[index].globalBaseTransform.GetColumn(3), Quaternion.Euler((animData.poseBase[index].globalBaseTransform.GetRow(1))), parentObj.transform);
                        newJoint.name = data.name;
                        mainObjStructure.addObject(newJoint);
                    }

                    animData.poseBase[index].currentTransform = animData.poseBase[index].globalBaseTransform;
                }
                else if (curMode == currentHTRMode.FRAMING)
                {
                    //get the keyframe and set it in
                    DataInput data  = superParseDataIntoInputKeyFrame(textLine);
                    int       index = jointIndexList.IndexOf(currentJoint);
                    animData.poseBase[index].keyFrames[data.frame].atFrame     = data.frame;
                    animData.poseBase[index].keyFrames[data.frame].keyPosition = data.transform;
                    animData.poseBase[index].keyFrames[data.frame].keyRotation = data.rotation;
                    animData.poseBase[index].keyFrames[data.frame].scale       = new Vector3(data.scaleFactor, data.scaleFactor, data.scaleFactor);
                }
            }
        }
    }