Reputation: 998
I am importing a .fbx model of an animated robot hand. I want to use a skinned mesh but render gl.POINTS instead of a standard mesh.
Here is my initial (naive) try. I am swapping the individual elements from THREE.Mesh to THREE.Points:
loader.load('/robot-arm-01.fbx', (object) => {
let children = object.children.map(child => {
child.material = new THREE.ShaderMaterial({
vertexShader,
fragmentShader,
skinning: true
})
let points = new THREE.Points(child.geometry, child.material)
points.position.copy(child.position)
points.scale.copy(child.scale)
points.rotation.copy(child.rotation)
return points
})
object.children = children
})
The problem is definitely not in my vertex shader, which I get to play the animation if I don't swap the children array
This gets my model displayed correctly with gl.POINTS, but my animation is simply not kicking in. What am I missing here?
My only idea is to change the three.js mesh's draw call from gl.TRIANGLES to gl.POINTS at runtime. How does one do such a thing and is there a smarter approach to the issue?
Upvotes: 1
Views: 476
Reputation: 256
This is probably not the ideal way to do it but it works for me without problem so far. What I did is just copying all SkinnedMesh
params into the Points
. Hope this helps
getSkinnedPoints(skinnedMesh) {
const points = new THREE.Points(skinnedMesh.geometry, skinnedMesh.material);
points.skeleton = skinnedMesh.skeleton;
points.bindMatrix = skinnedMesh.bindMatrix;
points.bindMatrixInverse = skinnedMesh.bindMatrixInverse;
points.bindMode = skinnedMesh.bindMode;
points.drawMode = skinnedMesh.drawMode;
points.name = skinnedMesh.name;
points.parent = skinnedMesh.parent;
points.uuid = skinnedMesh.uuid;
points.type = skinnedMesh.type;
points.isSkinnedMesh = true;
points.bind = skinnedMesh.bind;
points.clone = skinnedMesh.clone;
points.initBones = skinnedMesh.initBones;
points.normalizeSkinWeights = skinnedMesh.normalizeSkinWeights;
points.pose = skinnedMesh.pose;
points.updateMatrixWorld = skinnedMesh.updateMatrixWorld;
return points;
}
Upvotes: 2