Quellcode durchsuchen

cleanup : moved render order from Scene 3d to App

ncannasse vor 8 Jahren
Ursprung
Commit
82ccfe0a10
3 geänderte Dateien mit 16 neuen und 46 gelöschten Zeilen
  1. 1 23
      h3d/scene/Scene.hx
  2. 8 7
      hxd/App.hx
  3. 7 16
      hxd/inspect/Inspector.hx

+ 1 - 23
h3d/scene/Scene.hx

@@ -5,8 +5,6 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 	public var camera : h3d.Camera;
 	public var camera : h3d.Camera;
 	public var lightSystem : h3d.pass.LightSystem;
 	public var lightSystem : h3d.pass.LightSystem;
 	public var renderer(default,set) : Renderer;
 	public var renderer(default,set) : Renderer;
-	var prePasses : Array<h3d.IDrawable>;
-	var postPasses : Array<h3d.IDrawable>;
 	var ctx : RenderContext;
 	var ctx : RenderContext;
 	var interactives : Array<Interactive>;
 	var interactives : Array<Interactive>;
 	@:allow(h3d.scene.Interactive)
 	@:allow(h3d.scene.Interactive)
@@ -27,8 +25,6 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		ctx = new RenderContext();
 		ctx = new RenderContext();
 		renderer = new Renderer();
 		renderer = new Renderer();
 		lightSystem = new h3d.pass.LightSystem();
 		lightSystem = new h3d.pass.LightSystem();
-		postPasses = [];
-		prePasses = [];
 	}
 	}
 
 
 	@:noCompletion public function setEvents(events) {
 	@:noCompletion public function setEvents(events) {
@@ -178,21 +174,6 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		renderer = new Renderer();
 		renderer = new Renderer();
 	}
 	}
 
 
-	/**
-	 allow to customize render passes (for example, branch sub scene or 2d context)
-	 */
-	public function addPass(p,before=false) {
-		if( before )
-			prePasses.push(p);
-		else
-			postPasses.push(p);
-	}
-
-	public function removePass(p) {
-		postPasses.remove(p);
-		prePasses.remove(p);
-	}
-
 	@:allow(h3d)
 	@:allow(h3d)
 	function addEventTarget(i:Interactive) {
 	function addEventTarget(i:Interactive) {
 		interactives.push(i);
 		interactives.push(i);
@@ -272,8 +253,7 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		ctx.camera = camera;
 		ctx.camera = camera;
 		ctx.engine = engine;
 		ctx.engine = engine;
 		ctx.start();
 		ctx.start();
-		for( p in prePasses )
-			p.render(engine);
+
 		syncRec(ctx);
 		syncRec(ctx);
 		emitRec(ctx);
 		emitRec(ctx);
 		// sort by pass id
 		// sort by pass id
@@ -316,8 +296,6 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		#end
 		#end
 
 
 		ctx.done();
 		ctx.done();
-		for( p in postPasses )
-			p.render(engine);
 		ctx.camera = null;
 		ctx.camera = null;
 		ctx.engine = null;
 		ctx.engine = null;
 	}
 	}

+ 8 - 7
hxd/App.hx

@@ -1,6 +1,6 @@
 package hxd;
 package hxd;
 
 
