Game Development Reference
In-Depth Information
if(data.bones) {
stageObject=new RiggedMesh();
}
else{
stageObject=new StageObject();
}
}
...
}
•
The
initShaders
function accesses the attributes (
skinIndex
and
skinWeight
) and stores their references in the
shaderProgram
object.
function initShaders() {
...
shaderProgram.skinIndex =
gl.getAttribLocation(shaderProgram, "skinIndex");
shaderProgram.skinWeight =
gl.getAttribLocation(shaderProgram, "skinWeight");
shaderProgram.useSkinning =
gl.getUniformLocation(shaderProgram, "useSkinning");
shaderProgram.boneGlobalMatrices =
gl.getUniformLocation(shaderProgram,
"boneGlobalMatrices");
...
}
•
The
drawScene
function iterates over visible stage objects and checks
whether the instance is of the
RiggedMesh
type. If it is valid, it enables the
skinIndex
and
skinWeight
attributes (
gl.enableVertexAttribArray(sha
derProgram.skinIndex)
), activates the buffer objects (
gl.bindBuffer(gl.
ARRAY_BUFFER, stage.stageObjects[i].skinIndexBuffer)
), and assigns
their memory buffers to their corresponding attributes (
gl.vertexAttribPo
inter(shaderProgram.skinIndex, 4, gl.FLOAT, false, 0, 0)
). Then,
it also assigns the offset bone matrices to the uniform
boneGlobalMatrices
(
gl.uniformMatrix4fv( shaderProgram.boneGlobalMatrices,
false, stage.stageObjects[i].boneMatrices )
). Note that we assign
boneMatrices
as matrices of floats.