问题:如何为COLLADA模型添加动画?

10

我在对加载的COLLADA模型进行动画处理时遇到了一些问题。我已经编写了自己的解析器,现在我也想编写自己的绘制程序。问题是,一旦我在模型上启用动画,手、腿和头部就会从模型的原点拉伸开来。(加载器是基于这里的教程实现的:COLLADA教程

在我的模型绘制函数中,我首先要做的是使用读取块中给定的目标设置关节矩阵(而不是它的世界矩阵!), 例如,如果我读取一个通道:

<channel source="#some_sampler" target="some_joint/transform(3)(2)"/>

在第一步中,我将使用sid="transform"的jointMatrix从关节的联合矩阵中修改矩阵组件(3)(2)。
if( mCurrentAnimations_.size() > 0 ) {
    unsigned currentFrame = GEAR::Root::getSingleton().getFrameEvent().frame;
    bool updateTime = false;
    if( currentFrame != mLastFrameUpdate_ ) {
        if( timeSinceLastFrame < 1.0f ) 
            updateTime = true;
        mLastFrameUpdate_ = currentFrame;
    }

    /****************************************************
     * If we have an active animation,                  *
     * we animate it in each of it's defined channels   *
     ***************************************************/
    std::list<DAEAnimation*>::iterator it = mCurrentAnimations_.begin();
    while( it != mCurrentAnimations_.end() ) {
        for( int c = 0; c < (*it)->animation->channels.size(); ++c ) {
            // update the time of the channelanimation if requested
            if( updateTime ) {
                (*it)->channelStates[c].elapsedTime += timeSinceLastFrame;
            }

            GEAR::COLLADA::Channel* channel = (*it)->animation->channels[c];
            // read the two indices depending on the time we're 
            int firstKeyframeTimeIndex = 0;
            int secondKeyframeTimeIndex = 0;
            for( int i = 0; i < channel->sampler->inputSource->mFloatArray_->mCount_; ++i ) {
                float time = channel->sampler->inputSource->mFloatArray_->mFloats_[i];
                if( firstKeyframeTimeIndex == secondKeyframeTimeIndex && time > (*it)->channelStates[c].elapsedTime && i > 0) {
                    firstKeyframeTimeIndex = i-1;
                    secondKeyframeTimeIndex = i;
                    break;
                }
                if( firstKeyframeTimeIndex == secondKeyframeTimeIndex && i == channel->sampler->inputSource->mFloatArray_->mCount_-1 ) {
                    (*it)->channelStates[c].elapsedTime = 0.0f;
                    firstKeyframeTimeIndex = i;
                    secondKeyframeTimeIndex = 0;
                    break;
                }
            }
            // look what kind of TargetAccessor we have
            if( channel->targetAccessor != NULL && channel->targetAccessor->type == GEAR::MATRIX_ACCESSOR ) {
                // ok we have to read 1 value for first and second index
                float firstValue = channel->sampler->outputSource->mFloatArray_->mFloats_[firstKeyframeTimeIndex];
                float secondValue = channel->sampler->outputSource->mFloatArray_->mFloats_[secondKeyframeTimeIndex];

                float firstTime = channel->sampler->inputSource->mFloatArray_->mFloats_[firstKeyframeTimeIndex];
                float secondTime = channel->sampler->inputSource->mFloatArray_->mFloats_[secondKeyframeTimeIndex];
                float interpolateValue = 1.0f / (secondTime - firstTime) * (secondTime - (*it)->channelStates[c].elapsedTime);
                // now we calculate an linear interpolated value
                float value = (secondValue*interpolateValue) + (firstValue*(1.0-interpolateValue));

                // now we have to write this value to the Joint's Matrix
                int entry = ((COLLADA::MatrixTargetAccessor*)channel->targetAccessor)->firstAccessor*4+((COLLADA::MatrixTargetAccessor*)channel->targetAccessor)->secondAccessor;
                channel->targetJoint->matrix->jointSpaceMatrix.entries[entry] = channel->targetJoint->matrix->matrix.entries[entry] + value;
            }
        }
        ++it;
    }
}

在所有通道修改jointMatrices之后,我通过在根Joint上调用以下函数重新计算关节的worldMatrices:

    void 
COLLADA::Joint::recalcWorldSpaceTransMat() {
    GEAR::Mat4 parentMat;
    if( parent != NULL )
        parentMat = parent->worldSpaceTransformationMatrix;
    // @todo Here we have to test against NULL!
    if( matrix != NULL ) 
        this->worldSpaceTransformationMatrix = parentMat * matrix->jointSpaceMatrix;
    else {
        this->worldSpaceTransformationMatrix = parentMat;
    }
    //std::cout << "Joint " << sid << " recalculated\n";
    for( int i = 0; i < mChildJoints_.size(); ++i )
        mChildJoints_[i]->recalcWorldSpaceTransMat();
}

现在一切都准备好了,可以使用绘制函数的以下最后一部分来绘制我的模型宽度:

for( int i = 0; i < mSubMeshes_.size(); ++i ) {
    for( int k = 0; k < mSubMeshes_[i]->mSubMeshes_.size(); ++k ) {
        // first we animate it
        GEAR::DAESubMesh* submesh = mSubMeshes_[i]->mSubMeshes_[k];
        submesh->buffer->lock( true );
        {
            for( unsigned v = 0; v < submesh->buffer->getNumVertices(); ++v ) {
                // get the array of joints, which influence the current vertex
                DAEVertexInfo* vertexInfo = submesh->vertexInfo[v];
                GEAR::Vec3 vertex; // do not init the vertex with any value!
                float totalWeight = 0.0f;
                for( int j = 0; j < vertexInfo->joints.size(); ++j ) {
                    Mat4& invBindPoseMatrix = vertexInfo->joints[j]->joint->invBindPoseMatrix;
                    Mat4& transMat = vertexInfo->joints[j]->joint->worldSpaceTransformationMatrix;
                    totalWeight += vertexInfo->joints[j]->weight;
                    vertex += (transMat*invBindPoseMatrix*(submesh->skin->bindShapeMatrix*vertexInfo->vertex))*vertexInfo->joints[j]->weight;
                }
                if( totalWeight != 1.0f ) {
                    float normalizedWeight = 1.0f / totalWeight;
                    vertex *= normalizedWeight;
                }
                submesh->buffer->bufferVertexPos( v, vertex );
            }
        }
        submesh->buffer->unlock();

        mSubMeshes_[i]->mSubMeshes_[k]->buffer->draw( GEAR::TRIANGLES, 0, mSubMeshes_[i]->mSubMeshes_[k]->buffer->getNumVertices() );
    }
}

现在问题是,输出结果看起来像这样:enter image description here

我确定数据加载程序实现正确,因为行走人物的一般动画是可见的,但网格被扭曲了:enter image description here

就像我说的那样,当我取消注释这行时:

channel->targetJoint->matrix->jointSpaceMatrix.entries[entry] = channel->targetJoint->matrix->matrix.entries[entry] + value;

动画已禁用,模型以其标准姿势显示: enter image description here 现在另外,在我重新计算关节的 worldMatrix 之前,当我向 jointMatrices 的前 3 列添加归一化时:
GEAR::Vec3 row1( matrix->jointSpaceMatrix.entries[0], matrix->jointSpaceMatrix.entries[1], matrix->jointSpaceMatrix.entries[2] );
row1.normalize();
matrix->jointSpaceMatrix.entries[0] = row1.x;
matrix->jointSpaceMatrix.entries[1] = row1.y;
matrix->jointSpaceMatrix.entries[2] = row1.z;
GEAR::Vec3 row2( matrix->jointSpaceMatrix.entries[4], matrix->jointSpaceMatrix.entries[5], matrix->jointSpaceMatrix.entries[6] );
row2.normalize();
matrix->jointSpaceMatrix.entries[4] = row2.x;
matrix->jointSpaceMatrix.entries[5] = row2.y;
matrix->jointSpaceMatrix.entries[6] = row2.z;
GEAR::Vec3 row3( matrix->jointSpaceMatrix.entries[8], matrix->jointSpaceMatrix.entries[9], matrix->jointSpaceMatrix.entries[10] );
row3.normalize();
matrix->jointSpaceMatrix.entries[8] = row3.x;
matrix->jointSpaceMatrix.entries[9] = row3.y;
matrix->jointSpaceMatrix.entries[10] = row3.z;

问题仍然存在,但这次是在另一个输出中。现在的人看起来像外星人:D,但这减少了缩放: enter image description here

我不确定我是否以正确的方式进行了规范化。这种规范化真的有必要吗?它没有在教程中描述,我也找不到任何相关的信息。

最后,我查看了教程页面上插值实现的代码。他们根本没有使用四元数来插值整个矩阵。他们所做的是以下内容(对我来说不起作用):

        Mat4 temp;

    for (int i = 0; i < 16; ++i)
        temp.entries[i] = interpolatef(matrix->jointSpaceMatrixStart.entries[i],matrix->jointSpaceMatrixFinish.entries[i],matrix->delta);

    Vec3 forward,up,right,translation;
    forward = Vec3(temp.entries[8], temp.entries[9], temp.entries[10]);
    up= Vec3(temp.entries[4], temp.entries[5], temp.entries[6]);
    right = Vec3(temp.entries[0], temp.entries[1], temp.entries[2]);

    forward.normalize();
    up.normalize();
    right.normalize();

    temp.entries[8] = forward.x; temp.entries[9] = forward.y; temp.entries[10] = forward.z;
    temp.entries[4] = up.x; temp.entries[5] = up.y; temp.entries[6] = up.z;
    temp.entries[0] = right.x; temp.entries[1] = right.y; temp.entries[2] = right.z;

    matrix->jointSpaceMatrix = GEAR::Mat4(temp);

然后我尝试了另一种方法,使用四元数(也不适用于我):

        // wat we need for interpolation: rotMatStart, rotMatFinish, delta

    // create rotation matrices from our 2 given matrices
    GEAR::Mat4 rotMatStart = matrix->jointSpaceMatrixStart;
    rotMatStart.setTranslationPart( GEAR::VEC3_ZERO );
    GEAR::Mat4 rotMatFinish = matrix->jointSpaceMatrixFinish;
    rotMatFinish.setTranslationPart( GEAR::VEC3_ZERO );

    rotMatStart.transpose();
    rotMatFinish.transpose();

    // create Quaternions, which represent these 2 matrices
    float w = GEAR::Tools::sqr(1.0 + rotMatStart.entries[0] + rotMatStart.entries[5] + rotMatStart.entries[10]) / 2.0;
    float w4 = (4.0 * w);
    float x = (rotMatStart.entries[6] - rotMatStart.entries[9]) / w4 ;
    float y = (rotMatStart.entries[8] - rotMatStart.entries[2]) / w4 ;
    float z = (rotMatStart.entries[1] - rotMatStart.entries[4]) / w4 ;
    GEAR::Quaternion rotQuadStart(x, y, z, w);
    rotQuadStart.normalize();
    w = GEAR::Tools::sqr(1.0 + rotMatFinish.entries[0] + rotMatFinish.entries[5] + rotMatFinish.entries[10]) / 2.0;
    w4 = (4.0 * w);
    x = (rotMatFinish.entries[6] - rotMatFinish.entries[9]) / w4 ;
    y = (rotMatFinish.entries[8] - rotMatFinish.entries[2]) / w4 ;
    z = (rotMatFinish.entries[1] - rotMatFinish.entries[4]) / w4 ;
    GEAR::Quaternion rotQuadFinish(x, y, z, w);
    rotQuadFinish.normalize();

    // create the interpolated rotation matrix
    GEAR::Quaternion slerpedRotQuat = slerp(rotQuadStart, rotQuadFinish, matrix->delta );
    slerpedRotQuat.normalize();
    GEAR::Mat4 rotMat;
    slerpedRotQuat.createMatrix( rotMat );

    // interpolate the translation part
    GEAR::Vec3 transVecStart(0.0,0.0,0.0);
    matrix->jointSpaceMatrixStart.getTranslatedVector3D( transVecStart );
    GEAR::Vec3 transVecFinish(0.0,0.0,0.0);
    matrix->jointSpaceMatrixFinish.getTranslatedVector3D( transVecFinish );

    GEAR::Mat4 transMat;
    transMat.setTranslation( transVecFinish*matrix->delta + (transVecStart*(1.0f-matrix->delta)) );
    // now write the resulting Matrix back to the Joint
    matrix->jointSpaceMatrix = transMat * rotMat;

这对我也不起作用。似乎什么都不起作用。我真的不知道发生了什么。


现在2天过去了,多亏了datenwolf的答案,我已经把它搞定了

我想告诉大家我是如何让它工作的。现在一切都很清楚,一直只是一个小步骤。现在我们开始处理动画部分。我遍历所有通道,并将起始值和结束值以及范围为0.0到1.0的插值增量保存到关节中,该通道进行动画:

if( mCurrentAnimations_.size() > 0 ) {
    unsigned currentFrame = GEAR::Root::getSingleton().getFrameEvent().frame;
    bool updateTime = false;
    if( currentFrame != mLastFrameUpdate_ ) {
        if( timeSinceLastFrame < 1.0f ) 
            updateTime = true;
        mLastFrameUpdate_ = currentFrame;
    }

    /****************************************************
     * If we have an active animation,                  *
     * we animate it in each of it's defined channels   *
     ***************************************************/
    std::list<DAEAnimation*>::iterator it = mCurrentAnimations_.begin();
    while( it != mCurrentAnimations_.end() ) {
        for( int c = 0; c < (*it)->animation->channels.size(); ++c ) {
            // update the time of the channelanimation if requested
            if( updateTime ) {
                (*it)->channelStates[c].elapsedTime += timeSinceLastFrame;
            }

            GEAR::COLLADA::Channel* channel = (*it)->animation->channels[c];
            // read the two indices depending on the time we're 
            int firstIndex = 0;
            int secondIndex = 1;
            for( int i = 0; i < channel->sampler->inputSource->mFloatArray_->mCount_; ++i ) {
                float time = channel->sampler->inputSource->mFloatArray_->mFloats_[i];
                if( time > (*it)->channelStates[c].elapsedTime ) {
                    firstIndex = i-1;
                    secondIndex = i;
                    if( firstIndex == -1 ) // set to last frame
                        firstIndex = channel->sampler->inputSource->mFloatArray_->mCount_ - 1;
                    break;
                }
                else if( i == channel->sampler->inputSource->mFloatArray_->mCount_ - 1 ) {
                    (*it)->channelStates[c].elapsedTime -= channel->sampler->inputSource->mFloatArray_->mFloats_[i];
                    firstIndex = 0;
                    secondIndex = 1;
                    break;
                }
            }
            // look what kind of TargetAccessor we have
            if( channel->targetAccessor != NULL && channel->targetAccessor->type == GEAR::MATRIX_ACCESSOR ) {
                /************************************************************************
                 * Matrix accessors, which are read from a COLLADA <channel> block      *
                 * will always target one matrix component they animate.                *
                 * Such accessors are for example:                                      *
                 * <channel source"#someSource" target="someJoint/transform(0)(2)"/>    *
                 *                                                                      *
                 * @TODO:                                                               *
                 * In a pre processing step, we have to group all channels, which       *
                 * operate on the same joint. In order to accelerate the processing of  *
                 * grouped channels, we have to expand the number of keyframes of all   *
                 * channels to the maximum of all channels.                             *
                 ************************************************************************/
                unsigned entry = ((COLLADA::MatrixTargetAccessor*)channel->targetAccessor)->index;
                float firstTime = channel->sampler->inputSource->mFloatArray_->mFloats_[firstIndex];
                float secondTime = channel->sampler->inputSource->mFloatArray_->mFloats_[secondIndex];
                // in case of matrix accessor, we write the startMatrix and the endMatrix to the Joints accessor, who finally will do the animation interpolation
                channel->targetJoint->matrix->interpolationRequired = true;
                // write out the start and end value to the jointSpaceMatrix
                // this matrix will later be interpolated
                channel->targetJoint->matrix->jointSpaceMatrixStart.entries[entry] = channel->sampler->outputSource->mFloatArray_->mFloats_[firstIndex];
                channel->targetJoint->matrix->jointSpaceMatrixFinish.entries[entry] = channel->sampler->outputSource->mFloatArray_->mFloats_[secondIndex];
                // the delta value is in the range [0.0,1.0]
                channel->targetJoint->matrix->delta = 1.0f / (secondTime - firstTime) * (secondTime - (*it)->channelStates[c].elapsedTime);
            }
        }
        ++it;
    }
}

正如你所看到的,这里根本没有插值。我们只是缓存了所有动画关节的起始值、结束值和增量(并且还在每个修改过的关节上设置了一个标志)。

现在,在所有动画完成后,我们对所有根关节调用函数 interpolateMatrices():

    for( int i = 0; i < mSourceModel_->mVisualSceneLibrary_.mVisualScenes_.size(); ++i ) {
    for( int v = 0; v < mSourceModel_->mVisualSceneLibrary_.mVisualScenes_[i]->mSkeleton_.size(); ++v ) {
        if( mSourceModel_->mVisualSceneLibrary_.mVisualScenes_[i]->mSkeleton_[v]->mRootJoint_ != NULL ) {
            /************************************************************************************
             * Now we have constructed all jointSpaceMatrixces for the start and the end and    *
             * we're ready to interpolate them and to also recalculate the joint's              *
             * worldSpaceMatrix.                                                                *
             ***********************************************************************************/
            mSourceModel_->mVisualSceneLibrary_.mVisualScenes_[i]->mSkeleton_[v]->mRootJoint_->interpolateMatrices();
        }
    }
}

这并不是什么新鲜事,但现在有趣的部分是插值的实现。完全没有四元数的内容:

void COLLADA::Joint::interpolateMatrices() {
if( matrix != NULL && matrix->interpolationRequired ) {

    for (unsigned i = 0; i < 16; ++i)
        matrix->jointSpaceMatrix.entries[i] = interpolatef(matrix->jointSpaceMatrixStart.entries[i],matrix->jointSpaceMatrixFinish.entries[i],matrix->delta);

    Vec3 forward,up,right,translation;
    forward = Vec3(matrix->jointSpaceMatrix.entries[8], matrix->jointSpaceMatrix.entries[9], matrix->jointSpaceMatrix.entries[10]);
    up= Vec3(matrix->jointSpaceMatrix.entries[4], matrix->jointSpaceMatrix.entries[5], matrix->jointSpaceMatrix.entries[6]);
    right = Vec3(matrix->jointSpaceMatrix.entries[0], matrix->jointSpaceMatrix.entries[1], matrix->jointSpaceMatrix.entries[2]);

    forward.normalize();
    up.normalize();
    right.normalize();

    matrix->jointSpaceMatrix.entries[8] = forward.x; matrix->jointSpaceMatrix.entries[9] = forward.y; matrix->jointSpaceMatrix.entries[10] = forward.z;
    matrix->jointSpaceMatrix.entries[4] = up.x; matrix->jointSpaceMatrix.entries[5] = up.y; matrix->jointSpaceMatrix.entries[6] = up.z;
    matrix->jointSpaceMatrix.entries[0] = right.x; matrix->jointSpaceMatrix.entries[1] = right.y; matrix->jointSpaceMatrix.entries[2] = right.z;

    matrix->jointSpaceMatrix.entries[15] = 1.0f; // this component is always 1.0! In some files, this is exported the wrong way, which causes bugs!
}
/********************************************************
 * After the interpolation is finished,                 *
 * we have to recalculate the joint's worldSpaceMatrix. *
 ********************************************************/
GEAR::Mat4 parentMat;
if( parent != NULL )
    parentMat = parent->worldSpaceTransformationMatrix;
if( matrix != NULL ) 
    worldSpaceTransformationMatrix = (parentMat * matrix->jointSpaceMatrix);
else 
    worldSpaceTransformationMatrix = parentMat;
skinningMatrix = worldSpaceTransformationMatrix*invBindPoseMatrix;

// also interpolate and recalculate all childs
for( unsigned k = 0; k < mChildJoints_.size(); ++k )
    mChildJoints_[k]->interpolateMatrices();

}

正如您所看到的,我们只是插值矩阵的所有值,然后规范化矩阵的上三列。 之后,我们立即重新计算该关节的worldSpaceMatrix以及完整的蒙皮矩阵以提高性能。 现在,我们几乎完成了所有工作。最后要做的就是真正地对顶点进行动画处理,然后绘制网格:

for( int i = 0; i < mSubMeshes_.size(); ++i ) {
    for( int k = 0; k < mSubMeshes_[i]->mSubMeshes_.size(); ++k ) {
        // first we animate it
        GEAR::DAESubMesh* submesh = mSubMeshes_[i]->mSubMeshes_[k];
        submesh->buffer->lock( true );
        {
            for( unsigned v = 0; v < submesh->buffer->getNumVertices(); ++v ) {
                // get the array of joints, which influence the current vertex
                DAEVertexInfo* vertexInfo = submesh->vertexInfo[v];
                GEAR::Vec3 vertex; // do not init the vertex with any value!
                float totalWeight = 0.0f;
                for( int j = 0; j < vertexInfo->joints.size(); ++j ) {
                    totalWeight += vertexInfo->joints[j]->weight;
                    vertex += ((vertexInfo->joints[j]->joint->skinningMatrix*(vertexInfo->vertex))*vertexInfo->joints[j]->weight);
                }
                // since it isn't guaranteed that the total weight is exactly 1.0, we have no normalize it
                // @todo this should be moved to the parser
                if( totalWeight != 1.0f ) {
                    float normalizedWeight = 1.0f / totalWeight;
                    vertex *= normalizedWeight;
                }
                submesh->buffer->bufferVertexPos( v, vertex );
            }
        }
        submesh->buffer->unlock();

        mSubMeshes_[i]->mSubMeshes_[k]->buffer->draw( GEAR::TRIANGLES, 0, mSubMeshes_[i]->mSubMeshes_[k]->buffer->getNumVertices() );
    }
}

总的来说,它与我最初开始的代码几乎相同。但现在对我来说更清晰了,我还可以支持<translation>、<rotation>和<scale>动画。请随意查看我的实现gear3d.de(下载SVN trunk)。
希望这能帮助一些正在实现自己解决方案的人,这是一个美妙的主题 :)

