Browse Source

Add l3d.Camera

trethaller 6 years ago
parent
commit
6603d6c12f
3 changed files with 57 additions and 0 deletions
  1. 1 0
      hide/comp/Scene.hx
  2. 1 0
      hide/comp/SceneEditor.hx
  3. 55 0
      hide/prefab/l3d/Camera.hx

+ 1 - 0
hide/comp/Scene.hx

@@ -71,6 +71,7 @@ class Scene extends Component implements h3d.IDrawable {
 	public var sevents : hxd.SceneEvents;
 	public var sevents : hxd.SceneEvents;
 	public var speed : Float = 1.0;
 	public var speed : Float = 1.0;
 	public var visible(default, null) : Bool = true;
 	public var visible(default, null) : Bool = true;
+	public var editor : hide.comp.SceneEditor;
 
 
 	public function new(config, parent, el) {
 	public function new(config, parent, el) {
 		super(parent,el);
 		super(parent,el);

+ 1 - 0
hide/comp/SceneEditor.hx

@@ -123,6 +123,7 @@ class SceneEditor {
 
 
 		var sceneEl = new Element('<div class="scene"></div>');
 		var sceneEl = new Element('<div class="scene"></div>');
 		scene = new hide.comp.Scene(view.config, null, sceneEl);
 		scene = new hide.comp.Scene(view.config, null, sceneEl);
+		scene.editor = this;
 		scene.onReady = onSceneReady;
 		scene.onReady = onSceneReady;
 		scene.onResize = function() {
 		scene.onResize = function() {
 			context.shared.root2d.x = scene.width >> 1;
 			context.shared.root2d.x = scene.width >> 1;

+ 55 - 0
hide/prefab/l3d/Camera.hx

@@ -0,0 +1,55 @@
+package hide.prefab.l3d;
+import hxd.prefab.Context;
+import hxd.prefab.Library;
+
+
+class Camera extends hide.prefab.Object3D {
+
+	public function new(?parent) {
+		super(parent);
+		type = "camera";
+	}
+
+
+	#if editor
+
+	override function setSelected( ctx : hide.prefab.Context, b : Bool ) {
+
+	}
+
+	override function edit( ctx : hide.prefab.EditContext ) {
+		super.edit(ctx);
+
+		var props : hide.Element = ctx.properties.add(new hide.Element('
+			<div class="group" name="Camera">
+				<dl>
+				</dl>
+				<dt></dt><dd><input class="preview" type="button" value="Preview" /></dd>
+			</div>
+		'),this, function(pname) {
+
+		});
+
+		props.find(".preview").click(function(e) {
+			var c = ctx.scene.s3d.camera;
+			var front = getTransform().front();
+			var ray = h3d.col.Ray.fromValues(x, y, z, front.x, front.y, front.z);
+			var plane = h3d.col.Plane.Z();
+			var pt = ray.intersect(plane);
+			if(pt != null) {
+				c.pos.set(x, y, z);
+				c.target = pt.toVector();
+				var cam = ctx.scene.editor.cameraController;
+				cam.loadFromCamera();
+			}
+		});
+	}
+
+	override function getHideProps() : hide.prefab.HideProps {
+		return { icon : "cogs", name : "Camera" };
+	}
+	#end
+
+	static var _ = Library.register("camera", Camera);
+
+}