feat(style): move style.point.model to its own category: 'model' - #2808
feat(style): move style.point.model to its own category: 'model'#2808ftoromanoff wants to merge 3 commits into
Conversation
af3c3a0 to
c1ca507
Compare
96261e2 to
fe81a26
Compare
ab49d98 to
1db5332
Compare
ba7f2da to
fc81a0b
Compare
| const styleModel = style.model; | ||
| const count = geometries.length; | ||
| const instancedMesh = new THREE.InstancedMesh(mesh.geometry, mesh.material, count); | ||
| let index = 0; | ||
| for (let i = 0; i < count * 3; i += 3) { | ||
| const mat = new THREE.Matrix4(); | ||
| mat.setPosition(ptsIn[i], ptsIn[i + 1], ptsIn[i + 2]); | ||
| instancedMesh.setMatrixAt(index, mat); | ||
| index++; | ||
|
|
||
| for (let j = 0; j < count; j += 1) { | ||
| context.setGeometry(geometries[j]); | ||
| scale.set(1, 1, 1); | ||
| if (styleModel.size) { | ||
| scale.set( | ||
| styleModel.size.x / modelSize.x, | ||
| styleModel.size.y / modelSize.y, | ||
| styleModel.size.z / modelSize.z, | ||
| ); | ||
| } | ||
|
|
||
| let headingRad = 0; | ||
| if (styleModel.heading) { | ||
| headingRad = styleModel.heading * THREE.MathUtils.DEG2RAD; | ||
| } | ||
| mat.makeRotationZ(-headingRad); | ||
| mat.setPosition(ptsIn[j * 3], ptsIn[j * 3 + 1], ptsIn[j * 3 + 2]); | ||
| mat.scale(scale.multiplyScalar(styleModel.scale)); | ||
| instancedMesh.setMatrixAt(j, mat); |
There was a problem hiding this comment.
Could you use Vector3 methods to simplify your code
There was a problem hiding this comment.
done
scale.set(1, 1, 1) => scale.setScalar(1)
scale.set(x1/V.x, y1/V.y, z1/V.z) => scale.divide(V)
| model: { | ||
| object: model, |
There was a problem hiding this comment.
could you rename var model to object to have model: { object,
| const modelObject = style.model.object; | ||
|
|
||
| // orientation of the model following up and north properties. | ||
| quaternion.setFromUnitVectors(style.model.up, zVect); |
There was a problem hiding this comment.
It's possible to use Object3D.up ?
There was a problem hiding this comment.
I tried it to use with Object3D.lookAt(). But it has no direct impact to orient the object.
| const northWithRotation = style.model.north.applyQuaternion(quaternion.clone().conjugate()); | ||
| const angletoNorth = northWithRotation.angleTo(yVect); | ||
| quaternionY.setFromAxisAngle(yVect, angletoNorth); | ||
| quaternion.multiply(quaternionY); | ||
|
|
||
| modelObject.setRotationFromQuaternion(quaternion); |
There was a problem hiding this comment.
This part seems complex; we could first orient the Z-axis locally toward the north, and then calculate the quaternion needed to orient the Z-axis in global space.
There was a problem hiding this comment.
As we will need to calculate the size of the model object in the world space (using the bbox) we need the model oriented in the global space.
19e65ef to
99029ea
Compare
99029ea to
ebe3491
Compare
Currently, to instanciate several object 3D at different position, the associated style is the style category 'point' with the parameter 'object'.
The use of extra parameter as 'orientation', 'size', 'scale' to cite a few is currently limited. That's the reason why I propose to add a new style category 'model' with it's own parameter. (As it's done for text and icon).