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 5 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.
99029ea to
ebe3491
Compare
| * @property {object|Function} model.heading - The heading (or azimuth) to orient the model in degree. | ||
| * @property {object|Function} model.scale - The value to scale the model. (default value is 1). | ||
| * @property {object|Function} model.up - The vector pointing up. (default value is Vector3(0, 0, 1)). | ||
| * @property {object|Function} model.north - The vector pointing north. (default value is Vector3(0, 1, 0)). |
There was a problem hiding this comment.
Is this north vector supposed to be tangent to the ground, so orthogonal to up? What happens if it's not?
There was a problem hiding this comment.
The user should be able to define a vector, that point toward the 'head' or the 'front' of the model. It's per defiition orthogonal to 'up'. Maybe we should better use 'head' or 'front' or an other name ?. 'north' is more the direction in the world referentiel where the head will be directed as for the meaning 'heading' which is the angle between the head and the north.
There was a problem hiding this comment.
That makes sense. In that case, "front" sounds good. It matches the wording of most 3D modelling software. Then, the east vector in my code snippet in Feature2Mesh.js should be called right.
If the up and front vector are supposed to be orthogonal, I think we should either mention it in the doc, or check the input received by the function is valid.
There was a problem hiding this comment.
I can't imagine a real case where we would have the front of a model and a up, not being orthognal...
Ps: I renamed using front and right, it sounds better indeed.
There was a problem hiding this comment.
I agree that there are no such use cases, but it doesn't hurt to document the expected properties that the input values should verify. Or do a sanity check.
There was a problem hiding this comment.
I did add it in the documentation for 'front'.
d2832f3 to
94744e8
Compare
…rGeometry() and THREE.SphereGeometry()
94744e8 to
58136b6
Compare
|
I just did a rebase to the main branch. |
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).