0
"私は骨格アニメーションを学ぶので、多くの誤解があります" Blenderからエクスポートされた非常に単純なJSON形式のファイルを1つのキューブと1つのボーンを4フレームだけ回転させたので、VBOこれは図4に示すように、正しくレンダリングされた位置vec4、通常vec4、重量VEC2と骨インデックスVEC2属性骨は、POSを有し、rotq及びスケーリング私は骨OpenGL ES2骨格アニメーション
public static float[] createMat4(float[] t, float[] r, float[] s) {
float[] mat4 = new float[16];
float[] T = new float[16];
float[] R = new float[16];
float[] S = new float[16];
setIdentityM(T, 0);
setIdentityM(R, 0);
setIdentityM(S, 0);
translateM(T, 0, t[0], t[1], t[2]);
rotateM(R, 0, r[3], r[0], r[1], r[2]);
scaleM(S, 0, s[0], s[1], s[2]);
float[] temp = new float[16];
multiplyMM(temp, 0, T, 0, R, 0);
multiplyMM(mat4, 0, temp, 0, S, 0);
return mat4;
}
の変換行列を作成するには、次の関数を使用してい
だから私は、各フレームの逆数 "私が理解しているように"バインドを掛け合わせて骨最終行列を計算します。この行列を、前の方法でも生成するキーフレーム行列で乗算します結果は予想外でレンダリングするいくつかの顔が消え、ランダム頂点が移動するときに、POS、rotqとSCLから、最終的に私は、[]均一MAT4によってGPUにこれらの行列をアップロードし、これは頂点シェーダ
uniform mat4 modelview;
uniform mat4 projection;
uniform mat4 bones[BONES];
uniform int animated;
attribute vec4 vertexPosition;
attribute vec4 vertexNormal;
attribute vec2 textureCoords;
attribute vec2 skinweight;
attribute vec2 skinindex;
varying vec2 vTextureCoords;
varying vec4 viewDir;
varying vec4 modelviewNormal;
varying mat4 mv;
void main() {
mv=modelview;
vec4 newVertex;
vec4 newNormal;
if(animated==1){
int index;
index=int(skinindex.x);
newVertex += (bones[index] * vertexPosition * skinweight.x) ;
newNormal += (bones[index] * vertexPosition * skinweight.x) ;
index=int(skinindex.y);
newVertex += (bones[index] * vertexPosition * skinweight.y);
newNormal += (bones[index] * vertexNormal* skinweight.y);
}
else{
newVertex=vertexPosition;
newNormal=vertexNormal;
}
vec4 modelviewVertex=(modelview * newNormal);
modelviewNormal = normalize(modelviewVertex);
viewDir = normalize(-modelview*newVertex);
vTextureCoords = textureCoords;
gl_Position = (projection * modelview)* vec4(newVertex.xyz, 1.0);
}