I have modified the obj export script for all my needs so far but I am having trouble with the Math in regards to how I get a vertex's position before you apply multiple bone matrix's (with their weights).
I can get it working with 1 bone matrix (weight of 1) but not with multiple bones (max 3) with a total weight of 1 (eg 3 bones with 0.33333 weight each).
I have tried many different combos but unable to find a working order.
Can you please point me to a source of how to export vertex's before bones and their weights are applied or what I have done wrong/need to do? (so the vertex shader does this during runtime)
Below is the code I am using for relevant parts if I have missed something you need let me know and I will add :D
Bone Matrix exporting:
oArmature = OBJECT.find_armature() oBones = oArmature.pose.bones for oBone in oBones: BoneMatrix = EXPORT_GLOBAL_MATRIX * oArmature.matrix_world * oBone.bone.matrix_local oBoneName2Matrix[oBone.name] = BoneMatrix
#in the vertex loop oVMatrix = mathutils.Matrix() oVMatrix.zero() for oWeight in oVWeights: oMatrix = oBoneName2Matrix[oWeight.sBoneName] #tried adding .inverted() as well oVMatrix += oMatrix * oWeight.fWeight export = v.co * oVMatrix #tried adding .inverted() as well #export = oVMatrix * v.co #tried adding .inverted() as well
layout (location = 0) in vec3 Vertex_Position; layout (location = 2) in uvec3 BoneID; layout (location = 3) in vec3 Vertex_Weight; uniform mat4 BoneMatrixs; mat4 TotalBones = mat4(0); for(int i = 0; i < 3; ++i) TotalBones += (BoneMatrixs[BoneID[i]] * Vertex_Weight[i]); vec4 VertexPos_after_bones = TotalBones * vec4(Vertex_Position, 1.0);
Update: i am wanting to transform the final vertex position in blender to its position before any of the 3 bone matrices are applied.
vertex shader pov: ((bonematrix * boneweight) + (bonematrix * boneweight) + (bonematrix * boneweight)) * vertex_pos_before_bones
i need to know how to get from the final vertex pos in blender to vertex_pos_before_bones but i can't get the math to work.