Skip to content

Commit 6ffd2c6

Browse files
committed
fix: minor preview fixes when removing objects from graph or switching camera
1 parent da37bee commit 6ffd2c6

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

editor/src/editor/layout/graph/remove.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export function removeNodes(editor: Editor) {
144144
},
145145
redo: () => {
146146
nodes.forEach((d) => {
147-
removeNodeData(d, scene);
147+
removeNodeData(editor, d, scene);
148148
});
149149

150150
sounds.forEach((d) => {
@@ -214,7 +214,7 @@ function restoreNodeData(data: _RemoveNodeData, scene: Scene) {
214214
}
215215
}
216216

217-
function removeNodeData(data: _RemoveNodeData, scene: Scene) {
217+
function removeNodeData(editor: Editor, data: _RemoveNodeData, scene: Scene) {
218218
const node = data.node;
219219

220220
if (isAbstractMesh(node)) {
@@ -243,5 +243,9 @@ function removeNodeData(data: _RemoveNodeData, scene: Scene) {
243243

244244
if (isCamera(node)) {
245245
scene.removeCamera(node);
246+
247+
if (node === editor.layout.preview._previewCamera) {
248+
editor.layout.preview.setCameraPreviewActive(null);
249+
}
246250
}
247251
}

editor/src/editor/layout/preview.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ export class EditorPreview extends Component<IEditorPreviewProps, IEditorPreview
173173
private _mainCanvas: HTMLCanvasElement | null = null;
174174
private _mainView: EngineView | null = null;
175175

176-
private _previewCamera: Camera | null = null;
176+
/** @internal */
177+
public _previewCamera: Camera | null = null;
177178

178179
public constructor(props: IEditorPreviewProps) {
179180
super(props);
@@ -246,7 +247,7 @@ export class EditorPreview extends Component<IEditorPreviewProps, IEditorPreview
246247
<EditorPreviewIcons ref={(r) => this._onGotIconsRef(r!)} editor={this.props.editor} />
247248
</EditorGraphContextMenu>
248249

249-
{this._previewCamera && (
250+
{this._previewCamera && this.scene?.cameras.includes(this._previewCamera) && (
250251
<EditorPreviewCamera hidden={this.play?.state.playing} key={this._previewCamera.id} editor={this.props.editor} camera={this._previewCamera} />
251252
)}
252253

@@ -451,7 +452,7 @@ export class EditorPreview extends Component<IEditorPreviewProps, IEditorPreview
451452
* @param camera the camera to activate the preview
452453
*/
453454
public setCameraPreviewActive(camera: Camera | null): void {
454-
if (this._previewCamera === camera) {
455+
if (this._previewCamera === camera || camera === this.scene.activeCamera) {
455456
return;
456457
}
457458

@@ -1116,6 +1117,10 @@ export class EditorPreview extends Component<IEditorPreviewProps, IEditorPreview
11161117
});
11171118

11181119
this.props.editor.layout.inspector.forceUpdate();
1120+
1121+
if (this._previewCamera === camera) {
1122+
this.setCameraPreviewActive(null);
1123+
}
11191124
}
11201125

11211126
/**

editor/src/editor/layout/preview/gizmo.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ export class EditorPreviewGizmo {
145145
this._spriteTransformNode.scaling.set(object.width, object.height, 1);
146146
this._spriteTransformNode.rotation.set(0, 0, object.angle);
147147
}
148+
}
148149

149-
if (isCamera(object)) {
150-
this._cameraGizmo ??= new CameraGizmo(this._gizmosLayer);
151-
this._cameraGizmo.camera = object;
152-
this._cameraGizmo.attachedNode = object;
153-
} else {
154-
this._cameraGizmo?.dispose();
155-
this._cameraGizmo = null;
156-
}
150+
if (object && isCamera(object) && this._gizmosLayer.originalScene.cameras.includes(object)) {
151+
this._cameraGizmo ??= new CameraGizmo(this._gizmosLayer);
152+
this._cameraGizmo.camera = object;
153+
this._cameraGizmo.attachedNode = object;
154+
} else {
155+
this._cameraGizmo?.dispose();
156+
this._cameraGizmo = null;
157157
}
158158

159159
if (this.currentGizmo) {

0 commit comments

Comments
 (0)