Browse Source

Editor: Wired up camera to Config.

Mr.doob 11 years ago
parent
commit
45a5cda98b
3 changed files with 22 additions and 5 deletions
  1. 12 2
      editor/js/Config.js
  2. 8 2
      editor/js/Viewport.js
  3. 2 1
      examples/js/controls/EditorControls.js

+ 12 - 2
editor/js/Config.js

@@ -3,12 +3,22 @@ var Config = function () {
 	var name = 'threejs-editor';
 
 	var storage = {
-		theme: 'css/light.css'
+		theme: 'css/light.css',
+		camera: {
+			position: [ 500, 250, 500 ],
+			target: [ 0, 0, 0 ] 
+		}
 	};
 
 	if ( window.localStorage[ name ] !== undefined ) {
 
-		storage = JSON.parse( window.localStorage[ name ] );
+		var data = JSON.parse( window.localStorage[ name ] );
+
+		for ( var key in data ) {
+
+			storage[ key ] = data[ key ];
+
+		}
 
 	}
 

+ 8 - 2
editor/js/Viewport.js

@@ -27,8 +27,8 @@ var Viewport = function ( editor ) {
 	//
 
 	var camera = new THREE.PerspectiveCamera( 50, container.dom.offsetWidth / container.dom.offsetHeight, 1, 5000 );
-	camera.position.set( 500, 250, 500 );
-	camera.lookAt( scene.position );
+	camera.position.fromArray( editor.config.getKey( 'camera' ).position );
+	camera.lookAt( new THREE.Vector3().fromArray( editor.config.getKey( 'camera' ).target ) );
 
 	//
 
@@ -170,6 +170,7 @@ var Viewport = function ( editor ) {
 	// otherwise controls.enabled doesn't work.
 
 	var controls = new THREE.EditorControls( camera, container.dom );
+	controls.center.fromArray( editor.config.getKey( 'camera' ).target )
 	controls.addEventListener( 'change', function () {
 
 		transformControls.update();
@@ -234,6 +235,11 @@ var Viewport = function ( editor ) {
 
 	signals.cameraChanged.add( function () {
 
+		editor.config.setKey( 'camera', {
+			position: camera.position.toArray(),
+			target: controls.center.toArray()
+		} );
+
 		render();
 
 	} );

+ 2 - 1
examples/js/controls/EditorControls.js

@@ -12,6 +12,7 @@ THREE.EditorControls = function ( object, domElement ) {
 	// API
 
 	this.enabled = true;
+	this.center = new THREE.Vector3();
 
 	// internals
 
@@ -21,7 +22,7 @@ THREE.EditorControls = function ( object, domElement ) {
 	var STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2 };
 	var state = STATE.NONE;
 
-	var center = new THREE.Vector3();
+	var center = this.center;
 	var normalMatrix = new THREE.Matrix3();
 	var pointer = new THREE.Vector2();
 	var pointerOld = new THREE.Vector2();