Hi! I am new to three js. But my dive was amazing so far. Thanks a lot for this great project.
I found a nice demo here:
This is done in r70.
I am trying to update it to the current version (0.134.0)
This worked out quite okay.
Shadow is working again, the lion looks happy, all good.
But I have one major problem concerning the lions body.
The author of this nice demo used the buildin (geometry based) CylinderGeometry of r70.
He manipulates this standard geometry to his needs and sets a few positions new.
var bodyGeom = new THREE.CylinderGeometry(30,80, 140, 4);
// body
this.body = new THREE.Mesh(bodyGeom, this.yellowMat);
this.body.position.z = -60;
this.body.position.y = -30;
this.bodyVertices = [0,1,2,3,4,10]; // <---- -the "magic" part
for (var i=0;i<this.bodyVertices.length; i++){
var tv = this.body.geometry.vertices[this.bodyVertices[i]];
tv.z =70;
this.bodyInitPositions.push({x:tv.x, y:tv.y, z:tv.z});
}
And when turning on the fan - or when moving the mouse - he ābends/movesā the body. Nice idea:
Here i.e. look to the mouse pointer
for (var i=0; i<this.bodyVertices.length; i++){
var tvInit = this.bodyInitPositions[i];
var tv = this.body.geometry.vertices[this.bodyVertices[i]];
tv.x = tvInit.x + this.head.position.x;
}
this.body.geometry.verticesNeedUpdate = true;
So - this makes all sense for me.
The BufferGeometry - from my point of view - makes this impossible - as the vertices array from old geometry can not be migrated to buffergeometry
this.bodyVertices = [0,1,2,3,4,10];
This array hold the āimportantā vertices which makes the body able to ābend/moveā.
I tried it naive - but failed (of course)
const positionAttribute = this.body.geometry.getAttribute("position");
const vertex = new THREE.Vector3();
for (var i = 0; i < this.bodyVertices.length; i++) {
vertex.fromBufferAttribute(positionAttribute, this.bodyVertices[i]);
positionAttribute.setXYZ(this.bodyVertices[i], vertex.x, vertex.y, 70); // write coordinates back
this.bodyInitPositions.push({ x: vertex.x, y: vertex.y, z: 70 });
}
This one here - has the same issue - without success:
Any ideas how this could be solved?