ncannasse преди 7 години
родител
ревизия
a49a035387

+ 41 - 19
hide/comp/SceneEditor.hx

@@ -78,6 +78,7 @@ class SceneEditor {
 	public var tree : hide.comp.IconTree<PrefabElement>;
 	public var scene : hide.comp.Scene;
 	public var properties : hide.comp.PropsEditor;
+	public var context(default,null) : hide.prefab.Context;
 	public var curEdit(default, null) : SceneEditorContext;
 	public var snapToGround = false;
 	public var localTransform = true;
@@ -94,13 +95,11 @@ class SceneEditor {
 	function get_undo() { return view.undo; }
 
 	var view : hide.view.FileView;
-	var context : hide.prefab.Context;
 	var sceneData : PrefabElement;
 
-	public function new(view, context, data) {
+	public function new(view, data) {
 		ide = hide.Ide.inst;
 		this.view = view;
-		this.context = context;
 		this.sceneData = data;
 
 		event = new hxd.WaitEvent();
@@ -116,7 +115,11 @@ class SceneEditor {
 		var sceneEl = new Element('<div class="scene"></div>');
 		scene = new hide.comp.Scene(view.props, null, sceneEl);
 		scene.onReady = onSceneReady;
-		@:privateAccess context.shared = new hide.prefab.ContextShared(scene);
+
+		context = new hide.prefab.Context();
+		context.onError = function(e) ide.error(e);
+		context.shared = new hide.prefab.ContextShared(scene);
+		context.init();
 
 		view.keys.register("copy", onCopy);
 		view.keys.register("paste", onPaste);
@@ -228,6 +231,8 @@ class SceneEditor {
 			var newItems = getNewContextMenu(current);
 			var menuItems : Array<hide.comp.ContextMenu.ContextMenuItem> = [
 				{ label : "New...", menu : newItems },
+			];
+			var actionItems : Array<hide.comp.ContextMenu.ContextMenuItem> = [
 				{ label : "Rename", enabled : current != null, click : function() tree.editNode(current) },
 				{ label : "Delete", enabled : current != null, click : function() deleteElements(curEdit.rootElements) },
 				{ label : "Duplicate", enabled : current != null, click : duplicate.bind(false) },
@@ -235,23 +240,24 @@ class SceneEditor {
 			];
 
 			if(current != null && current.to(Object3D) != null) {
+				var visible = current.to(Object3D).visible;
 				menuItems = menuItems.concat([
+					{ label : "Visible", checked : visible, click : function() setVisible(curEdit.elements, !visible) },
 					{ label : "Select all", click : selectAll },
 					{ label : "Select children", enabled : current != null, click : function() selectObjects(current.flatten()) },
-					{ label : "Show", click : function() setVisible(curEdit.elements, true) },
-					{ label : "Hide", click : function() setVisible(curEdit.elements, false) },
+				]);
+				actionItems = actionItems.concat([
 					{ label : "Isolate", click : function() isolate(curEdit.elements) },
 					{ label : "Group", enabled : curEdit != null && canGroupSelection(), click : groupSelection }
 				]);
 			}
 			else if(current != null) {
 				var enabled = current.enabled;
-				menuItems = menuItems.concat([
-					{ label : enabled ? "Disable" : "Enable", click : function() setEnabled(curEdit.elements, !enabled) },
-				]);
+				menuItems.push({ label : "Enable", checked : enabled, click : function() setEnabled(curEdit.elements, !enabled) });
 			}
 
-			new hide.comp.ContextMenu(menuItems);
+			menuItems.push({ isSeparator : true, label : "" });
+			new hide.comp.ContextMenu(menuItems.concat(actionItems));
 		});
 		tree.allowRename = true;
 		tree.init();
@@ -1158,21 +1164,37 @@ class SceneEditor {
 	function getNewContextMenu(current: PrefabElement) : Array<hide.comp.ContextMenu.ContextMenuItem> {
 		var newItems = new Array<hide.comp.ContextMenu.ContextMenuItem>();
 		var allRegs = hxd.prefab.Library.getRegistered();
-		var allowed = ["model", "object"];
-		for( ptype in allowed ) {
-			newItems.push(getNewTypeMenuItem(ptype, current));
+		var parent = current == null ? sceneData : current;
+		var allowChildren = null;
+		{
+			var cur = parent;
+			while( allowChildren == null && cur != null ) {
+				allowChildren = cur.getHideProps().allowChildren;
+				cur = cur.parent;
+			}
+		}
+		for( ptype in allRegs.keys() ) {
+			var pinf = allRegs.get(ptype);
+			if( allowChildren != null && !allowChildren(ptype) ) {
+				if( pinf.inf.allowParent == null || !pinf.inf.allowParent(parent) )
+					continue;
+			} else {
+				if( pinf.inf.allowParent != null && !pinf.inf.allowParent(parent) )
+					continue;
+			}
+			newItems.push(getNewTypeMenuItem(ptype, parent));
 		}
+		newItems.sort(function(l1,l2) return Reflect.compare(l1.label,l2.label));
 		return newItems;
 	}
 
 	function getNewTypeMenuItem(ptype: String, parent: PrefabElement) : hide.comp.ContextMenu.ContextMenuItem {
-		var pcl = hxd.prefab.Library.getRegistered().get(ptype);
-		var props = Type.createEmptyInstance(pcl).getHideProps();
+		var pmodel = hxd.prefab.Library.getRegistered().get(ptype);
 		return {
-			label : props.name,
+			label : pmodel.inf.name,
 			click : function() {
 				function make(?path) {
-					var p = Type.createInstance(pcl, [parent]);
+					var p = Type.createInstance(pmodel.cl, [parent]);
 					@:privateAccess p.type = ptype;
 					if(path != null)
 						p.source = path;
@@ -1180,8 +1202,8 @@ class SceneEditor {
 					return p;
 				}
 
-				if( props.fileSource != null )
-					ide.chooseFile(props.fileSource, function(path) {
+				if( pmodel.inf.fileSource != null )
+					ide.chooseFile(pmodel.inf.fileSource, function(path) {
 						if( path == null ) return;
 						var p = make(path);
 						addObject(p);

+ 2 - 2
hide/prefab/Box.hx

@@ -61,8 +61,8 @@ class Box extends Object3D {
 		}
 	}
 
-	override function getHideProps() {
-		return { icon : "square", name : "Box", fileSource : null };
+	override function getHideProps() : HideProps {
+		return { icon : "square", name : "Box" };
 	}
 	#end
 

+ 1 - 1
hide/prefab/Curve.hx

@@ -219,7 +219,7 @@ class Curve extends Prefab {
 	}
 
 	#if editor
-	override function getHideProps() {
+	override function getHideProps() : HideProps {
 		return { icon : "paint-brush", name : "Curve", fileSource : null };
 	}
 	#end

+ 3 - 1
hide/prefab/HideProps.hx

@@ -4,4 +4,6 @@ typedef HideProps = {
 	var icon : String;
 	var name : String;
 	@:optional var fileSource : Array<String>;
-}
+	@:optional function allowChildren( type : String ) : Bool;
+	@:optional function allowParent( p : Prefab ) : Bool;
+}

+ 2 - 2
hide/prefab/Light.hx

@@ -239,8 +239,8 @@ class Light extends Object3D {
 
 	}
 
-	override function getHideProps() {
-		return { icon : "sun-o", name : "Light", fileSource : null };
+	override function getHideProps() : HideProps {
+		return { icon : "sun-o", name : "Light" };
 	}
 	#end
 

+ 1 - 1
hide/prefab/Material.hx

@@ -106,7 +106,7 @@ class Material extends Prefab {
 	}
 
 	override function getHideProps() : HideProps {
-		return { icon : "cog", name : "Material" };
+		return { icon : "cog", name : "Material", allowParent : function(p) return p.to(Object3D) != null };
 	}
 	#end
 

+ 1 - 1
hide/prefab/Model.hx

@@ -101,7 +101,7 @@ class Model extends Object3D {
 		});
 	}
 
-	override function getHideProps() {
+	override function getHideProps() : HideProps {
 		return { icon : "cube", name : "Model", fileSource : ["fbx","hmd"] };
 	}
 	#end

+ 5 - 2
hide/prefab/Object3D.hx

@@ -111,9 +111,12 @@ class Object3D extends Prefab {
 		});
 	}
 
-	override function getHideProps() {
+	override function getHideProps() : HideProps {
 		// Check children
-		return { icon : children == null || children.length > 0 ? "folder-open" : "genderless", name : "Group", fileSource : null };
+		return {
+			icon : children == null || children.length > 0 ? "folder-open" : "genderless",
+			name : "Group",
+		};
 	}
 	#end
 

+ 2 - 2
hide/prefab/Reference.hx

@@ -43,8 +43,8 @@ class Reference extends Prefab {
 	}
 
 	#if editor
-	override function getHideProps() {
-		return { icon : "share", name : "Reference", fileSource : null };
+	override function getHideProps() : HideProps {
+		return { icon : "share", name : "Reference" };
 	}
 	#end
 

+ 8 - 2
hide/prefab/RenderProps.hx

@@ -58,6 +58,12 @@ class RenderProps extends Prefab {
 		if( props == null )
 			return false;
 		renderer.props = props;
+		renderer.effects = [];
+		for( s in children ) {
+			var fx = Std.instance(s, hxd.prefab.rfx.RendererFX);
+			if( fx != null )
+				renderer.effects.push(fx);
+		}
 		renderer.refreshProps();
 		return true;
 	}
@@ -83,8 +89,8 @@ class RenderProps extends Prefab {
 		applyProps(renderer);
 	}
 
-	override function getHideProps() {
-		return { icon : "sun-o", name : "RenderProps", fileSource : null };
+	override function getHideProps() : HideProps {
+		return { icon : "sun-o", name : "RenderProps" };
 	}
 
 	#end

+ 1 - 1
hide/prefab/Scene.hx

@@ -32,7 +32,7 @@ class Scene extends Prefab {
 	}
 
 	#if editor
-	override function getHideProps() {
+	override function getHideProps() : HideProps {
 		return { icon : "cube", name : "Scene", fileSource : ["hsd"] };
 	}
 	#end

+ 2 - 2
hide/prefab/Shader.hx

@@ -136,8 +136,8 @@ class Shader extends Prefab {
 		});
 	}
 
-	override function getHideProps() {
-		return { icon : "cog", name : "Shader", fileSource : ["hx"] };
+	override function getHideProps() : HideProps {
+		return { icon : "cog", name : "Shader", fileSource : ["hx"], allowParent : function(p) return p.to(Object3D) != null };
 	}
 
 	#end

+ 2 - 2
hide/prefab/fx/Emitter.hx

@@ -728,8 +728,8 @@ class Emitter extends Object3D {
 		}
 	}
 
-	override function getHideProps() {
-		return { icon : "asterisk", name : "Emitter", fileSource : null };
+	override function getHideProps() : HideProps {
+		return { icon : "asterisk", name : "Emitter", allowParent : function(p) return p.to(FX) != null || p.getParent(FX) != null };
 	}
 	#end
 

+ 1 - 1
hide/prefab/fx/FX.hx

@@ -320,7 +320,7 @@ class FX extends hxd.prefab.Library {
 		});
 	}
 
-	override function getHideProps() {
+	override function getHideProps() : HideProps {
 		return { icon : "cube", name : "FX", fileSource : ["fx"] };
 	}
 	#end

+ 2 - 2
hide/prefab/l3d/Decal.hx

@@ -70,8 +70,8 @@ class Decal extends Object3D {
 
 
 	#if editor
-	override function getHideProps() {
-		return { icon : "paint-brush", name : "Decal", fileSource : null };
+	override function getHideProps() : HideProps {
+		return { icon : "paint-brush", name : "Decal" };
 	}
 
 	override function edit( ctx : EditContext ) {

+ 2 - 2
hide/prefab/l3d/Instance.hx

@@ -47,8 +47,8 @@ class Instance extends Object3D {
 		//ctx.properties.addProps([for(c in sheet.columns) {t: getPropType(c), name: c.name}], this.props);
 	}
 
-	override function getHideProps() {
-		return { icon : "circle", name : "Instance", fileSource : null };
+	override function getHideProps() : HideProps {
+		return { icon : "circle", name : "Instance", allowParent : function(p) return p.type == "layer" };
 	}
 
 	// Move to Prefab?

+ 2 - 2
hide/prefab/l3d/Layer.hx

@@ -86,8 +86,8 @@ class Layer extends Object3D {
 		}
 	}
 
-	override function getHideProps() {
-		return { icon : "file", name : "Layer", fileSource : null };
+	override function getHideProps() : HideProps {
+		return { icon : "file", name : "Layer" };
 	}
 	#end
 

+ 2 - 2
hide/prefab/l3d/Level3D.hx

@@ -39,8 +39,8 @@ class Level3D extends hxd.prefab.Library {
 		});
 	}
 
-	override function getHideProps() {
-		return { icon : "cube", name : "Level3D", fileSource : ["l3d"] };
+	override function getHideProps() : HideProps {
+		return { icon : "cube", name : "Level3D", fileSource : ["l3d"], allowChildren : function(t) return hxd.prefab.Library.isOfType(t,Object3D) };
 	}
 
 	#end

+ 2 - 2
hide/prefab/l3d/Polygon.hx

@@ -133,8 +133,8 @@ class Polygon extends Object3D {
 		});
 	}
 
-	override function getHideProps() {
-		return { icon : "square", name : "Polygon", fileSource : null };
+	override function getHideProps() : HideProps {
+		return { icon : "square", name : "Polygon" };
 	}
 
 	#end

+ 9 - 15
hide/view/FXEditor.hx

@@ -27,8 +27,8 @@ class FXEditContext extends hide.prefab.EditContext {
 @:access(hide.view.FXEditor)
 private class FXSceneEditor extends hide.comp.SceneEditor {
 	var parent : hide.view.FXEditor;
-	public function new(view, context, data) {
-		super(view, context, data);
+	public function new(view,  data) {
+		super(view, data);
 		parent = cast view;
 	}
 
@@ -74,7 +74,7 @@ private class FXSceneEditor extends hide.comp.SceneEditor {
 				function shaderItem(name, path) : hide.comp.ContextMenu.ContextMenuItem {
 					return {
 						label : name,
-						click : function() {	
+						click : function() {
 							var s = new hide.prefab.Shader(parentElt);
 							s.source = path;
 							s.name = name;
@@ -105,6 +105,7 @@ private class FXSceneEditor extends hide.comp.SceneEditor {
 			}
 
 			// Other prefabs
+			// TODO : use allowParent/allowChildren
 			var allowed = ["model", "object", "emitter", "constraint", "polygon", "material"];
 			for( ptype in allowed ) {
 				registered.push(getNewTypeMenuItem(ptype, parentElt));
@@ -118,7 +119,6 @@ class FXEditor extends FileView {
 
 	var sceneEditor : FXSceneEditor;
 	var data : hide.prefab.fx.FX;
-	var context : hide.prefab.Context;
 	var tabs : hide.comp.Tabs;
 	var fxprops : hide.comp.PropsEditor;
 
@@ -185,12 +185,6 @@ class FXEditor extends FileView {
 		data.load(haxe.Json.parse(content));
 		currentSign = haxe.crypto.Md5.encode(content);
 
-		context = new hide.prefab.Context();
-		context.onError = function(e) {
-			ide.error(e);
-		};
-		context.init();
-
 		element.html('
 			<div class="flex vertical">
 				<div class="toolbar"></div>
@@ -225,7 +219,7 @@ class FXEditor extends FileView {
 			</div>');
 		tools = new hide.comp.Toolbar(null,element.find(".toolbar"));
 		tabs = new hide.comp.Tabs(null,element.find(".tabs"));
-		sceneEditor = new FXSceneEditor(this, context, data);
+		sceneEditor = new FXSceneEditor(this, data);
 		element.find(".hide-scene-tree").first().append(sceneEditor.tree.element);
 		element.find(".hide-scroll").first().append(sceneEditor.properties.element);
 		element.find(".scene").first().append(sceneEditor.scene.element);
@@ -235,7 +229,7 @@ class FXEditor extends FileView {
 		});
 		fxprops = new hide.comp.PropsEditor(undo,null,element.find(".fx-props"));
 		{
-			var edit = new FXEditContext(this, context);
+			var edit = new FXEditContext(this, sceneEditor.context);
 			edit.prefabPath = state.path;
 			edit.properties = fxprops;
 			edit.scene = sceneEditor.scene;
@@ -356,7 +350,7 @@ class FXEditor extends FileView {
 
 		tools.saveDisplayKey = "FXScene/tools";
 		tools.addButton("video-camera", "Perspective camera", () -> sceneEditor.resetCamera(false));
-		
+
 		function renderProps() {
 			properties.clear();
 			var renderer = scene.s3d.renderer;
@@ -507,7 +501,7 @@ class FXEditor extends FileView {
 				icon.removeClass("fa-angle-down").addClass("fa-angle-right");
 			curvesContainer.toggleClass("hidden", !expand);
 			for(c in trackEdits)
-				c.refresh();	
+				c.refresh();
 		}
 		trackEl.find(".track-prop").click(function(e) {
 			expand = !expand;
@@ -1000,7 +994,7 @@ class FXEditor extends FileView {
 				anim.setRandSeed(Std.random(0xFFFFFF));
 			}
 		}
-		
+
 		if(anim != null) {
 			anim.setTime(currentTime);
 		}

+ 3 - 20
hide/view/Prefab.hx

@@ -5,8 +5,8 @@ import hide.prefab.Prefab in PrefabElement;
 @:access(hide.view.Prefab)
 private class PrefabSceneEditor extends hide.comp.SceneEditor {
 	var parent : Prefab;
-	public function new(view, context, data) {
-		super(view, context, data);
+	public function new(view, data) {
+		super(view, data);
 		parent = cast view;
 	}
 	override function onSceneReady() {
@@ -17,23 +17,12 @@ private class PrefabSceneEditor extends hide.comp.SceneEditor {
 		super.update(dt);
 		parent.onUpdate(dt);
 	}
-
-	override function getNewContextMenu(current: PrefabElement) {
-		var registered = new Array<hide.comp.ContextMenu.ContextMenuItem>();
-		var allRegs = hxd.prefab.Library.getRegistered();
-		for( ptype in allRegs.keys() ) {
-			if( ptype == "prefab" ) continue;
-			registered.push(getNewTypeMenuItem(ptype, current == null ? sceneData : current));
-		}
-		return registered;
-	}
 }
 
 class Prefab extends FileView {
 
 	var sceneEditor : PrefabSceneEditor;
 	var data : hxd.prefab.Library;
-	var context : hide.prefab.Context;
 	var tabs : hide.comp.Tabs;
 
 	var tools : hide.comp.Toolbar;
@@ -80,12 +69,6 @@ class Prefab extends FileView {
 		data.load(haxe.Json.parse(content));
 		currentSign = haxe.crypto.Md5.encode(content);
 
-		context = new hide.prefab.Context();
-		context.onError = function(e) {
-			ide.error(e);
-		};
-		context.init();
-
 		element.html('
 			<div class="flex vertical">
 				<div class="toolbar"></div>
@@ -105,7 +88,7 @@ class Prefab extends FileView {
 		');
 		tools = new hide.comp.Toolbar(null,element.find(".toolbar"));
 		tabs = new hide.comp.Tabs(null,element.find(".tabs"));
-		sceneEditor = new PrefabSceneEditor(this, context, data);
+		sceneEditor = new PrefabSceneEditor(this, data);
 		element.find(".hide-scene-tree").first().append(sceneEditor.tree.element);
 		element.find(".tab").first().append(sceneEditor.properties.element);
 		element.find(".scene").first().append(sceneEditor.scene.element);

+ 9 - 26
hide/view/l3d/Level3D.hx

@@ -74,8 +74,8 @@ class CamController extends h3d.scene.CameraController {
 private class Level3DSceneEditor extends hide.comp.SceneEditor {
 	var parent : Level3D;
 
-	public function new(view, context, data) {
-		super(view, context, data);
+	public function new(view, data) {
+		super(view, data);
 		parent = cast view;
 		this.localTransform = false; // TODO: Expose option
 	}
@@ -145,17 +145,9 @@ private class Level3DSceneEditor extends hide.comp.SceneEditor {
 
 	override function getNewContextMenu(current: PrefabElement) {
 		var newItems = new Array<hide.comp.ContextMenu.ContextMenuItem>();
-		var allRegs = hxd.prefab.Library.getRegistered();
-		var allowed = ["model", "object", "layer", "box", "polygon", "light", "decal"];
 
-		if(current != null && current.type == "object" && current.name == "settings" && current.parent == sceneData) {
-			allowed = ["renderProps"];
-		}
-
-		if(current != null && (current.type == "model" || current.type == "polygon" || current.type == "object")) {
-			allowed.push("material");
-			allowed.push("shader");
-		}
+		if(current != null && current.type == "object" && current.name == "settings" && current.parent == sceneData)
+			newItems.push(getNewTypeMenuItem("renderProps",current)); // hack : todo
 
 		var curLayer = current != null ? current.to(hide.prefab.l3d.Layer) : null;
 		var cdbSheet = curLayer != null ? curLayer.getCdbModel(curLayer) : null;
@@ -179,9 +171,7 @@ private class Level3DSceneEditor extends hide.comp.SceneEditor {
 			haxe.Timer.delay(addObject.bind(p), 0);
 		}
 
-		for( ptype in allowed ) {
-			newItems.push(getNewTypeMenuItem(ptype, current == null ? sceneData : current));
-		}
+		newItems = newItems.concat(super.getNewContextMenu(current));
 
 		function addNewInstances() {
 			if(curLayer == null)
@@ -232,7 +222,6 @@ class Level3D extends FileView {
 
 	var sceneEditor : Level3DSceneEditor;
 	var data : hide.prefab.l3d.Level3D;
-	var context : hide.prefab.Context;
 	var tabs : hide.comp.Tabs;
 
 	var tools : hide.comp.Toolbar;
@@ -265,12 +254,6 @@ class Level3D extends FileView {
 		data.load(haxe.Json.parse(content));
 		currentSign = haxe.crypto.Md5.encode(content);
 
-		context = new hide.prefab.Context();
-		context.onError = function(e) {
-			ide.error(e);
-		};
-		context.init();
-
 		element.html('
 			<div class="flex vertical">
 				<div class="toolbar">
@@ -301,7 +284,7 @@ class Level3D extends FileView {
 		currentVersion = undo.currentID;
 
 		levelProps = new hide.comp.PropsEditor(undo,null,element.find(".level-props"));
-		sceneEditor = new Level3DSceneEditor(this, context, data);
+		sceneEditor = new Level3DSceneEditor(this, data);
 		sceneEditor.addSearchBox(element.find(".hide-scene-tree").first());
 		element.find(".hide-scene-tree").first().append(sceneEditor.tree.element);
 		element.find(".hide-scroll").first().append(sceneEditor.properties.element);
@@ -310,7 +293,7 @@ class Level3D extends FileView {
 
 		// Level edit
 		{
-			var edit = new LevelEditContext(this, context);
+			var edit = new LevelEditContext(this, sceneEditor.context);
 			edit.prefabPath = state.path;
 			edit.properties = levelProps;
 			edit.scene = sceneEditor.scene;
@@ -406,7 +389,7 @@ class Level3D extends FileView {
 	}
 
 	function onRefreshScene() {
-		var all = context.shared.contexts.keys();
+		var all = sceneEditor.context.shared.contexts.keys();
 		for(elt in all)
 			refreshSceneStyle(elt);
 
@@ -456,7 +439,7 @@ class Level3D extends FileView {
 				b.element.remove();
 		}
 		layerButtons = new Map<PrefabElement, hide.comp.Toolbar.ToolToggle>();
-		var all = context.shared.contexts.keys();
+		var all = sceneEditor.context.shared.contexts.keys();
 		var initDone = false;
 		for(elt in all) {
 			var layer = elt.to(hide.prefab.l3d.Layer);