首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

3D模型动画片技术 - 皮肤变形计算(skinned meshes)

2013-11-02 
3D模型动画技术 - 皮肤变形计算(skinned meshes)uniform extern float4x4 gWorlduniform extern float4x4

3D模型动画技术 - 皮肤变形计算(skinned meshes)

uniform extern float4x4 gWorld;uniform extern float4x4 gWorldInvTrans;uniform extern float4x4 gWVP;// The matrix palette.uniform extern float4x4 gFinalXForms[35];OutputVS VBlend2VS(float3 posL : POSITION0, float3 normalL : NORMAL0, float2 tex0 : TEXCOORD0, float weight0 : BLENDWEIGHT0, int4 boneIndex : BLENDINDICES0){ // Zero out our output. OutputVS outVS = (OutputVS)0; // 计算顶点的公式算法.这个是本章重点 float weight1 = 1.0f - weight0;//因为权重加起来是1的,所以weight1+weight0 = 1; float4 p = weight0 * mul(float4(posL, 1.0f), gFinalXForms[boneIndex[0]]); p += weight1 * mul(float4(posL, 1.0f), gFinalXForms[boneIndex[1]]); p.w = 1.0f; // 计算单位法向量的公式算法,这个也是本章重点 float4 n = weight0 * mul(float4(normalL, 0.0f), gFinalXForms[boneIndex[0]]); n += weight1 * mul(float4(normalL, 0.0f), gFinalXForms[boneIndex[1]]); n.w = 0.0f; // Transform normal to world space. outVS.normalW = mul(n, gWorldInvTrans).xyz; // Transform vertex position to world space. float3 posW = mul(p, gWorld).xyz; // Transform to homogeneous clip space. outVS.posH = mul(p, gWVP); . . // 其他代码与本章无关. .}

typedef struct _D3DXFRAME { LPSTR Name; D3DXMATRIX TransformationMatrix; LPD3DXMESHCONTAINER pMeshContainer; struct _D3DXFRAME *pFrameSibling; struct _D3DXFRAME *pFrameFirstChild;} D3DXFRAME, *LPD3DXFRAME;

struct FrameEx : public D3DXFRAME{ D3DXMATRIX toRoot;};

void SkinnedMesh::buildToRootXForms(FrameEx* frame, D3DXMATRIX& parentsToRoot){ // Save some references to economize line space. D3DXMATRIX& toParent = frame->TransformationMatrix; D3DXMATRIX& toRoot = frame->toRoot; toRoot = toParent * parentsToRoot; FrameEx* sibling = (FrameEx*)frame->pFrameSibling; FrameEx* firstChild = (FrameEx*)frame->pFrameFirstChild; // Recurse down siblings. if( sibling ) buildToRootXForms(sibling, parentsToRoot); // Recurse to first child. if( firstChild ) buildToRootXForms(firstChild, toRoot);}

D3DXMATRIX identity;D3DXMatrixIdentity(&identity);buildToRootXForms((FrameEx*)mRoot, identity);

identity表示是对角单位矩阵,也就相当于数学的1,不过这里的是矩阵的1,任何数乘以对角单位矩阵都等于1.

因为我们本来就把根节点放置到世界坐标中,所以不需要转移或者变形。

热点排行