Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        // This code just adjusts the primitives and has no effect on the joint solver
        pelvisPrimitive.transform.localPosition = new Vector3(0.0f, pelvisLength / 2, 0.0f);
        waistPrimitive.transform.localPosition  = new Vector3(0.0f, waistLength / 2, 0.0f);
        torsoPrimitive.transform.localPosition  = new Vector3(0.0f, torsoLength / 2, 0.0f);
        Vector3 pelvisScale = new Vector3(0.5f, pelvisLength, 0.5f);
        Vector3 waistScale  = new Vector3(0.5f, waistLength, 0.5f);
        Vector3 torsoScale  = new Vector3(0.5f, torsoLength, 0.5f);

        pelvisPrimitive.transform.localScale = pelvisScale;
        waistPrimitive.transform.localScale  = waistScale;
        torsoPrimitive.transform.localScale  = torsoScale;

        // The code below demonstrates how to determine all joint rotations and positions from
        // the given control points and values
        root.transform.localPosition   = rootControl.localPosition;
        root.transform.localRotation   = rootControl.localRotation;
        pelvis.transform.localPosition = Vector3.zero;
        waist.transform.localPosition  = new Vector3(0.0f, pelvisLength, 0.0f);
        torso.transform.localPosition  = new Vector3(0.0f, waistLength, 0.0f);

        JointSolver.SpineSolverOutput output = solver.SpineRotationSolver(C_CurveX, C_CurveY, S_CurveX, S_CurveY, X_Angle_Max, Y_Angle_Max, pelvisLength, waistLength, torsoLength);
        pelvis.transform.localRotation = output.pelvisRotation;
        waist.transform.localRotation  = output.waistRotation;
        torso.transform.localRotation  = output.torsoRotation;

        neckMarker.transform.localPosition = new Vector3(0.0f, output.neckDistance, 0.0f);
    }
