Browse Source

allow custom material properties edition

Nicolas Cannasse 8 years ago
parent
commit
5f2f5775ae
10 changed files with 87 additions and 17 deletions
  1. 1 1
      .gitignore
  2. 5 0
      bin/app.html
  3. 1 0
      bin/style.css
  4. 1 1
      bin/style.less
  5. 2 0
      hide.hxml
  6. 1 1
      hide.hxproj
  7. 15 4
      hide/comp/PropsEditor.hx
  8. 38 2
      hide/ui/Ide.hx
  9. 2 0
      hide/ui/Props.hx
  10. 21 8
      hide/view/Particles3D.hx

+ 1 - 1
.gitignore

@@ -1,4 +1,4 @@
 /bin/nwjs
 /bin/nwjs
 /bin/style.min.css
 /bin/style.min.css
 /dump
 /dump
-/bin/props.json
+/bin/*.json

+ 5 - 0
bin/app.html

@@ -36,6 +36,11 @@
 			<menu label="Clear Recents" class="clear"></menu>
 			<menu label="Clear Recents" class="clear"></menu>
 		</menu>
 		</menu>
 		<separator></separator>
 		<separator></separator>
+		<menu label="Renderer">
+			<div class="renderers">
+			</div>
+		</menu>
+		<separator></separator>
 		<menu label="Exit" class="exit"></menu>
 		<menu label="Exit" class="exit"></menu>
 	</menu>
 	</menu>
 	<menu label="View" class="view">
 	<menu label="View" class="view">

+ 1 - 0
bin/style.css

@@ -243,6 +243,7 @@ input[type=checkbox]:checked:after {
   flex: 0 0 260px;
   flex: 0 0 260px;
   padding: 10px;
   padding: 10px;
   overflow: auto;
   overflow: auto;
+  padding-bottom: 80px;
 }
 }
 .hide-properties > .content {
 .hide-properties > .content {
   flex-grow: 100;
   flex-grow: 100;

+ 1 - 1
bin/style.less

@@ -263,6 +263,7 @@ input[type=checkbox] {
 		flex : 0 0 260px;
 		flex : 0 0 260px;
 		padding:10px;
 		padding:10px;
 		overflow:auto;
 		overflow:auto;
+		padding-bottom:80px;
 	}
 	}
 
 
 	>.content {
 	>.content {
@@ -339,7 +340,6 @@ input[type=checkbox] {
 		margin-bottom : 5px;
 		margin-bottom : 5px;
 	}
 	}
 
 
-
 }
 }
 
 
 /* Golden Layout Fixes */
 /* Golden Layout Fixes */

+ 2 - 0
hide.hxml

@@ -4,6 +4,8 @@
 -lib hxnodejs
 -lib hxnodejs
 -lib heaps
 -lib heaps
 -lib hxbit
 -lib hxbit
+-lib hscript
+-D hscriptPos
 -dce no
 -dce no
 --macro include('hide.view')
 --macro include('hide.view')
 --macro include('h3d.prim')
 --macro include('h3d.prim')

+ 1 - 1
hide.hxproj

@@ -24,7 +24,7 @@
     <option noInlineOnDebug="False" />
     <option noInlineOnDebug="False" />
     <option mainClass="hide.ui.Ide" />
     <option mainClass="hide.ui.Ide" />
     <option enabledebug="False" />
     <option enabledebug="False" />
-    <option additional="-lib hxnodejs&#xA;-lib heaps&#xA;-lib hxbit&#xA;-dce no&#xA;&#xA;--macro include('hide.view')&#xA;--macro include('h3d.prim')" />
+    <option additional="-lib hxnodejs&#xA;-lib heaps&#xA;-lib hxbit&#xA;-lib hscript&#xA;-D hscriptPos&#xA;-dce no&#xA;&#xA;--macro include('hide.view')&#xA;--macro include('h3d.prim')" />
   </build>
   </build>
   <!-- haxelib libraries -->
   <!-- haxelib libraries -->
   <haxelib>
   <haxelib>

+ 15 - 4
hide/comp/PropsEditor.hx

@@ -14,7 +14,18 @@ class PropsEditor extends Component {
 		panel = e.find(".panel");
 		panel = e.find(".panel");
 	}
 	}
 
 