1
+1;一个写得好的问题,包含必要的代码和对错误及期望正确结果的精确描述。 - datenwolf
2个回答

4

看这些图片,我有一种印象,你的联合矩阵没有标准化,即左上角的3×3部分放大了你的网格。尝试一下如果标准化左上角的3列向量会发生什么。

如果这样可以解决问题,就需要调查动画系统的哪个部分导致了这个问题。


谢谢你的回答和帮助。我现在已经测试了规范化,但我不确定我是否做得正确。安迪 - Andy Reimann
@Andy:规范化只是为了缩小问题范围的测试。最终,您必须正确进行动画插值。我在那里读到了一条评论,说您正在执行线性插值。当插值(旋转)矩阵时,这通常不是正确的方法。 - datenwolf
你对此有其他的想法吗?我已经尝试了几乎所有组合,但没有好的结果。我不知道你是否熟悉COLLADA。在COLLADA中,你有动画,它们被分成包含任何数据(如时间值、变换值和插值值)的源,包含对源的引用的采样器和包含对采样器和关节的引用的通道。对关节的引用定义了要进行动画处理的组件。在我的情况下,所有的引用都指向矩阵组件。这就是为什么我只插值一个矩阵组件的原因。 - Andy Reimann

1
在我的情况下,所有引用都针对矩阵分量。这就是为什么我只插值一个矩阵分量的原因。
永远不要插值矩阵。
通常处理方式是,在加载动画数据时,将每个矩阵分解为四元数和位置(如果您正在动画缩放,则还包括缩放)。使用四元数是因为它们体积小,易于插值,并且容易在插值后规范化。与矩阵不同,矩阵大,难以插值,并且难以进行正交归一化。
请注意,上述通常作为工具中的预处理步骤完成。该工具加载Collada动画,转换为四元数和位置,然后将其写入文件格式以供以后读取。
因此,您可以根据需要插值四元数(随意在动画内插值使用LERP),并快速进行规范化。仅当相对于原始偏移量实际更改位置时,才需要更新位置。将它们组合回矩阵,并像往常一样继续执行。
简单又容易。

