Sfoglia il codice sorgente

[CAMERA] Edit camera angle and position while in preview

Jed 3 anni fa
parent
commit
bf1c8429cd
1 ha cambiato i file con 24 aggiunte e 7 eliminazioni
  1. 24 7
      hrt/prefab/l3d/Camera.hx

+ 24 - 7
hrt/prefab/l3d/Camera.hx

@@ -6,8 +6,6 @@ import hrt.prefab.Library;
 class CameraSyncObject extends h3d.scene.Object {
 
 	public var enable : Bool;
-	public var dir : h3d.Vector;
-	public var pos : h3d.Vector;
 	public var fovY : Float;
 	public var zFar : Float;
 	public var zNear : Float;
@@ -16,8 +14,6 @@ class CameraSyncObject extends h3d.scene.Object {
 		if( enable ) {
 			var c = getScene().camera;
 			if( c != null ) {
-				c.pos.load(pos);
-				c.target.load(pos.add(dir));
 				c.fovY = fovY;
 				c.zFar = zFar;
 				c.zNear = zNear;
@@ -114,8 +110,6 @@ class Camera extends Object3D {
 		drawFrustum(ctx);
 		var cso = Std.downcast(ctx.local3d, CameraSyncObject);
 		if( cso != null ) {
-			cso.pos = getTransform().getPosition();
-			cso.dir = getTransform().front();
 			cso.fovY = fovY;
 			cso.zFar = zFar;
 			cso.zNear = zNear;
@@ -181,7 +175,30 @@ class Camera extends Object3D {
 			preview = !preview;
 			editModeButton.val(preview ? "Preview Mode : Enabled" : "Preview Mode : Disabled");
 			editModeButton.toggleClass("editModeEnabled", preview);
-			updateInstance(ctx.getContext(this));
+			var cam = ctx.scene.s3d.camera;
+			if (preview) {
+				updateInstance(ctx.getContext(this));
+				applyTo(cam);
+				ctx.scene.editor.cameraController.lockZPlanes = true;
+				ctx.scene.editor.cameraController.loadFromCamera();
+			}
+			else {
+				ctx.makeChanges(this, function() {
+					var q = new h3d.Quat();
+					q.initDirection(cam.target.sub(cam.pos));
+					var angles = q.toEuler();
+					this.rotationX = hxd.Math.fmt(angles.x * 180 / Math.PI);
+					this.rotationY = hxd.Math.fmt(angles.y * 180 / Math.PI);
+					this.rotationZ = hxd.Math.fmt(angles.z * 180 / Math.PI);
+					this.scaleX = this.scaleY = this.scaleZ = 1;
+					this.x = hxd.Math.fmt(cam.pos.x);
+					this.y = hxd.Math.fmt(cam.pos.y);
+					this.z = hxd.Math.fmt(cam.pos.z);
+					this.zFar = cam.zFar;
+					this.zNear = cam.zNear;
+					this.fovY = cam.fovY;
+				});
+			}
 		});
 
 		props.find(".copy").click(function(e) {