Exemplo n.º 1
0
    // ----- end of public functions -----


    // loads the specified fbx file
    private bool LoadFile()
    {
        if (!bFbxInited)
        {
            return(false);
        }

        if (!SaveFileIfNeeded())
        {
            throw new Exception("Could not save the modified file to: " + saveFilePath);
        }

        string sLoadFbxFile = loadFilePath;

        if (loadSaveFileIfExists && saveFilePath != string.Empty && File.Exists(saveFilePath))
        {
            sLoadFbxFile = saveFilePath;
        }

        if (sLoadFbxFile != string.Empty)
        {
            bFbxLoaded = MocapFbxWrapper.LoadFbxFile(sLoadFbxFile, false);
        }
        else
        {
            bFbxLoaded = false;
        }

        if (avatarCtrl && manager && manager.IsInitialized())
        {
            // get the pre- and post-rotations
            int jointCount = manager.GetJointCount();

            lastSavedPos = new Vector3[jointCount + 2];
            lastSavedRot = new Quaternion[jointCount + 2];

            for (int j = 0; j < (jointCount + 2); j++)
            {
                lastSavedPos [j] = Vector3.zero;
                lastSavedRot [j] = Quaternion.identity;
            }

            alJointPreRots  = new Quaternion[jointCount + 2];
            alJointPostRots = new Quaternion[jointCount + 2];

            for (int j = 0; j < jointCount; j++)
            {
                int       boneIndex      = avatarCtrl.GetBoneIndexByJoint((KinectInterop.JointType)j, false);
                Transform jointTransform = avatarCtrl.GetBoneTransform(boneIndex);

                alJointPreRots [j]  = GetJointPreRot(jointTransform);
                alJointPostRots [j] = GetJointPostRot(jointTransform);
            }

            // get special transforms
            int       specIndex     = avatarCtrl.GetSpecIndexByJoint(KinectInterop.JointType.ShoulderLeft, KinectInterop.JointType.SpineShoulder, false);
            Transform specTransform = avatarCtrl.GetBoneTransform(specIndex);
            alJointPreRots [jointCount]  = GetJointPreRot(specTransform);
            alJointPostRots [jointCount] = GetJointPostRot(specTransform);

            specIndex     = avatarCtrl.GetSpecIndexByJoint(KinectInterop.JointType.ShoulderRight, KinectInterop.JointType.SpineShoulder, false);
            specTransform = avatarCtrl.GetBoneTransform(specIndex);
            alJointPreRots [jointCount + 1]  = GetJointPreRot(specTransform);
            alJointPostRots [jointCount + 1] = GetJointPostRot(specTransform);
        }
        else
        {
            bFbxLoaded = false;
        }

        bFbxDirty = false;

        return(bFbxLoaded);
    }