Pryme8
January 5, 2024, 7:23pm
1
So in Frame we have a third person camera that is the child of our first person camera. The first person camera is responsible for moving around the scene while the third person acts as an orbit camera that like mentioned prior is a child of the fpc.
We have a situation where the scale boxes are doing very unpredictable scaling when a user has an object being dragged and moved with the player.
After doing some digging I noticed in the method for setting their size the gizmoLayer uses the activeCamera.position which in our setup would always be a localized position instead of the global position. Would there be a way to work around this? Im thinking just changing the code here:
for (let j = 0; j < 3; j++) {
for (let k = 0; k < 3; k++) {
const zeroAxisCount = (i === 1 ? 1 : 0) + (j === 1 ? 1 : 0) + (k === 1 ? 1 : 0);
if (zeroAxisCount === 1 || zeroAxisCount === 3) {
continue;
}
if (scaleBoxes[index]) {
scaleBoxes[index].position.set(this._boundingDimensions.x * (i / 2), this._boundingDimensions.y * (j / 2), this._boundingDimensions.z * (k / 2));
scaleBoxes[index].position.addInPlace(new Vector3(-this._boundingDimensions.x / 2, -this._boundingDimensions.y / 2, -this._boundingDimensions.z / 2));
if (this.fixedDragMeshScreenSize && this.gizmoLayer.utilityLayerScene.activeCamera) {
scaleBoxes[index].absolutePosition.subtractToRef(this.gizmoLayer.utilityLayerScene.activeCamera.position, this._tmpVector);
const distanceFromCamera = (this.scaleBoxSize * this._tmpVector.length()) / this.fixedDragMeshScreenSizeDistanceFactor;
scaleBoxes[index].scaling.set(distanceFromCamera, distanceFromCamera, distanceFromCamera);
} else if (this.fixedDragMeshBoundsSize) {
scaleBoxes[index].scaling.set(
this.scaleBoxSize * this._boundingDimensions.x,
this.scaleBoxSize * this._boundingDimensions.y,
this.scaleBoxSize * this._boundingDimensions.z
);
} else {
scaleBoxes[index].scaling.set(this.scaleBoxSize, this.scaleBoxSize, this.scaleBoxSize);
to say
scaleBoxes[index].absolutePosition.subtractToRef(this.gizmoLayer.utilityLayerScene.activeCamera.globalPosition, this._tmpVector);
would fix the problem or am I mistaken in thinking that?
I guess this makes sense !!! Can you “monkeypatch” in Frame and validates that it works there before creating a PR ?
1 Like
Pryme8
January 6, 2024, 6:28am
3
“monkeypatch” I see what you did there.
Pryme8
January 8, 2024, 7:02pm
4
It does look like that fixed the problem when I polyfilled over the method with the fix.
Ill submit a PR here.
BabylonJS:master
← Pryme8:bounding-box-gizmo-scale-boxes-fix
opened 07:11PM - 08 Jan 24 UTC
There was a bug where if the active utility layers camera was a child of an obje… ct the calculations would use the local position instead of the desired global position.
@sebavan
1 Like
ahah did not even noticed primate monkey patching… this goes way too deep for me
1 Like