-	public function add( e : Element, context : Dynamic ) {
+	public function addMaterial( m : h3d.mat.Material, props : Dynamic, ?parent : Element ) {
+		var def = h3d.mat.MaterialSetup.current.editMaterial(props);
+		def = add(def, props);
+		def.find("input,select").change(function(_) {
+			m.props = props;
+			def.remove();
+			addMaterial(m, props, parent);
+		});
+		if( parent != null && parent.length != 0 ) def.appendTo(parent);
+	}
+
+	public function add( e : Element, ?context : Dynamic ) {
 
 
 		e.appendTo(panel);
 		e.appendTo(panel);
 		e = e.wrap("<div></div>").parent(); // necessary to have find working on top level element
 		e = e.wrap("<div></div>").parent(); // necessary to have find working on top level element
@@ -26,7 +37,7 @@ class PropsEditor extends Component {
 		e.find(".section").not(".open").children(".content").hide();
 		e.find(".section").not(".open").children(".content").hide();
 		e.find(".section > h1").mousedown(function(e) {
 		e.find(".section > h1").mousedown(function(e) {
 			if( e.button != 0 ) return;
 			if( e.button != 0 ) return;
-			var section = js.jquery.Helper.JTHIS.parent();
+			var section = e.getThis().parent();
 			section.toggleClass("open");
 			section.toggleClass("open");
 			section.children(".content").slideToggle(100);
 			section.children(".content").slideToggle(100);
 		}).find("input").mousedown(function(e) e.stopPropagation());
 		}).find("input").mousedown(function(e) e.stopPropagation());
@@ -38,7 +49,7 @@ class PropsEditor extends Component {
 
 
 		e.find(".group > .title").mousedown(function(e) {
 		e.find(".group > .title").mousedown(function(e) {
 			if( e.button != 0 ) return;
 			if( e.button != 0 ) return;
-			var group = js.jquery.Helper.JTHIS.parent();
+			var group = e.getThis().parent();
 			group.children(".content").slideToggle(100);
 			group.children(".content").slideToggle(100);
 		}).find("input").mousedown(function(e) e.stopPropagation());
 		}).find("input").mousedown(function(e) e.stopPropagation());
 
 
@@ -131,10 +142,10 @@ class PropsEditor extends Component {
 				}
 				}
 				current = newVal;
 				current = newVal;
 				Reflect.setProperty(context, fname, newVal);
 				Reflect.setProperty(context, fname, newVal);
-
 			});
 			});
 		}
 		}
 
 
+		return e;
 	}
 	}
 
 
 }
 }

+ 38 - 2
hide/ui/Ide.hx

@@ -29,6 +29,8 @@ class Ide {
 	var updates : Array<Void->Void> = [];
 	var updates : Array<Void->Void> = [];
 	var views : Array<View<Dynamic>> = [];
 	var views : Array<View<Dynamic>> = [];
 
 
+	var renderers : Array<h3d.mat.MaterialSetup>;
+
 	function new() {
 	function new() {
 		inst = this;
 		inst = this;
 		window = nw.Window.get();
 		window = nw.Window.get();
@@ -187,6 +189,29 @@ class Ide {
 		}
 		}
 		window.title = "HIDE - " + dir;
 		window.title = "HIDE - " + dir;
 		props = Props.loadForProject(resourceDir);
 		props = Props.loadForProject(resourceDir);
+		renderers = [
+			new h3d.mat.MaterialSetup("Default"),
+		];
+		var path = getPath("Renderer.hx");
+		if( sys.FileSystem.exists(path) ) {
+			var r = new h3d.mat.MaterialScript();
+			try {
+				r.load(sys.io.File.getContent(path));
+				renderers.unshift(r);
+			} catch( e : Dynamic ) {
+				js.Browser.alert(e);
+			}
+			r.onError = function(msg) js.Browser.alert(msg);
+		}
+
+		var render = renderers[0];
+		for( r in renderers )
+			if( r.name == props.current.current.hide.renderer ) {
+				render = r;
+				break;
+			}
+		h3d.mat.MaterialSetup.current = render;
+
 		initMenu();
 		initMenu();
 		initLayout();
 		initLayout();
 	}
 	}
@@ -209,8 +234,8 @@ class Ide {
 
 
 	public function chooseDirectory( onSelect : String -> Void ) {
 	public function chooseDirectory( onSelect : String -> Void ) {
 		var e = new Element('<input type="file" value="" nwdirectory/>');
 		var e = new Element('<input type="file" value="" nwdirectory/>');
-		e.change(function(_) {
-			var dir = makeRelative(js.jquery.Helper.JTHIS.val());
+		e.change(function(ev) {
+			var dir = makeRelative(ev.getThis().val());
 			onSelect(dir == "" ? null : dir);
 			onSelect(dir == "" ? null : dir);
 			e.remove();
 			e.remove();
 		}).appendTo(window.window.document.body).click();
 		}).appendTo(window.window.document.body).click();
@@ -258,6 +283,17 @@ class Ide {
 			Sys.exit(0);
 			Sys.exit(0);
 		});
 		});
 
 
+		for( r in renderers ) {
+			new Element("<menu type='checkbox'>").attr("label", r.name).prop("checked",r == h3d.mat.MaterialSetup.current).appendTo(menu.find(".project .renderers")).click(function(_) {
+				if( r != h3d.mat.MaterialSetup.current ) {
+					if( props.user.source.hide == null ) props.user.source.hide = cast {};
+					props.user.source.hide.renderer = r.name;
+					props.user.save();
+					setProject(ideProps.currentProject);
+				}
+			});
+		}
+
 		// view
 		// view
 		if( !sys.FileSystem.exists(resourceDir) )
 		if( !sys.FileSystem.exists(resourceDir) )
 			menu.find(".view").remove();
 			menu.find(".view").remove();

