This commit is contained in:
Evert Prants 2024-02-18 14:08:01 +02:00
parent b5c0adca22
commit 3be6493f3d
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
1 changed files with 16 additions and 9 deletions

View File

@ -89,13 +89,7 @@ export class ThreeBuilder {
parent: Object3D,
parentComponent?: MsonComponent,
) {
const offset = new Vector3();
if (parentComponent?.pivot) {
offset.sub(new Vector3().fromArray(parentComponent.pivot as Vec3));
}
const size = new Vector3().fromArray(component.size as Vec3);
const pos = new Vector3().fromArray(component.from as Vec3);
const dilate = new Vector3();
if (component.dilate) {
@ -112,9 +106,18 @@ export class ThreeBuilder {
);
}
const pos = new Vector3();
if (parentComponent?.pivot) {
pos.fromArray(parentComponent.pivot as Vec3);
}
pos.setY(pos.y * -1);
const offset = new Vector3().fromArray(component.from as Vec3);
const halfOffset = offset.clone().divideScalar(2);
const halfSize = size.clone().divideScalar(2);
const halfDilation = dilate.clone().divideScalar(2);
offset.setY(offset.y * -1);
const adjustedTranslate = halfSize.clone().add(offset);
const geometry = new BoxGeometry(
size.x + dilate.x,
@ -125,7 +128,11 @@ export class ThreeBuilder {
1,
);
geometry.translate(halfOffset.x, halfOffset.y, halfOffset.z);
geometry.translate(
adjustedTranslate.x,
adjustedTranslate.y - size.y,
adjustedTranslate.z,
);
geometry.rotateX(rotate.x);
geometry.rotateY(rotate.y);
geometry.rotateZ(rotate.z);
@ -135,7 +142,7 @@ export class ThreeBuilder {
delete (geometry as any).parameters;
// TODO: apply UVs
pos.add(halfOffset).add(halfSize);
// pos.add(halfOffset).add(halfSize);
const mesh = new Mesh(geometry, this.material);
mesh.name = `${name}__mesh`;