Beispiel #2
0
    // Below is an abstract list for all animation functions to override
    protected ClipContainer.AnimationGroup CreateClips(float animTime, string animName)
    {
        int i           = 0;
        int arrayLength = (int)(animTime / Time.deltaTime) + 1;

        float[] times = new float[arrayLength];

        Vector3[]    rootPos      = new Vector3[arrayLength];
        Quaternion[] rootPivotRot = new Quaternion[arrayLength];
        Quaternion[] pelvisRot    = new Quaternion[arrayLength];
        Quaternion[] waistRot     = new Quaternion[arrayLength];
        Quaternion[] torsoRot     = new Quaternion[arrayLength];
        Vector3[]    FL_hipPos    = new Vector3[arrayLength];
        Quaternion[] FL_hipRot    = new Quaternion[arrayLength];
        Quaternion[] FL_thighRot  = new Quaternion[arrayLength];
        Quaternion[] FL_calfRot   = new Quaternion[arrayLength];
        Quaternion[] FL_footRot   = new Quaternion[arrayLength];
        Quaternion[] FL_toeRot    = new Quaternion[arrayLength];
        Vector3[]    FR_hipPos    = new Vector3[arrayLength];
        Quaternion[] FR_hipRot    = new Quaternion[arrayLength];
        Quaternion[] FR_thighRot  = new Quaternion[arrayLength];
        Quaternion[] FR_calfRot   = new Quaternion[arrayLength];
        Quaternion[] FR_footRot   = new Quaternion[arrayLength];
        Quaternion[] FR_toeRot    = new Quaternion[arrayLength];
        Vector3[]    BL_hipPos    = new Vector3[arrayLength];
        Quaternion[] BL_hipRot    = new Quaternion[arrayLength];
        Quaternion[] BL_thighRot  = new Quaternion[arrayLength];
        Quaternion[] BL_calfRot   = new Quaternion[arrayLength];
        Quaternion[] BL_footRot   = new Quaternion[arrayLength];
        Quaternion[] BL_toeRot    = new Quaternion[arrayLength];
        Vector3[]    BR_hipPos    = new Vector3[arrayLength];
        Quaternion[] BR_hipRot    = new Quaternion[arrayLength];
        Quaternion[] BR_thighRot  = new Quaternion[arrayLength];
        Quaternion[] BR_calfRot   = new Quaternion[arrayLength];
        Quaternion[] BR_footRot   = new Quaternion[arrayLength];
        Quaternion[] BR_toeRot    = new Quaternion[arrayLength];
        JointSolver.SpineSolverOutput spine_out = new JointSolver.SpineSolverOutput();
        JointSolver.LegSolverOutput   FL_out    = new JointSolver.LegSolverOutput();
        JointSolver.LegSolverOutput   FR_out    = new JointSolver.LegSolverOutput();
        JointSolver.LegSolverOutput   BL_out    = new JointSolver.LegSolverOutput();
        JointSolver.LegSolverOutput   BR_out    = new JointSolver.LegSolverOutput();


        GameObject  solverObject = new GameObject("solverObject");
        JointSolver solver       = solverObject.AddComponent <JointSolver>();

        for (float t = 0.0f; t < animTime; t += Time.deltaTime)
        {
            // Call all animation functions and store values in appropriate variables
            rootPos[i]      = AF_rootPosition(t);
            rootPivotRot[i] = AF_rootPivotRotation(t);
            Vector3 FL_target = AF_FL_LegTarget(t);
            Vector3 FR_target = AF_FR_LegTarget(t);
            Vector3 BL_target = AF_BL_LegTarget(t);
            Vector3 BR_target = AF_BR_LegTarget(t);

            float hipWidth      = species.spineData.pelvisData.radiusA;
            float shoulderWidth = species.spineData.torsoData.radiusB;

            float spine_CX = AF_spine_CX(t);
            float spine_CY = AF_spine_CY(t);
            float spine_SX = AF_spine_SX(t);
            float spine_SY = AF_spine_SY(t);

            // Convert all function values to raw rotations and positions for each joint
            spine_out = solver.SpineRotationSolver(spine_CX, spine_CY, spine_SX, spine_SY, 90.0f, 90.0f,
                                                   species.spineData.pelvisData.length,
                                                   species.spineData.waistData.length,
                                                   species.spineData.torsoData.length);

            pelvisRot[i] = spine_out.pelvisRotation;
            waistRot[i]  = spine_out.waistRotation;
            torsoRot[i]  = spine_out.torsoRotation;

            //Vector3 sideHipPoint = rootPos[i] + rootPivotRot[i]*(new Vector3(0.0f,0.0f,hipWidth));
            BL_hipPos[i] = rootPos[i] + rootPivotRot[i] * (new Vector3(0.0f, 0.0f, hipWidth));
            BL_out       = solver.LegRotationSolver(BL_hipPos[i], BL_target,
                                                    species.backLegData.thighData.length,
                                                    species.backLegData.calfData.length,
                                                    species.backLegData.footData.length,
                                                    30.0f, 0.0f, false);
            BL_hipRot[i]   = BL_out.legPivotRotation;
            BL_thighRot[i] = BL_out.thighRotation;
            BL_calfRot[i]  = BL_out.calfRotation;
            BL_footRot[i]  = BL_out.footRotation;
            BL_toeRot[i]   = Quaternion.identity;

            BR_hipPos[i] = rootPos[i] + rootPivotRot[i] * (new Vector3(0.0f, 0.0f, -hipWidth));
            BR_out       = solver.LegRotationSolver(BR_hipPos[i], BR_target,
                                                    species.backLegData.thighData.length,
                                                    species.backLegData.calfData.length,
                                                    species.backLegData.footData.length,
                                                    30.0f, 0.0f, false);
            BR_hipRot[i]   = BR_out.legPivotRotation;
            BR_thighRot[i] = BR_out.thighRotation;
            BR_calfRot[i]  = BR_out.calfRotation;
            BR_footRot[i]  = BR_out.footRotation;
            BR_toeRot[i]   = Quaternion.identity;


            Vector3 neckPivot = rootPos[i] + rootPivotRot[i] * (new Vector3(0.0f, spine_out.neckDistance, 0.0f));

            FL_hipPos[i] = neckPivot + rootPivotRot[i] * pelvisRot[i] * waistRot[i] * torsoRot[i] * (new Vector3(0.0f, 0.0f, shoulderWidth));
            Debug.Log("FL_hipPos = " + FL_hipPos[i] + ", FL_target = " + FL_target);
            FL_out = solver.LegRotationSolver(FL_hipPos[i], FL_target,
                                              species.frontLegData.thighData.length,
                                              species.frontLegData.calfData.length,
                                              species.frontLegData.footData.length,
                                              30.0f, 0.0f, true);
            FL_hipRot[i]   = FL_out.legPivotRotation;
            FL_thighRot[i] = FL_out.thighRotation;
            FL_calfRot[i]  = FL_out.calfRotation;
            FL_footRot[i]  = FL_out.footRotation;
            FL_toeRot[i]   = Quaternion.identity;

            FR_hipPos[i] = neckPivot + rootPivotRot[i] * pelvisRot[i] * waistRot[i] * torsoRot[i] * (new Vector3(0.0f, 0.0f, -shoulderWidth));
            FR_out       = solver.LegRotationSolver(FR_hipPos[i], FR_target,
                                                    species.frontLegData.thighData.length,
                                                    species.frontLegData.calfData.length,
                                                    species.frontLegData.footData.length,
                                                    30.0f, 0.0f, true);
            FR_hipRot[i]   = FR_out.legPivotRotation;
            FR_thighRot[i] = FR_out.thighRotation;
            FR_calfRot[i]  = FR_out.calfRotation;
            FR_footRot[i]  = FR_out.footRotation;
            FR_toeRot[i]   = Quaternion.identity;

            times[i] = t;
            i++;
        }

        // Assign values to animation clips in new AnimationGroup and store in ClipContainer
        ClipContainer.AnimationGroup animGroup = new ClipContainer.AnimationGroup();
        animGroup.rootClip      = CreatePositionClip(rootPos, times, animName);
        animGroup.rootPivotClip = CreateRotationClip(rootPivotRot, times, animName);
        animGroup.pelvisClip    = CreateRotationClip(pelvisRot, times, animName);
        animGroup.waistClip     = CreateRotationClip(waistRot, times, animName);
        animGroup.torsoClip     = CreateRotationClip(torsoRot, times, animName);

        animGroup.FL_HipClip   = CreatePositionClip(FL_hipPos, times, animName);
        animGroup.FL_HipClip   = CreateRotationClip(animGroup.FL_HipClip, FL_hipRot, times);
        animGroup.FL_ThighClip = CreateRotationClip(FL_thighRot, times, animName);
        animGroup.FL_KneeClip  = CreateRotationClip(FL_calfRot, times, animName);
        animGroup.FL_AnkleClip = CreateRotationClip(FL_footRot, times, animName);
        animGroup.FL_ToeClip   = CreateRotationClip(FL_toeRot, times, animName);

        animGroup.FR_HipClip   = CreatePositionClip(FR_hipPos, times, animName);
        animGroup.FR_HipClip   = CreateRotationClip(animGroup.FR_HipClip, FR_hipRot, times);
        animGroup.FR_ThighClip = CreateRotationClip(FR_thighRot, times, animName);
        animGroup.FR_KneeClip  = CreateRotationClip(FR_calfRot, times, animName);
        animGroup.FR_AnkleClip = CreateRotationClip(FR_footRot, times, animName);
        animGroup.FR_ToeClip   = CreateRotationClip(FR_toeRot, times, animName);

        animGroup.BL_HipClip   = CreatePositionClip(BL_hipPos, times, animName);
        animGroup.BL_HipClip   = CreateRotationClip(animGroup.BL_HipClip, BL_hipRot, times);
        animGroup.BL_ThighClip = CreateRotationClip(BL_thighRot, times, animName);
        animGroup.BL_KneeClip  = CreateRotationClip(BL_calfRot, times, animName);
        animGroup.BL_AnkleClip = CreateRotationClip(BL_footRot, times, animName);
        animGroup.BL_ToeClip   = CreateRotationClip(BL_toeRot, times, animName);

        animGroup.BR_HipClip   = CreatePositionClip(BR_hipPos, times, animName);
        animGroup.BR_HipClip   = CreateRotationClip(animGroup.BR_HipClip, BR_hipRot, times);
        animGroup.BR_ThighClip = CreateRotationClip(BR_thighRot, times, animName);
        animGroup.BR_KneeClip  = CreateRotationClip(BR_calfRot, times, animName);
        animGroup.BR_AnkleClip = CreateRotationClip(BR_footRot, times, animName);
        animGroup.BR_ToeClip   = CreateRotationClip(BR_toeRot, times, animName);

        // etc...

        //SetAnimGroupName(ref animGroup, animName);
        GameObject.Destroy(solverObject);
        return(animGroup);
    }