Hello Everyone. Merry Crhitmas.
Now I have an urgent problem now, so I am looking forward your help.
I am developing a three.js project. My major skill is web site develope and python automation.
So, I am not familiar with three.js.
You can check my project here.
https://mousecode.vercel.app
And, if you want, I can provide the source code.
As to my project:
It imports a mouse(rat) 3D mesh from a gltf file.
Then, if I change the inputs values, it update the bones and joints values of the Mouse mesh.
But, when I export the Mouse 3D mesh as an object, it has some problems now.
For example, the current 3D mesh on the scene is changed a little per exporting.
And, if I import another pose from csv files after exporting, it generage a broken pose.
This is my current exporting function.
document.getElementById(“export-btn”).addEventListener(“click”, function () {
scene.traverse(function (object) {
if (!object.isSkinnedMesh) return;
if (object.geometry.isBufferGeometry !== true) throw new error(‘only buffergeometry supported.’);
object.skeleton.bones.forEach(bone => {
let filtered = initialRotations.filter(rot => {
return rot.name == bone.name
})
if (filtered.length > 0) {
bone.rotation.x = filtered[0].x;
bone.rotation.y = filtered[0].y;
bone.rotation.z = filtered[0].z;
// bone.rotation.set(0,0,0)
}
else {
bone.rotation.set(0, 0, 0)
}
});
var positionattribute = object.geometry.getAttribute('position');
var normalattribute = object.geometry.getAttribute('normal');
var v1 = new Vector3();
for (var j = 0; j < positionattribute.count; j++) {
object.boneTransform(j, v1);
// object.getVertexPosition(j, v1);
positionattribute.setXYZ(j, v1.x, v1.y, v1.z);
getBoneNormalTransform.call(object, j, v1);
normalattribute.setXYZ(j, v1.x, v1.y, v1.z);
}
positionattribute.needsUpdate = true;
normalattribute.needsUpdate = true;
});
// Apply bone transformations to the skinned mesh before exporting
// Create a new OBJExporter
var exporter = new OBJExporter();
// Export the updated scene
const result = exporter.parse(scene);
const blob = new Blob([result], { type: "text/plain" });
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "exported_model.obj";
link.click();
});
document.getElementById("import-btn").addEventListener("click", function () {
document.getElementById("csvInput").click();
});
document.getElementById("csvInput").addEventListener("change", function () {
importCsv();
});
}
Sincerely hope your help.