2
0
Эх сурвалжийг харах

moved prefab from heaps to hide

ncannasse 6 жил өмнө
parent
commit
8d94fd4ad1

+ 14 - 0
h3d/impl/RendererFX.hx

@@ -0,0 +1,14 @@
+package h3d.impl;
+
+enum Step {
+	BeforeLighting;
+	BeforeTonemapping;
+	AfterTonemapping;
+	AfterUI;
+}
+
+interface RendererFX {
+	public var enabled : Bool;
+	public function apply( r : h3d.scene.Renderer, step : Step ) : Void;
+	public function dispose() : Void;
+}

+ 3 - 2
h3d/scene/Renderer.hx

@@ -16,7 +16,7 @@ enum RenderMode{
 	LightProbe;
 }
 
-@:allow(hxd.prefab.rfx.RendererFX)
+@:allow(hrt.prefab.rfx.RendererFX)
 @:allow(h3d.pass.Shadows)
 class Renderer extends hxd.impl.AnyProps {
 
@@ -27,7 +27,8 @@ class Renderer extends hxd.impl.AnyProps {
 	var ctx : RenderContext;
 	var hasSetTarget = false;
 
-	public var effects : Array<hxd.prefab.rfx.RendererFX> = [];
+	public var effects : Array<h3d.impl.RendererFX> = [];
+	
 	public var renderMode : RenderMode = Default;
 
 	public function new() {

+ 1 - 1
h3d/scene/pbr/Renderer.hx

@@ -207,7 +207,7 @@ class Renderer extends h3d.scene.Renderer {
 		}
 	}
 
-	function apply( step : hxd.prefab.rfx.RendererFX.Step ) {
+	function apply( step : h3d.impl.RendererFX.Step ) {
 		for( f in effects )
 			if( f.enabled )
 				f.apply(this, step);

+ 0 - 86
hxd/prefab/Context.hx

@@ -1,86 +0,0 @@
-package hxd.prefab;
-
-@:final class Context {
-
-	public var local2d : h2d.Object;
-	public var local3d : h3d.scene.Object;
-	public var shared : ContextShared;
-	public var cleanup : Void -> Void;
-	public var custom : Dynamic;
-	public var isRef : Bool = false;
-
-	public function new() {
-	}
-
-	public function init() {
-		if( shared == null )
-			shared = new ContextShared();
-		local2d = shared.root2d;
-		local3d = shared.root3d;
-	}
-
-	public function clone( p : Prefab ) {
-		var c = new Context();
-		c.shared = shared;
-		c.local2d = local2d;
-		c.local3d = local3d;
-		c.custom = custom;
-		c.isRef = isRef;
-		if( p != null ) {
-			if(!isRef)
-				shared.contexts.set(p, c);
-			else {
-				if(!shared.references.exists(p))
-					shared.references.set(p, [c])
-				else
-					shared.references[p].push(c);
-			}
-		}
-		return c;
-	}
-
-	public function loadModel( path : String ) {
-		return shared.loadModel(path);
-	}
-
-	public function loadAnimation( path : String ) {
-		return shared.loadAnimation(path);
-	}
-
-	public function loadTexture( path : String ) {
-		return shared.loadTexture(path);
-	}
-
-	public function loadShader( name : String ) {
-		return shared.loadShader(name);
-	}
-
-	public function locateObject( path : String ) {
-		if( path == null )
-			return null;
-		var parts = path.split(".");
-		var root = shared.root3d;
-		while( parts.length > 0 ) {
-			var v = null;
-			var pname = parts.shift();
-			for( o in root )
-				if( o.name == pname ) {
-					v = o;
-					break;
-				}
-			if( v == null ) {
-				v = root.getObjectByName(pname);
-				//if( v != null && v.parent != root ) v = null; ??
-			}
-			if( v == null ) {
-				var parts2 = path.split(".");
-				for( i in 0...parts.length ) parts2.pop();
-				shared.onError("Object not found " + parts2.join("."));
-				return null;
-			}
-			root = v;
-		}
-		return root;
-	}
-
-}

+ 0 - 237
hxd/prefab/ContextShared.hx

@@ -1,237 +0,0 @@
-package hxd.prefab;
-
-typedef ShaderDef = {
-	var shader : hxsl.SharedShader;
-	var inits : Array<{ v : hxsl.Ast.TVar, e : hxsl.Ast.TExpr }>;
-}
-
-typedef ShaderDefCache = Map<String, ShaderDef>;
-
-class ContextShared {
-	public var root2d : h2d.Object;
-	public var root3d : h3d.scene.Object;
-	public var contexts : Map<Prefab,Context>;
-	public var references : Map<Prefab,Array<Context>>;
-	public var currentPath : String;
-	public var editorDisplay : Bool;
-
-	var cache : h3d.prim.ModelCache;
-	var shaderCache : ShaderDefCache;
-	var bakedData : Map<String, haxe.io.Bytes>;
-
-	public function new() {
-		root2d = new h2d.Object();
-		root3d = new h3d.scene.Object();
-		contexts = new Map();
-		references = new Map();
-		cache = new h3d.prim.ModelCache();
-		shaderCache = new ShaderDefCache();
-	}
-
-	public function onError( e : Dynamic ) {
-		throw e;
-	}
-
-	public function elements() {
-		return [for(e in contexts.keys()) e];
-	}
-
-	public function getContexts(p: Prefab) {
-		var ret : Array<Context> = [];
-		var ctx = contexts.get(p);
-		if(ctx != null)
-			ret.push(ctx);
-		var ctxs = references.get(p);
-		if(ctxs != null)
-			return ret.concat(ctxs);
-		return ret;
-	}
-
-	public function loadDir(p : String, ?dir : String ) : Array<hxd.res.Any> {
-		var datPath = new haxe.io.Path(currentPath);
-		datPath.ext = "dat";
-		var path = datPath.toString() + "/" + p;
-		if(dir != null) path += "/" + dir;
-		return try hxd.res.Loader.currentInstance.dir(path) catch( e : hxd.res.NotFound ) null;
-	}
-
-	public function loadPrefabDat(file : String, ext : String, p : String) : hxd.res.Any {
-		var datPath = new haxe.io.Path(currentPath);
-		datPath.ext = "dat";
-		var path = new haxe.io.Path(datPath.toString() + "/" + p + "/" + file);
-		path.ext = ext;
-		return try hxd.res.Loader.currentInstance.load(path.toString()) catch( e : hxd.res.NotFound ) null;
-	}
-
-	public function savePrefabDat(file : String, ext : String, p : String, bytes : haxe.io.Bytes ) {
-		throw "Not implemented";
-	}
-
-	public function loadPrefab( path : String ) : Prefab {
-		throw "Not implemented";
-	}
-
-	public function loadShader( path : String ) : ShaderDef {
-		var r = shaderCache.get(path);
-		if(r != null)
-			return r;
-		var cl = Type.resolveClass(path.split("/").join("."));
-		if(cl == null) return null;
-		var shader = new hxsl.SharedShader(Reflect.field(cl, "SRC"));
-		r = {
-			shader: shader,
-			inits: []
-		};
-		shaderCache.set(path, r);
-		return r;
-	}
-
-	public function loadModel( path : String ) {
-		return cache.loadModel(hxd.res.Loader.currentInstance.load(path).toModel());
-	}
-
-	public function loadAnimation( path : String ) {
-		return @:privateAccess cache.loadAnimation(hxd.res.Loader.currentInstance.load(path).toModel());
-	}
-
-	public function loadTexture( path : String ) {
-		return cache.loadTexture(null, path);
-	}
-
-	public function loadBytes( file : String) : haxe.io.Bytes {
-		return try hxd.res.Loader.currentInstance.load(file).entry.getBytes() catch( e : hxd.res.NotFound ) null;
-	}
-
-	public function loadBakedBytes( file : String ) {
-		if( bakedData == null ) loadBakedData();
-		return bakedData.get(file);
-	}
-
-	public function saveBakedBytes( file : String, bytes : haxe.io.Bytes ) {
-		if( bakedData == null ) loadBakedData();
-		if( bytes == null ) {
-			if( !bakedData.remove(file) )
-				return;
-		} else
-			bakedData.set(file, bytes);
-		var keys = Lambda.array({ iterator : bakedData.keys });
-		if( keys.length == 0 ) {
-			saveBakedFile(null);
-			return;
-		}
-		var bytes = new haxe.io.BytesOutput();
-		bytes.writeString("BAKE");
-		bytes.writeInt32(keys.length);
-		var headerSize = 8;
-		for( name in keys )
-			headerSize += 2 + name.length + 8;
-		for( name in keys ) {
-			bytes.writeUInt16(name.length);
-			bytes.writeString(name);
-			bytes.writeInt32(headerSize);
-			var len = bakedData.get(name).length;
-			bytes.writeInt32(len);
-			headerSize += len + 1;
-		}
-		for( name in keys ) {
-			bytes.write(bakedData.get(name));
-			bytes.writeByte(0xFE); // stop
-		}
-		saveBakedFile(bytes.getBytes());
-	}
-
-	public function saveTexture( file : String, bytes : haxe.io.Bytes , dir : String, ext : String) {
-		throw "Don't know how to save texture";
-	}
-
-	function saveBakedFile( bytes : haxe.io.Bytes ) {
-		throw "Don't know how to save baked file";
-	}
-
-	function loadBakedFile() {
-		var path = new haxe.io.Path(currentPath);
-		path.ext = "bake";
-		return try hxd.res.Loader.currentInstance.load(path.toString()).entry.getBytes() catch( e : hxd.res.NotFound ) null;
-	}
-
-	function loadBakedData() {
-		bakedData = new Map();
-		var data = loadBakedFile();
-		if( data == null )
-			return;
-		if( data.getString(0,4) != "BAKE" )
-			throw "Invalid bake file";
-		var count = data.getInt32(4);
-		var pos = 8;
-		for( i in 0...count ) {
-			var len = data.getUInt16(pos);
-			pos += 2;
-			var name = data.getString(pos, len);
-			pos += len;
-			var bytesPos = data.getInt32(pos);
-			pos += 4;
-			var bytesLen = data.getInt32(pos);
-			pos += 4;
-			bakedData.set(name,data.sub(bytesPos,bytesLen));
-			if( data.get(bytesPos+bytesLen) != 0xFE )
-				throw "Corrupted bake file";
-		}
-	}
-
-	function getChildrenRoots( base : h3d.scene.Object, p : Prefab, out : Array<h3d.scene.Object> ) {
-		for( c in p.children ) {
-			var ctx = contexts.get(c);
-			if( ctx == null ) continue;
-			if( ctx.local3d == base )
-				getChildrenRoots(base, c, out);
-			else
-				out.push(ctx.local3d);
-		}
-		return out;
-	}
-
-	public function getObjects<T:h3d.scene.Object>( p : Prefab, c: Class<T> ) : Array<T> {
-		var ctx = contexts.get(p);
-		if( ctx == null )
-			return [];
-		var root = ctx.local3d;
-		var childObjs = getChildrenRoots(root, p, []);
-		var ret = [];
-		function rec(o : h3d.scene.Object) {
-			var m = Std.instance(o, c);
-			if(m != null) ret.push(m);
-			for( child in o )
-				if( childObjs.indexOf(child) < 0 )
-					rec(child);
-		}
-		rec(root);
-		return ret;
-	}
-
-	public function getMaterials( p : Prefab ) {
-		var ctx = contexts.get(p);
-		if( ctx == null )
-			return [];
-		var root = ctx.local3d;
-		var childObjs = getChildrenRoots(root, p, []);
-		var ret = [];
-		function rec(o : h3d.scene.Object) {
-			if( o.isMesh() ) {
-				var m = o.toMesh();
-				var multi = Std.instance(m, h3d.scene.MultiMaterial);
-				if( multi != null ) {
-					for( m in multi.materials )
-						if( m != null )
-							ret.push(m);
-				} else if( m.material != null )
-					ret.push(m.material);
-			}
-			for( child in o )
-				if( childObjs.indexOf(child) < 0 )
-					rec(child);
-		}
-		rec(root);
-		return ret;
-	}
-
-}

+ 0 - 77
hxd/prefab/Library.hx

@@ -1,77 +0,0 @@
-package hxd.prefab;
-
-class Library extends Prefab {
-
-	public function new() {
-		super(null);
-		type = "prefab";
-	}
-
-	override function load( obj : Dynamic ) {
-	}
-
-	override function save() {
-		return {};
-	}
-
-	/**
-		Returns the prefab within children that matches the given absolute path
-	**/
-	public function getFromPath( path : String ) : Prefab {
-		var parts = path.split(".");
-		var cur : Prefab = this;
-		for( p in parts ) {
-			var found = false;
-			for( c in cur.children )
-				if( c.name == p ) {
-					found = true;
-					cur = c;
-					break;
-				}
-			if( !found ) return null;
-		}
-		return cur;
-	}
-
-	static var registeredElements = new Map<String,{ cl : Class<Prefab> #if editor, inf : hide.prefab.HideProps #end }>();
-	static var registeredExtensions = new Map<String,String>();
-
-	public static function getRegistered() {
-		return registeredElements;
-	}
-
-	public static function isOfType( prefabKind : String, cl : Class<Prefab> ) {
-		var inf = registeredElements.get(prefabKind);
-		if( inf == null ) return false;
-		var c : Class<Dynamic> = inf.cl;
-		while( c != null ) {
-			if( c == cl ) return true;
-			c = Type.getSuperClass(c);
-		}
-		return false;
-	}
-
-	public static function register( type : String, cl : Class<Prefab>, ?extension : String ) {
-		registeredElements.set(type, { cl : cl #if editor, inf : Type.createEmptyInstance(cl).getHideProps() #end });
-		if( extension != null ) registeredExtensions.set(extension, type);
-		return true;
-	}
-
-	public static function create( extension : String ) {
-		var type = getPrefabType(extension);
-		var p : hxd.prefab.Prefab;
-		if( type == null )
-			p = new Library();
-		else
-			p = Type.createInstance(registeredElements.get(type).cl,[]);
-		return p;
-	}
-
-	public static function getPrefabType(path: String) {
-		var extension = path.split(".").pop().toLowerCase();
-		return registeredExtensions.get(extension);
-	}
-
-	static var _ = hxd.prefab.Library.register("prefab", Library, "prefab");
-
-}

+ 0 - 413
hxd/prefab/Prefab.hx

@@ -1,413 +0,0 @@
-package hxd.prefab;
-
-/**
-	Prefab is an data-oriented tree container capable of creating instances of Heaps objects.
-**/
-@:keepSub
-class Prefab {
-
-	/**
-		The type of prefab, allows to identify which class it should be loaded with.
-	**/
-	public var type(default, null) : String;
-
-	/**
-		The name of the prefab in the tree view
-	**/
-	public var name(default, set) : String;
-
-	/**
-		The parent of the prefab in the tree view
-	**/
-	public var parent(default, set) : Prefab;
-
-	/**
-		The associated source file (an image, a 3D model, etc.) if the prefab type needs it.
-	**/
-	public var source(default, set) : String;
-
-	/**
-		The list of children prefab in the tree view
-	**/
-	public var children(default, null) : Array<Prefab>;
-
-	/**
-		Tells if the prefab will create an instance when calling make() or be ignored. Also apply to this prefab children.
-	**/
-	public var enabled : Bool = true;
-
-
-	/**
-		A storage for some extra properties
-	**/
-	public var props : Any;
-
-	/**
-		Creates a new prefab with the given parent.
-	**/
-	public function new(?parent) {
-		this.parent = parent;
-		children = [];
-	}
-
-	function set_name(n) {
-		return name = n;
-	}
-
-	function set_source(f) {
-		return source = f;
-	}
-
-	function set_parent(p) {
-		if( parent != null )
-			parent.children.remove(this);
-		parent = p;
-		if( parent != null )
-			parent.children.push(this);
-		return p;
-	}
-
-	#if editor
-
-	/**
-		Allows to customize how the prefab object is edited within Hide
-	**/
-	public function edit( ctx : hide.prefab.EditContext ) {
-	}
-
-	/**
-		Allows to customize how the prefab object is displayed / handled within Hide
-	**/
-	public function getHideProps() : hide.prefab.HideProps {
-		return { icon : "question-circle", name : "Unknown" };
-	}
-
-	/**
-		Allows to customize how the prefab instance changes when selected/unselected within Hide
-	**/
-	public function setSelected( ctx : Context, b : Bool ) {
-		var materials = ctx.shared.getMaterials(this);
-
-		if( !b ) {
-			for( m in materials ) {
-				m.mainPass.stencil = null;
-				m.removePass(m.getPass("highlight"));
-			}
-			return;
-		}
-
-		var shader = new h3d.shader.FixedColor(0xffffff);
-		for( m in materials ) {
-			var p = m.allocPass("highlight");
-			p.culling = None;
-			p.depthWrite = false;
-			p.addShader(shader);
-		}
-	}
-	#end
-
-	/**
-		Iterate over children prefab
-	**/
-	public inline function iterator() : Iterator<Prefab> {
-		return children.iterator();
-	}
-
-	/**
-		Override to implement your custom prefab data loading
-	**/
-	function load( v : Dynamic ) {
-		throw "Not implemented";
-	}
-
-	/**
-		Override to implement your custom prefab data saving
-	**/
-	function save() : {} {
-		throw "Not implemented";
-		return null;
-	}
-
-	/**
-		Creates an instance for this prefab only (and not its children).
-		Use make(ctx) to creates the whole instances tree;
-	**/
-	public function makeInstance( ctx : Context ) : Context {
-		return ctx;
-	}
-
-	/**
-		Allows to customize how an instance gets updated when a property name changes.
-		You can also call updateInstance(ctx) in order to force whole instance synchronization against current prefab data.
-	**/
-	public function updateInstance( ctx : Context, ?propName : String ) {
-	}
-
-	/**
-		Removes the created instance for this prefab only (not is children).
-		If false is returned, the instance could not be removed and the whole context scene needs to be rebuilt
-	**/
-	public function removeInstance( ctx : Context ) : Bool {
-		return false;
-	}
-
-	/**
-		Save the whole prefab data and its children.
-	**/
-	@:final public function saveData() : {} {
-		var obj : Dynamic = save();
-		obj.type = type;
-		if( !enabled )
-			obj.enabled = false;
-		if( name != null )
-			obj.name = name;
-		if( source != null )
-			obj.source = source;
-		if( children.length > 0 )
-			obj.children = [for( s in children ) s.saveData()];
-		if( props != null && obj.props == null )
-			obj.props = props;
-		return obj;
-	}
-
-	/**
-		Load the whole prefab data and creates its children.
-	**/
-	@:final public function loadData( v : Dynamic ) {
-		type = v.type;
-		name = v.name;
-		enabled = v.enabled == null ? true : v.enabled;
-		props = v.props;
-		source = v.source;
-		load(v);
-		if( children.length > 0 )
-			children = [];
-		var children : Array<Dynamic> = v.children;
-		if( children != null )
-			for( v in children )
-				loadPrefab(v, this);
-	}
-
-	/**
-		Updates in-place the whole prefab data and its children.
-	**/
-	public function reload( p : Dynamic ) {
-		name = p.name;
-		enabled = p.enabled == null ? true : p.enabled;
-		props = p.props;
-		source = p.source;
-		load(p);
-		var childData : Array<Dynamic> = p.children;
-		if( childData == null ) {
-			if( this.children.length > 0 ) this.children = [];
-			return;
-		}
-		var curChild = new Map();
-		for( c in children )
-			curChild.set(c.name, c);
-		var newchild = [];
-		for( v in childData ) {
-			var name : String = v.name;
-			var prev = curChild.get(name);
-			if( prev != null && prev.type == v.type ) {
-				curChild.remove(name);
-				prev.reload(v);
-				newchild.push(prev);
-			} else {
-				newchild.push(loadPrefab(v,this));
-			}
-		}
-		children = newchild;
-	}
-
-	/**
-		Creates the correct prefab based on v.type and load its data and children.
-		If one the prefab in the tree is not registered, a hxd.prefab.Unkown is created instead.
-	**/
-	public static function loadPrefab( v : Dynamic, ?parent : Prefab ) {
-		var pcl = @:privateAccess Library.registeredElements.get(v.type);
-		var pcl = pcl == null ? null : pcl.cl;
-		if( pcl == null ) pcl = hxd.prefab.Unknown;
-		var p = Type.createInstance(pcl, [parent]);
-		p.loadData(v);
-		return p;
-	}
-
-	/**
-		Creates an instance for this prefab and its children.
-	**/
-	public function make( ctx : Context ) : Context {
-		if( !enabled )
-			return ctx;
-		if( ctx == null ) {
-			ctx = new Context();
-			ctx.init();
-		}
-		ctx = makeInstance(ctx);
-		for( c in children )
-			c.make(ctx);
-		return ctx;
-	}
-
-	#if castle
-	/**
-		Returns which CDB model this prefab props represents
-	**/
-	public function getCdbModel( ?p : Prefab ) : cdb.Sheet {
-		if( p == null )
-			p = this;
-		if( parent != null )
-			return parent.getCdbModel(p);
-		return null;
-	}
-	#end
-
-	/**
-		Search the prefab tree for the prefab matching the given name, returns null if not found
-	**/
-	public function getPrefabByName( name : String ) {
-		if( this.name == name )
-			return this;
-		for( c in children ) {
-			var p = c.getPrefabByName(name);
-			if( p != null )
-				return p;
-		}
-		return null;
-	}
-
-	/**
-		Simlar to get() but returns null if not found.
-	**/
-	public function getOpt<T:Prefab>( cl : Class<T>, ?name : String ) : T {
-		if( name == null || this.name == name ) {
-			var cval = to(cl);
-			if( cval != null ) return cval;
-		}
-		for( c in children ) {
-			var p = c.getOpt(cl, name);
-			if( p != null )
-				return p;
-		}
-		return null;
-	}
-
-	/**
-		Search the prefab tree for the prefab matching the given prefab class (and name, if specified).
-		Throw an exception if not found. Uses getOpt() to return null instead.
-	**/
-	public function get<T:Prefab>( cl : Class<T>, ?name : String ) : T {
-		var v = getOpt(cl, name);
-		if( v == null )
-			throw "Missing prefab " + (name == null ? Type.getClassName(cl) : (cl == null ? name : name+"(" + Type.getClassName(cl) + ")"));
-		return v;
-	}
-
-	/**
-		Return all prefabs in the tree matching the given prefab class.
-	**/
-	public function getAll<T:Prefab>( cl : Class<T>, ?arr: Array<T> ) : Array<T> {
-		return findAll(function(p) return p.to(cl));
-	}
-
-	/**
-		Find a single prefab in the tree by calling `f` on each and returning the first not-null value returned, or null if not found.
-	**/
-	public function find<T>( f : Prefab -> Null<T> ) : Null<T> {
-		var v = f(this);
-		if( v != null )
-			return v;
-		for( p in children ) {
-			var v = p.find(f);
-			if( v != null ) return v;
-		}
-		return null;
-	}
-
-	/**
-		Find several prefabs in the tree by calling `f` on each and returning all the not-null values returned.
-	**/
-	public function findAll<T>( f : Prefab -> Null<T>, ?arr : Array<T> ) : Array<T> {
-		if( arr == null ) arr = [];
-		var v = f(this);
-		if( v != null )
-			arr.push(v);
-		for( o in children )
-			o.findAll(f,arr);
-		return arr;
-	}
-
-	/**
-		Returns all prefabs in the tree matching the specified class.
-	**/
-	public function flatten<T:Prefab>( ?cl : Class<T>, ?arr: Array<T> ) : Array<T> {
-		if(arr == null)
-			arr = [];
-		if( cl == null )
-			arr.push(cast this);
-		else {
-			var i = to(cl);
-			if(i != null)
-				arr.push(i);
-		}
-		for(c in children)
-			c.flatten(cl, arr);
-		return arr;
-	}
-
-	/**
-		Returns the first parent in the tree matching the specified class or null if not found.
-	**/
-	public function getParent<T:Prefab>( c : Class<T> ) : Null<T> {
-		var p = parent;
-		while(p != null) {
-			var inst = p.to(c);
-			if(inst != null) return inst;
-			p = p.parent;
-		}
-		return null;
-	}
-
-	/**
-		Converts the prefab to another prefab class.
-		Returns null if not of this type.
-	**/
-	public function to<T:Prefab>( c : Class<T> ) : Null<T> {
-		return Std.instance(this, c);
-	}
-
-	/**
-		Returns the absolute name path for this prefab
-	**/
-	public function getAbsPath() {
-		var p = this;
-		var path = [];
-		while(p.parent != null) {
-			var n = p.name;
-			if( n == null ) n = getDefaultName();
-			path.unshift(n);
-			p = p.parent;
-		}
-		return path.join('.');
-	}
-
-	/**
-		Returns the default name for this prefab
-	**/
-	public function getDefaultName() : String {
-		if(source != null) {
-			var f = new haxe.io.Path(source).file;
-			f = f.split(" ")[0].split("-")[0];
-			return f;
-		}
-		return type.split(".").pop();
-	}
-
-	/**
-		Clone this prefab and all its children
-	**/
-	public function clone() : Prefab {
-		var obj = saveData();
-		return loadPrefab(haxe.Json.parse(haxe.Json.stringify(obj)));
-	}
-}

+ 0 - 26
hxd/prefab/Unknown.hx

@@ -1,26 +0,0 @@
-package hxd.prefab;
-
-class Unknown extends Prefab {
-
-	var data : Dynamic;
-
-	public function getPrefabType() {
-		return data.type;
-	}
-
-	override function load(v:Dynamic) {
-		this.data = v;
-	}
-
-	override function save() {
-		return data;
-	}
-
-	#if editor
-	override function edit(ctx:hide.prefab.EditContext) {
-		ctx.properties.add(new hide.Element('<font color="red">Unknown prefab $type</font>'));
-	}
-	#end
-
-
-}

+ 0 - 71
hxd/prefab/rfx/Bloom.hx

@@ -1,71 +0,0 @@
-package hxd.prefab.rfx;
-
-typedef BloomProps = {
-	var size : Float;
-	var threshold : Float;
-	var intensity : Float;
-	var blur : Float;
-	var saturation : Float;
-	var blurQuality : Float;
-	var blurLinear : Float;
-}
-
-class Bloom extends RendererFX {
-
-	var bloomPass = new h3d.pass.ScreenFx(new h3d.shader.pbr.Bloom());
-	var bloomBlur = new h3d.pass.Blur();
-
-	public function new(?parent) {
-		super(parent);
-		props = ({
-			size : 0.5,
-			blur : 3,
-			intensity : 1.,
-			threshold : 0.5,
-			saturation: 0,
-			blurQuality: 1.0,
-			blurLinear : 0.0,
-		} : BloomProps);
-	}
-
-	override function apply(r:h3d.scene.Renderer, step:hxd.prefab.rfx.RendererFX.Step) {
-		if( step == BeforeTonemapping ) {
-			var pb : BloomProps = props;
-			var bloom = r.allocTarget("bloom", false, pb.size, RGBA16F);
-			var ctx = r.ctx;
-			ctx.engine.pushTarget(bloom);
-			bloomPass.shader.hdr = ctx.getGlobal("hdr");
-			bloomPass.shader.threshold = pb.threshold;
-			bloomPass.shader.intensity = pb.intensity;
-			bloomPass.shader.colorMatrix.identity();
-			bloomPass.shader.colorMatrix.colorSaturate(pb.saturation);
-			bloomPass.render();
-			ctx.engine.popTarget();
-
-			bloomBlur.radius = pb.blur;
-			bloomBlur.quality = pb.blurQuality;
-			bloomBlur.linear = pb.blurLinear;
-			bloomBlur.apply(ctx, bloom);
-			ctx.setGlobal("bloom",bloom);
-		}
-	}
-
-	#if editor
-	override function edit( ctx : hide.prefab.EditContext ) {
-		ctx.properties.add(new hide.Element('
-			<dl>
-			<dt>Intensity</dt><dd><input type="range" min="0" max="2" field="intensity"/></dd>
-			<dt>Threshold</dt><dd><input type="range" min="0" max="1" field="threshold"/></dd>
-			<dt>Size</dt><dd><input type="range" min="0" max="1" field="size"/></dd>
-			<dt>Blur</dt><dd><input type="range" min="0" max="20" field="blur"/></dd>
-			<dt>Saturation</dt><dd><input type="range" min="-1" max="1" field="saturation"/></dd>
-			<dt>Blur Quality</dt><dd><input type="range" min="0" max="1" field="blurQuality"/></dd>
-			<dt>Blur Linear</dt><dd><input type="range" min="0" max="1" field="blurLinear"/></dd>
-			</dl>
-		'),props);
-	}
-	#end
-
-	static var _ = Library.register("rfx.bloom", Bloom);
-
-}

+ 0 - 82
hxd/prefab/rfx/DistanceFog.hx

@@ -1,82 +0,0 @@
-package hxd.prefab.rfx;
-
-typedef DistanceFogProps = {
- 	var startDistance : Float;
-	var endDistance : Float;
-	var startOpacity : Float;
-	var endOpacity : Float;
-
-	var startColor : Int;
-	var endColor : Int;
-	var startColorDistance : Float;
-	var endColorDistance : Float;
-}
-
-class DistanceFog extends RendererFX {
-
-	var fogPass = new h3d.pass.ScreenFx(new h3d.shader.DistanceFog());
-
-	public function new(?parent) {
-		super(parent);
-		props = ({
-			startDistance : 0,
-			endDistance : 100,
-			startOpacity : 0,
-			endOpacity : 1,
-		 	startColor : 0xffffff,
-	    	endColor : 0xffffff,
-			startColorDistance : 0,
-			endColorDistance : 100,
-		} : DistanceFogProps);
-
-		fogPass.pass.setBlendMode(Alpha);
-	}
-
-	override function apply(r:h3d.scene.Renderer, step:hxd.prefab.rfx.RendererFX.Step) {
-		if( step == BeforeTonemapping ) {
-			var p : DistanceFogProps = props;
-			var ctx = r.ctx;
-			var depth : hxsl.ChannelTexture = ctx.getGlobal("depthMap");
-
-			fogPass.shader.startDistance = p.startDistance;
-			fogPass.shader.endDistance = p.endDistance;
-			fogPass.shader.startOpacity = p.startOpacity;
-			fogPass.shader.endOpacity = p.endOpacity;
-			fogPass.shader.startColorDistance = p.startColorDistance;
-			fogPass.shader.endColorDistance = p.endColorDistance;
-			fogPass.shader.startColor = h3d.Vector.fromColor(p.startColor);
-			fogPass.shader.endColor = h3d.Vector.fromColor(p.endColor);
-			fogPass.shader.depthTextureChannel = depth.channel;
-			fogPass.shader.depthTexture = depth.texture;
-
-			fogPass.shader.cameraPos = ctx.camera.pos;
-			fogPass.shader.cameraInverseViewProj.load(ctx.camera.getInverseViewProj());
-
-			fogPass.render();
-		}
-	}
-
-	#if editor
-	override function edit( ctx : hide.prefab.EditContext ) {
-		ctx.properties.add(new hide.Element('
-			<dl>
-				<div class="group" name="Opacity">
-					<dt>Start Distance</dt><dd><input type="range" min="0" max="100" field="startDistance"/></dd>
-					<dt>End Distance</dt><dd><input type="range" min="0" max="100" field="endDistance"/></dd>
-					<dt>Start Opacity</dt><dd><input type="range" min="0" max="1" field="startOpacity"/></dd>
-					<dt>End Opacity</dt><dd><input type="range" min="0" max="1" field="endOpacity"/></dd>
-				</div>
-				<div class="group" name="Color">
-					<dt>Start Distance</dt><dd><input type="range" min="0" max="100" field="startColorDistance"/></dd>
-					<dt>End Distance</dt><dd><input type="range" min="0" max="100" field="endColorDistance"/></dd>
-					<dt>Start Color</dt><dd><input type="color" field="startColor"/></dd>
-					<dt>End Color</dt><dd><input type="color" field="endColor"/></dd>
-				</div>
-			</dl>
-		'),props);
-	}
-	#end
-
-	static var _ = Library.register("rfx.distanceFog", DistanceFog);
-
-}

+ 0 - 31
hxd/prefab/rfx/RendererFX.hx

@@ -1,31 +0,0 @@
-package hxd.prefab.rfx;
-
-enum Step {
-	BeforeLighting;
-	BeforeTonemapping;
-	AfterTonemapping;
-	AfterUI;
-}
-
-class RendererFX extends Prefab {
-
-	public function apply( r : h3d.scene.Renderer, step : Step ) {
-	}
-
-	override function save() {
-		return {};
-	}
-
-	override function load(v:Dynamic) {
-	}
-
-	public function dispose() {
-	}
-
-	#if editor
-	override function getHideProps() : hide.prefab.HideProps {
-		return { name : Type.getClassName(Type.getClass(this)).split(".").pop(), icon : "plus-circle" };
-	}
-	#end
-
-}

+ 0 - 86
hxd/prefab/rfx/Sao.hx

@@ -1,86 +0,0 @@
-package hxd.prefab.rfx;
-
-typedef SaoProps = {
-	var size : Float;
-	var blur : Float;
-	var samples : Int;
-	var radius : Float;
-	var intensity : Float;
-	var bias : Float;
-	var microIntensity : Float;
-	var useWorldUV : Bool;
-}
-
-class Sao extends RendererFX {
-
-	var sao : h3d.pass.ScalableAO;
-	var saoBlur = new h3d.pass.Blur();
-	var saoCopy = new h3d.pass.Copy();
-
-	public function new(?parent) {
-		super(parent);
-		props = ({
-			size : 1,
-			blur : 5,
-			samples : 30,
-			radius : 1,
-			intensity : 1,
-			bias : 0.1,
-			microIntensity : 1.0,
-			useWorldUV : false,
-		} : SaoProps);
-	}
-
-	override function apply( r : h3d.scene.Renderer, step : RendererFX.Step ) {
-		if( step == BeforeLighting ) {
-			if( sao == null ) sao = new h3d.pass.ScalableAO();
-			var props : SaoProps = props;
-			var ctx = r.ctx;
-			var saoTex = r.allocTarget("sao",false, props.size);
-			var microOcclusion = r.allocTarget("sao",false, props.size);
-			var normal : hxsl.ChannelTexture = ctx.getGlobal("normalMap");
-			var depth : hxsl.ChannelTexture = ctx.getGlobal("depthMap");
-			var occlu : hxsl.ChannelTexture = ctx.getGlobal("occlusionMap");
-			ctx.engine.pushTarget(saoTex);
-			sao.shader.numSamples = props.samples;
-			sao.shader.sampleRadius	= props.radius;
-			sao.shader.intensity = props.intensity;
-			sao.shader.bias = props.bias * props.bias;
-			sao.shader.depthTextureChannel = depth.channel;
-			sao.shader.normalTextureChannel = normal.channel;
-			sao.shader.useWorldUV = props.useWorldUV;
-			sao.shader.microOcclusion = occlu.texture;
-			sao.shader.microOcclusionChannel = occlu.channel;
-			sao.shader.microOcclusionIntensity = props.microIntensity;
-			sao.apply(depth.texture,normal.texture,ctx.camera);
-			ctx.engine.popTarget();
-
-			saoBlur.radius = props.blur;
-			saoBlur.quality = 0.5;
-			saoBlur.apply(ctx, saoTex);
-
-			saoCopy.pass.setColorChannel(occlu.channel);
-			saoCopy.apply(saoTex, occlu.texture);
-		}
-	}
-
-	#if editor
-	override function edit( ctx : hide.prefab.EditContext ) {
-		ctx.properties.add(new hide.Element('
-			<dl>
-			<dt>Intensity</dt><dd><input type="range" min="0" max="10" field="intensity"/></dd>
-			<dt>Radius</dt><dd><input type="range" min="0" max="10" field="radius"/></dd>
-			<dt>Bias</dt><dd><input type="range" min="0" max="0.5" field="bias"/></dd>
-			<dt>Size</dt><dd><input type="range" min="0" max="1" field="size"/></dd>
-			<dt>Blur</dt><dd><input type="range" min="0" max="20" field="blur"/></dd>
-			<dt>Samples</dt><dd><input type="range" min="3" max="256" field="samples" step="1"/></dd>
-			<dt>Micro Intensity</dt><dd><input type="range" min="0" max="1" field="microIntensity"/></dd>
-			<dt>Use World UV</dt><dd><input type="checkbox" field="useWorldUV"/></dd>
-			</dl>
-		'),props);
-	}
-	#end
-
-	static var _ = Library.register("rfx.sao", Sao);
-
-}

+ 13 - 3
hxd/res/Prefab.hx

@@ -2,16 +2,26 @@ package hxd.res;
 
 class Prefab extends hxd.res.Resource {
 
-	var lib : hxd.prefab.Prefab;
+	#if !hide
 
-	public function load() : hxd.prefab.Prefab {
+	public function load() : Dynamic {
+		throw "Prefab requires -lib hide";
+	}
+
+	#else
+
+	var lib : hrt.prefab.Prefab;
+
+	public function load() : hrt.prefab.Prefab {
 		if( lib != null )
 			return lib;
 		var data = haxe.Json.parse(entry.getText());
-		lib = hxd.prefab.Library.create(entry.extension);
+		lib = hrt.prefab.Library.create(entry.extension);
 		lib.loadData(data);
 		watch(function() lib.reload(haxe.Json.parse(entry.getText())));
 		return lib;
 	}
 
+	#end
+
 }

+ 7 - 7
samples/FxView.hx

@@ -1,5 +1,5 @@
-import hide.prefab.fx.FX;
-import hide.prefab.l3d.Polygon;
+import hrt.prefab.fx.FX;
+import hrt.prefab.l3d.Polygon;
 
 class ColorMult extends hxsl.Shader {
 	static var SRC = {
@@ -19,20 +19,20 @@ class FxView extends hxd.App {
 
 	override function init() {
 		var prefab = hxd.Res.hideEffect.load();
-		var unk = prefab.getOpt(hxd.prefab.Unknown);
+		var unk = prefab.getOpt(hrt.prefab.Unknown);
 		if( unk != null )
 			throw "Prefab "+unk.getPrefabType()+" was not compiled";
 
-		var ctx = new hxd.prefab.Context();
-		var shared = new hxd.prefab.ContextShared();
+		var ctx = new hrt.prefab.Context();
+		var shared = new hrt.prefab.ContextShared();
 		ctx.shared = shared;
 		shared.root2d = s2d;
 		shared.root3d = s3d;
 		ctx.init();
 
 		function play() {
-			var i = prefab.makeInstance(ctx);
-			var fx = cast(i.local3d, hide.prefab.fx.FX.FXAnimation);
+			var i = prefab.make(ctx);
+			var fx = cast(i.local3d, hrt.prefab.fx.FX.FXAnimation);
 			fx.onEnd = function() {
 				fx.remove();
 				play();