-class App {
+class App implements h3d.IDrawable {
 
 
 	public var engine : h3d.Engine;
 	public var engine : h3d.Engine;
 	public var s3d : h3d.scene.Scene;
 	public var s3d : h3d.scene.Scene;
@@ -33,7 +33,6 @@ class App {
 	function setScene3D( s3d : h3d.scene.Scene, disposePrevious = true ) {
 	function setScene3D( s3d : h3d.scene.Scene, disposePrevious = true ) {
 		sevents.removeScene(this.s3d);
 		sevents.removeScene(this.s3d);
 		sevents.addScene(s3d);
 		sevents.addScene(s3d);
-		s3d.addPass(s2d);
 		if( disposePrevious )
 		if( disposePrevious )
 			this.s3d.dispose();
 			this.s3d.dispose();
 		this.s3d = s3d;
 		this.s3d = s3d;
@@ -42,13 +41,16 @@ class App {
 	function setScene2D( s2d : h2d.Scene, disposePrevious = true ) {
 	function setScene2D( s2d : h2d.Scene, disposePrevious = true ) {
 		sevents.removeScene(this.s2d);
 		sevents.removeScene(this.s2d);
 		sevents.addScene(s2d,0);
 		sevents.addScene(s2d,0);
-		s3d.removePass(this.s2d);
-		s3d.addPass(s2d);
 		if( disposePrevious )
 		if( disposePrevious )
 			this.s2d.dispose();
 			this.s2d.dispose();
 		this.s2d = s2d;
 		this.s2d = s2d;
 	}
 	}
 
 
+	public function render(e:h3d.Engine) {
+		s3d.render(e);
+		s2d.render(e);
+	}
+
 	function setup() {
 	function setup() {
 		var initDone = false;
 		var initDone = false;
 		engine.onResized = function() {
 		engine.onResized = function() {
@@ -58,7 +60,6 @@ class App {
 		};
 		};
 		s3d = new h3d.scene.Scene();
 		s3d = new h3d.scene.Scene();
 		s2d = new h2d.Scene();
 		s2d = new h2d.Scene();
-		s3d.addPass(s2d);
 		sevents = new hxd.SceneEvents();
 		sevents = new hxd.SceneEvents();
 		sevents.addScene(s2d);
 		sevents.addScene(s2d);
 		sevents.addScene(s3d);
 		sevents.addScene(s3d);
@@ -102,7 +103,7 @@ class App {
 			log.logLines = [];
 			log.logLines = [];
 			engine.setDriver(log);
 			engine.setDriver(log);
 			try {
 			try {
-				engine.render(s3d);
+				engine.render(this);
 			} catch( e : Dynamic ) {
 			} catch( e : Dynamic ) {
 				log.logLines.push(Std.string(e));
 				log.logLines.push(Std.string(e));
 			}
 			}
@@ -112,7 +113,7 @@ class App {
 			return;
 			return;
 		}
 		}
 		#end
 		#end
-		engine.render(s3d);
+		engine.render(this);
 	}
 	}
 
 
 	function update( dt : Float ) {
 	function update( dt : Float ) {

+ 7 - 16
hxd/inspect/Inspector.hx

@@ -2,16 +2,6 @@ package hxd.inspect;
 import cdb.jq.JQuery;
 import cdb.jq.JQuery;
 import hxd.inspect.Property;
 import hxd.inspect.Property;
 
 
-private class DrawEvent implements h3d.IDrawable {
-	var i : Inspector;
-	public function new(i) {
-		this.i = i;
-	}
-	public function render( engine : h3d.Engine ) {
-		i.sync();
-	}
-}
-
 class Tool {
 class Tool {
 	public var name(default,set) : String;
 	public var name(default,set) : String;
 	public var icon(default,set) : String;
 	public var icon(default,set) : String;
@@ -55,7 +45,6 @@ class Inspector {
 
 
 	var props : PropManager;
 	var props : PropManager;
 	var jroot : JQuery;
 	var jroot : JQuery;
-	var event : DrawEvent;
 	var oldLog : Dynamic -> haxe.PosInfos -> Void;
 	var oldLog : Dynamic -> haxe.PosInfos -> Void;
 	var savedFile : String;
 	var savedFile : String;
 	var oldLoop : Void -> Void;
 	var oldLoop : Void -> Void;
@@ -70,12 +59,12 @@ class Inspector {
 	var logPanel : Panel;
 	var logPanel : Panel;
 	var panelList : Array<{ name : String, create : Void -> Panel, p : Panel } >;
 	var panelList : Array<{ name : String, create : Void -> Panel, p : Panel } >;
 	var currentNode : Node;
 	var currentNode : Node;
+	var event : haxe.MainLoop.MainEvent;
 
 
 	public function new( scene, ?host, ?port ) {
 	public function new( scene, ?host, ?port ) {
 
 
 		current = this;
 		current = this;
 
 
-		event = new DrawEvent(this);
 		savedFile = "sceneProps.js";
 		savedFile = "sceneProps.js";
 		state = new Map();
 		state = new Map();
 		oldLog = haxe.Log.trace;
 		oldLog = haxe.Log.trace;
@@ -274,10 +263,12 @@ class Inspector {
 	}
 	}
 
 
 	function set_scene(s:h3d.scene.Scene) {
 	function set_scene(s:h3d.scene.Scene) {
-		if( scene != null )
-			scene.removePass(event);
-		if( s != null )
-			s.addPass(event);
+		if( s == null && event != null ) {
+			event.stop();
+			event = null;
+		}
+		if( s != null && event == null )
+			event = haxe.MainLoop.add(sync);
 		return scene = s;
 		return scene = s;
 	}
 	}