Browse Source

Editor: Save and restore controls state. (#32408)

mrdoob 2 months ago
parent
commit
1d89376142
3 changed files with 23 additions and 0 deletions
  1. 7 0
      editor/js/Editor.js
  2. 14 0
      editor/js/EditorControls.js
  3. 2 0
      editor/js/Viewport.js

+ 7 - 0
editor/js/Editor.js

@@ -647,6 +647,12 @@ Editor.prototype = {
 		delete this.cameras[ existingUuid ]; // remove old entry [existingUuid, this.camera]
 		this.cameras[ incomingUuid ] = this.camera; // add new entry [incomingUuid, this.camera]
 
+		if ( json.controls !== undefined ) {
+
+			this.controls.fromJSON( json.controls );
+
+		}
+
 		this.signals.cameraResetted.dispatch();
 
 		this.history.fromJSON( json.history );
@@ -705,6 +711,7 @@ Editor.prototype = {
 				toneMappingExposure: this.config.getKey( 'project/renderer/toneMappingExposure' )
 			},
 			camera: this.viewportCamera.toJSON(),
+			controls: this.controls.toJSON(),
 			scene: this.scene.toJSON(),
 			scripts: this.scripts,
 			history: this.history.toJSON(),

+ 14 - 0
editor/js/EditorControls.js

@@ -445,6 +445,20 @@ class EditorControls extends THREE.EventDispatcher {
 
 	}
 
+	fromJSON( json ) {
+
+		if ( json.center !== undefined ) this.center.fromArray( json.center );
+
+	}
+
+	toJSON() {
+
+		return {
+			center: this.center.toArray()
+		};
+
+	}
+
 }
 
 export { EditorControls };

+ 2 - 0
editor/js/Viewport.js

@@ -283,6 +283,8 @@ function Viewport( editor ) {
 	} );
 	viewHelper.center = controls.center;
 
+	editor.controls = controls;
+
 	// signals
 
 	signals.editorCleared.add( function () {

粤ICP备19079148号