From 9459166f681c8e63e8760c963729f6de784e004e Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 27 Apr 2026 00:30:10 +0200 Subject: [PATCH] Refactor transform reset to target specific preview IDs --- src/viewport-three/viewport-host.ts | 47 ++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/src/viewport-three/viewport-host.ts b/src/viewport-three/viewport-host.ts index af92cc69..02ac35bf 100644 --- a/src/viewport-three/viewport-host.ts +++ b/src/viewport-three/viewport-host.ts @@ -5170,12 +5170,18 @@ export class ViewportHost { ); } - private resetRenderObjectTransformsFromDocument() { + private resetTransformPreviewTargets(targetIds: TransformPreviewTargetIds) { if (this.currentDocument === null) { return; } - for (const brush of Object.values(this.currentDocument.brushes)) { + for (const brushId of targetIds.brushIds) { + const brush = this.currentDocument.brushes[brushId]; + + if (brush === undefined) { + continue; + } + this.updateBrushRenderObjectGeometry(brush); this.applyBrushRenderObjectTransform( brush.id, @@ -5184,29 +5190,52 @@ export class ViewportHost { ); } - for (const entity of getEntityInstances(this.currentDocument.entities)) { + for (const entityId of targetIds.entityIds) { + const entity = this.currentDocument.entities[entityId]; + + if (entity === undefined) { + continue; + } + this.applyEntityRenderObjectTransform(entity); this.applyLocalLightRenderObjectTransform(entity); } - for (const modelInstance of getModelInstances( - this.currentDocument.modelInstances - )) { + for (const modelInstanceId of targetIds.modelInstanceIds) { + const modelInstance = this.currentDocument.modelInstances[modelInstanceId]; + + if (modelInstance === undefined) { + continue; + } + this.applyModelInstanceRenderObjectTransform(modelInstance); } - for (const path of getScenePaths(this.currentDocument.paths)) { + for (const pathId of targetIds.pathIds) { + const path = this.currentDocument.paths[pathId]; + + if (path === undefined) { + continue; + } + this.updatePathRenderObjectState(path); } } private applyTransformPreview() { - this.resetRenderObjectTransformsFromDocument(); + if (this.currentTransformPreviewTargetIds !== null) { + this.resetTransformPreviewTargets(this.currentTransformPreviewTargetIds); + this.currentTransformPreviewTargetIds = null; + } if (this.currentTransformSession.kind !== "active") { return; } + const nextPreviewTargetIds = collectTransformPreviewTargetIds( + this.currentTransformSession + ); + switch (this.currentTransformSession.target.kind) { case "brush": case "brushFace": @@ -5485,6 +5514,8 @@ export class ViewportHost { } break; } + + this.currentTransformPreviewTargetIds = nextPreviewTargetIds; } private rebuildLocalLights(document: SceneDocument) {