+ 2 - 0
hide/ui/Props.hx

@@ -8,6 +8,7 @@ typedef HideProps = {
 	var recentProjects : Array<String>;
 	var recentProjects : Array<String>;
 
 
 	var windowPos : { x : Int, y : Int, w : Int, h : Int, max : Bool };
 	var windowPos : { x : Int, y : Int, w : Int, h : Int, max : Bool };
+	var renderer : String;
 };
 };
 
 
 typedef PropsDef = {
 typedef PropsDef = {
@@ -107,6 +108,7 @@ class Props {
 				recentProjects : [],
 				recentProjects : [],
 				currentProject : resourcePath,
 				currentProject : resourcePath,
 				windowPos : null,
 				windowPos : null,
+				renderer : null,
 			};
 			};
 
 
 		var perProject = new Props(userGlobals);
 		var perProject = new Props(userGlobals);

+ 21 - 8
hide/view/Particles3D.hx

@@ -54,6 +54,9 @@ class Particles3D extends FileView {
 						</dl>
 						</dl>
 					</div>
 					</div>
 
 
+					<div class="group material" name="Material">
+					</div>
+
 					<div class="group" name="Emit">
 					<div class="group" name="Emit">
 						<dl>
 						<dl>
 							<dt>Mode</dt><dd><select field="emitMode"/></dd>
 							<dt>Mode</dt><dd><select field="emitMode"/></dd>
@@ -115,6 +118,7 @@ class Particles3D extends FileView {
 				</div>
 				</div>
 			</div>
 			</div>
 		');
 		');
+
 		e.find("h1").contextmenu(function(ev) {
 		e.find("h1").contextmenu(function(ev) {
 			new hide.comp.ContextMenu([
 			new hide.comp.ContextMenu([
 				{ label : "Enable", checked : g.enable, click : function() { g.enable = !g.enable; e.find("[field=enable]").prop("checked", g.enable); } },
 				{ label : "Enable", checked : g.enable, click : function() { g.enable = !g.enable; e.find("[field=enable]").prop("checked", g.enable); } },
@@ -123,7 +127,8 @@ class Particles3D extends FileView {
 			ev.preventDefault();
 			ev.preventDefault();
 		});
 		});
 		e.find("[field=emitLoop]").change(function(_) parts.currentTime = 0);
 		e.find("[field=emitLoop]").change(function(_) parts.currentTime = 0);
-		properties.add(e,g);
+		properties.add(e, g);
+		properties.addMaterial( parts.materials[Lambda.indexOf({ iterator : parts.getGroups },g)], g.getMaterialProps(), e.find(".material > .content") );
 	}
 	}
 
 
 	function init() {
 	function init() {
@@ -135,21 +140,29 @@ class Particles3D extends FileView {
 
 
 		for( g in parts.getGroups() )
 		for( g in parts.getGroups() )
 			addGroup(g);
 			addGroup(g);
+
+
 		var extra = new Element('
 		var extra = new Element('
 			<div class="section open">
 			<div class="section open">
 				<h1>Manage</h1>
 				<h1>Manage</h1>
 				<div class="content">
 				<div class="content">
-					<div class="inputs">
-						<input type="button" class="new" value="New Group"/>
-						<div>Show Bounds <input type="checkbox" class="bounds"/></div>
-					</div>
+					<dl>
+					<dt>Show Bounds</dt><dd><input type="checkbox" class="bounds"/></dd>
+					<dt>Enable Lights</dt><dd><input type="checkbox" class="lights" checked="checked"/></dd>
+					<dt></dt><dd><input type="button" class="new" value="New Group"/></dd>
+					</dl>
 				</div>
 				</div>
 			</div>
 			</div>
 		');
 		');
-
+		extra = properties.add(extra);
 		extra.find(".bounds").change(function(e) bounds.visible = e.getThis().prop("checked"));
 		extra.find(".bounds").change(function(e) bounds.visible = e.getThis().prop("checked"));
-		extra.appendTo(properties.panel);
-
+		var defAmbient = scene.s3d.lightSystem.ambientLight.clone();
+		extra.find(".lights").change(function(e) {
+			var ls = scene.s3d.lightSystem;
+			var enable = e.getThis().prop("checked");
+			ls.maxLightsPerObject = enable ? 6 : 0;
+			if( enable ) ls.ambientLight.load(defAmbient) else ls.ambientLight.set(1, 1, 1);
+		});
 		extra.find(".new").click(function(_) {
 		extra.find(".new").click(function(_) {
 			var g = parts.addGroup();
 			var g = parts.addGroup();
 			g.name = "Group#" + Lambda.count({ iterator : parts.getGroups });
 			g.name = "Group#" + Lambda.count({ iterator : parts.getGroups });