system information: build info:20241205, blender version: 4.2.3, python version: 3.11.7
it works fine to the point where i morph the body mesh using shape keys. this results in assets like eyes, hair etc. staying in the same position (which is expected because the actual position of body doesnt change).
I tried solving this by aligning the skeleton to the morphed shape. I was able to do it, but assets still dont follow the bones. which is another problem in itself because i confirmed they are correctly weighted and bones do move.
anyway, then i decided to use mhclo files since they have vertex information. the documentation says:
If the n:th line reads
v1 v2 v3 w1 w2 w3 d1 d2 d3
then the location of clothing vertex n is
w1*r1 + w2*r2 + w3 *r3 + (s1*d1, s2*d2, s3*d3)
where r1,r2,r3 are locations of human vertices v1,v2,v3, and s1,s2,s3 are scale factors
i tried to implement this in javascript as:
- Code: Select all
const r1 = baseMesh.getVertexPosition(remappedV1, new THREE.Vector3());
const r2 = baseMesh.getVertexPosition(remappedV2, new THREE.Vector3());
const r3 = baseMesh.getVertexPosition(remappedV3, new THREE.Vector3());
const position = new THREE.Vector3()
.addScaledVector(r1, w1)
.addScaledVector(r2, w2)
.addScaledVector(r3, w3);
position.x += scale.x_scale[2] * d1;
position.y += scale.y_scale[2] * d2;
position.z += scale.z_scale[2] * d3;
const mappedIndices = eyeMeshVertexMap[i];
if (mappedIndices) {
mappedIndices.forEach(mappedIdx => {
eyeVertices[mappedIdx * 3] = position.x;
eyeVertices[mappedIdx * 3 + 1] = position.y;
eyeVertices[mappedIdx * 3 + 2] = position.z
});
}
this sort of works unless i add offsets. the moment i add the offsets (even without scaling) it breaks the whole geometry.
a potential source for this is that, gltf exporter in blender adds duplicate vertices when you export uv data (for example base mesh has 19158 vertices in blender, but 21833 in three js). i solved that by creating maps that maps original vertices to duplicate ones, and they work fine when aligning the skeleton or hiding helper parts of the geometry. but still maybe they mess up offset calculation somehow? or my implementation is wrong altogether?
with and without offsets:
EDIT: in the meantime, i found out that adding another factor to the scales kinda works. mesh gets a bit squishy, but definitely much better than before.
- Code: Select all
position.x += scale.x_scale[2] * 0.04 * d1;
position.y += scale.y_scale[2] * 0.04 * d2;
position.z += scale.z_scale[2] * 0.04 * d3;
0.04 seems to work fine, at least for eye and hair meshes now.