谢谢您的回答。我已经使用四元数来实现它,但是迄今为止没有好的结果。在上面的代码中,我在插值上添加了一些额外的东西。如果您能看一下就太好了。 - Andy Reimann
2
在顶点混合中,插值矩阵的不准确通常是可以容忍的(矩阵调色板蒙皮是实时顶点混合的事实标准),所以你的“永远”有点错误。显式(四元数、平移)对也有其缺点。一个非常好的替代矩阵调色板蒙皮的方法是双四元数蒙皮,它可以在不增加太多运行时间成本的情况下减少通常的顶点混合伪影,并且没有(四元数、平移)对的缺失坐标系独立性问题。 - Christian Rau
@Christian Rau:即使您可以在没有正交规范化的情况下处理插值伪影,四元数仍然更受青睐,因为它们更小,压缩更容易,并且甚至可以更快地插值(只需4个值而不是9个)。直接插值矩阵就没有任何理由。 - Nicol Bolas
@Nicol 使用四元数可能会在非常复杂的关节(如肩膀)出现问题,因为很难选择有效的旋转中心。别忘了,我们正在插值全局变换,而不仅仅是本地简单的铰链关节。我更喜欢使用双四元数(它们隐式携带和插值旋转中心)进行皮肤绑定,它们可以兼顾两个世界的优点。 - Christian Rau
@Christian Rau:是的,但双四元数不是“矩阵”;它们是双四元数。我不反对您使用双四元数的建议;我不同意的是您的评估,即在动画中插值矩阵有任何理由。 - Nicol Bolas
@Nicol 快速、简便、坐标系不变。我知道前两个也适用于四元数和平移向量对。 - Christian Rau

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接