Its me again, i fixed some bugs and i am trying to add animation to the symmetric model.
[java]
// Assign all verticies to bone 0 with weight 1
for (int i = 0; i < (mesh.getVertexCount()/2) * 4; i += 4)
{
// assign vertex to bone index 0
indices.array() = boneIndexArray;
indices.array() = boneIndexArray;
indices.array() = boneIndexArray;
indices.array() = boneIndexArray;
indices.array()[boneIndexArray.length + i + 0] = (byte) (boneIndexArray + SymmetricBoneIndexIncreaseOffset);
indices.array()[boneIndexArray.length + i + 1] = (byte) (boneIndexArray + SymmetricBoneIndexIncreaseOffset);
indices.array()[boneIndexArray.length + i + 2] = (byte) (boneIndexArray + SymmetricBoneIndexIncreaseOffset);
indices.array()[boneIndexArray.length + i + 3] = (byte) (boneIndexArray + SymmetricBoneIndexIncreaseOffset);
// set weight to 1 only for first entry
weights.array() = boneWeightArray;
weights.array() = boneWeightArray;
weights.array() = boneWeightArray;
weights.array() = boneWeightArray;
weights.array()[boneWeightArray.length + i + 0] = boneWeightArray;
weights.array()[boneWeightArray.length + i + 1] = boneWeightArray;
weights.array()[boneWeightArray.length + i + 2] = boneWeightArray;
weights.array()[boneWeightArray.length + i + 3] = boneWeightArray;
}
[/java]
Now if i test this with SymmetricBoneIndexIncreaseOffset = 0. The chest will look ok, but the hand has wrong animation.
http://www.youtube.com/watch?v=y1XGpj_TxQ8
If i test with SymmetricBoneIndexIncreaseOffset = 25. The hand will look correctly, but the chest will be deformed.
http://www.youtube.com/watch?v=yRh6ANNeoqE
How should i have the bone weights for the symmetric mesh ?
i was able to solve this and make it animate correctly by using a hardcoded hack:
[java]
private void IncreaseWithCheck(ByteBuffer indices, int i, byte SymmetricBoneIndexIncreaseOffset)
{
byte boneIncrease = 0;
byte boneIndex = boneIndexArray;
if (boneIndex > 35) boneIncrease = 25;
indices.array()[boneIndexArray.length + i ] = (byte) (boneIndex + boneIncrease);
}[/java]
However now it works for only 1 model, all others will be wrong.
How do i detect if i should use the corresponding symmetric bone ? or share the original ?
I am trying to create the symmetric skeleton.
there is no tutorial on how to create the bones / skeleton. TestCustomAnim creates an empty bone = no help.
i wanted to start with something simple how to copy the skeleton, afterwords i can refactor that code to do apply symmetry. I need this because jme always requires “call my secret undocumented method” to work.
a) new Skeleton( skeleton ) doesnt work.
b) this doesnt work also :
[java]
public static Skeleton copySkeleton(Skeleton skeleton)
{
Bone[] roots = skeleton.getRoots();
Bone[] clonedRoots = new Bone[roots.length];
for(int i=0;i<roots.length;i++)
{
clonedRoots=copy(roots);
}
Skeleton copySkeleton = new Skeleton(clonedRoots);
return copySkeleton;
}
public static Bone copy(Bone bone)
{
Bone copiedBone = new Bone(bone.getName()+" Symmetric");
copiedBone.setBindTransforms(bone.getWorldBindPosition(), bone.getWorldBindRotation(), bone.getWorldBindScale());
for(Bone child : bone.getChildren()) copiedBone.addChild(copy(child));
return copiedBone;
}
[/java]
Addez
July 19, 2011, 4:17pm
4
Humm…
I really do suck when it comes to non documented stuff.
LOL I got problems getting the documented stuff to work
But why do you need a mirrored animation?
Can’t you do it using blender instead?