From b6b3caead7f85f592603078f89332216e457893d Mon Sep 17 00:00:00 2001 From: Laura Sach <5183697+lawsie@users.noreply.github.com> Date: Tue, 11 Aug 2026 18:30:32 +0100 Subject: [PATCH 1/2] Fix resize rounding bug --- ui/blockmesh.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ui/blockmesh.js b/ui/blockmesh.js index aea803d8..2c8e7d1f 100644 --- a/ui/blockmesh.js +++ b/ui/blockmesh.js @@ -1515,13 +1515,30 @@ export function updateMeshFromBlock(meshesOrMesh, block, changeEvent) { function moveMeshToOrigin(mesh) { mesh.position = flock.BABYLON.Vector3.Zero(); mesh.rotation = flock.BABYLON.Vector3.Zero(); + // rotationQuaternion takes priority over rotation when set, so it must be + // cleared too or callers that bake the transform into vertices (e.g. + // setAbsoluteSize) will bake in the old rotation as well. + mesh.rotationQuaternion = null; return mesh; } function setAbsoluteSize(mesh, width, height, depth) { flock.ensureUniqueGeometry(mesh); - const boundingInfo = mesh.getBoundingInfo(); - const originalSize = boundingInfo.boundingBox.extendSize; + + // Anchor to the true original geometry (captured once), like flock.resize(). + mesh.metadata = mesh.metadata || {}; + if (!mesh.metadata.originalMin || !mesh.metadata.originalMax) { + const bi = mesh.getBoundingInfo(); + mesh.metadata.originalMin = bi.boundingBox.minimum.clone(); + mesh.metadata.originalMax = bi.boundingBox.maximum.clone(); + } + const origMin = mesh.metadata.originalMin; + const origMax = mesh.metadata.originalMax; + const originalSize = { + x: (origMax.x - origMin.x) / 2, + y: (origMax.y - origMin.y) / 2, + z: (origMax.z - origMin.z) / 2, + }; // Store the current world matrix and decompose it const worldMatrix = mesh.computeWorldMatrix(true); From 32b5a17649bdc62a2377cb2d676a0e9ccfe8db44 Mon Sep 17 00:00:00 2001 From: Laura Sach <5183697+lawsie@users.noreply.github.com> Date: Thu, 13 Aug 2026 08:38:42 +0100 Subject: [PATCH 2/2] Update calculation --- ui/blockmesh.js | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/ui/blockmesh.js b/ui/blockmesh.js index 2c8e7d1f..4affc629 100644 --- a/ui/blockmesh.js +++ b/ui/blockmesh.js @@ -1516,8 +1516,9 @@ function moveMeshToOrigin(mesh) { mesh.position = flock.BABYLON.Vector3.Zero(); mesh.rotation = flock.BABYLON.Vector3.Zero(); // rotationQuaternion takes priority over rotation when set, so it must be - // cleared too or callers that bake the transform into vertices (e.g. - // setAbsoluteSize) will bake in the old rotation as well. + // cleared too or callers that rebuild geometry at the origin (e.g. + // updateCylinderGeometry, updateCapsuleGeometry) will bake in the old + // rotation as well. mesh.rotationQuaternion = null; return mesh; } @@ -1535,38 +1536,17 @@ function setAbsoluteSize(mesh, width, height, depth) { const origMin = mesh.metadata.originalMin; const origMax = mesh.metadata.originalMax; const originalSize = { - x: (origMax.x - origMin.x) / 2, - y: (origMax.y - origMin.y) / 2, - z: (origMax.z - origMin.z) / 2, + x: origMax.x - origMin.x, + y: origMax.y - origMin.y, + z: origMax.z - origMin.z, }; - // Store the current world matrix and decompose it - const worldMatrix = mesh.computeWorldMatrix(true); - const currentScale = new flock.BABYLON.Vector3(); - const currentRotationQuaternion = new flock.BABYLON.Quaternion(); - const currentPosition = new flock.BABYLON.Vector3(); - worldMatrix.decompose(currentScale, currentRotationQuaternion, currentPosition); - - // Temporarily move mesh to origin - mesh = moveMeshToOrigin(mesh); + const newScaleX = originalSize.x ? width / originalSize.x : 1; + const newScaleY = originalSize.y ? height / originalSize.y : 1; + const newScaleZ = depth === 0 ? 1 : originalSize.z ? depth / originalSize.z : 1; - // Calculate new scaling - const newScaleX = width / (originalSize.x * 2); - const newScaleY = height / (originalSize.y * 2); - const newScaleZ = depth === 0 ? 1 : depth / (originalSize.z * 2); - - // Apply scaling mesh.scaling = new flock.BABYLON.Vector3(newScaleX, newScaleY, newScaleZ); - - // Bake the scaling into the vertices - mesh.bakeCurrentTransformIntoVertices(); - - // Reset scaling to 1,1,1 - mesh.scaling = flock.BABYLON.Vector3.One(); - - // Restore original position and rotation from world matrix - mesh.position = currentPosition; - mesh.rotationQuaternion = currentRotationQuaternion; + mesh.computeWorldMatrix(true); let shapeType = null; if (mesh.metadata) shapeType = mesh.metadata.shapeType;