ncannasse 7 năm trước cách đây
mục cha
commit
80a4193f3d
4 tập tin đã thay đổi với 83 bổ sung22 xóa
  1. 1 0
      hide.hxml
  2. 1 1
      hide/comp/Scene.hx
  3. 59 1
      hide/tools/Interp.hx
  4. 22 20
      hide/tools/MaterialScript.hx

+ 1 - 0
hide.hxml

@@ -9,3 +9,4 @@
 -D hscriptPos
 -D old-error-format
 -dce no
+-debug

+ 1 - 1
hide/comp/Scene.hx

@@ -1,7 +1,7 @@
 package hide.comp;
 
 @:access(hide.comp.Scene)
-class SceneLoader extends h3d.impl.Serializable.SceneSerializer {
+class SceneLoader extends hxd.fmt.hsd.Serializer {
 
 	var ide : hide.ui.Ide;
 	var hsdPath : String;

+ 59 - 1
hide/tools/Interp.hx

@@ -1,5 +1,8 @@
 package hide.tools;
 
+// make sure these classes are compiled
+import h3d.anim.SmoothTarget;
+
 class Interp extends hscript.Interp {
 
 	var ide : hide.ui.Ide;
@@ -7,6 +10,10 @@ class Interp extends hscript.Interp {
 	public function new() {
 		ide = hide.ui.Ide.inst;
 		super();
+		// share some classes
+		variables.set("hxd", { Res : new ResourceLoader([]) });
+		variables.set("h3d", { mat : { Texture : h3d.mat.Texture } });
+		variables.set("haxe", { Json : haxe.Json });
 	}
 
 	public function shareEnum( e : Enum<Dynamic> ) {
@@ -36,6 +43,16 @@ class Interp extends hscript.Interp {
 		return super.get(o, f);
 	}
 
+	override function fcall(o:Dynamic, f:String, args:Array<Dynamic>):Dynamic {
+		var fun = get(o, f);
+		if( !Reflect.isFunction(fun) ) {
+			if( fun == null )
+				throw o + " has no function " + f;
+			throw o + "." + f + " is not a function";
+		}
+		return call(o, fun, args);
+	}
+
 	override function cnew(cl:String, args:Array<Dynamic>):Dynamic {
 		var c = Type.resolveClass(cl);
 		if( c == null )
@@ -52,4 +69,45 @@ class Interp extends hscript.Interp {
 		return Type.createInstance(c,args);
 	}
 
-}
+}
+
+class ResourceLoader {
+
+	var __path : Array<String>;
+
+	public function new(p) {
+		__path = p;
+	}
+
+	public function toTexture() {
+		return hide.comp.Scene.getCurrent().loadTextureDotPath(__path.join("."));
+	}
+
+	function resolvePath() {
+		var ide = hide.ui.Ide.inst;
+		var dir = __path.copy();
+		var name = dir.pop();
+		var dir = dir.join("/");
+		for( f in sys.FileSystem.readDirectory(ide.getPath(dir)) )
+			if( f.substr(0, f.lastIndexOf(".")) == name )
+				return dir + "/" + f;
+		return null;
+	}
+
+	public function hscriptGet( field : String ) : Dynamic {
+
+		var f = Reflect.field(this,field);
+		if( f != null )
+			return Reflect.makeVarArgs(function(args) return Reflect.callMethod(this, f, args));
+
+		if( field == "entry" ) {
+			var path = resolvePath();
+			return hxd.res.Loader.currentInstance.load(path).entry;
+		}
+
+		var p = __path.copy();
+		p.push(field);
+		return new ResourceLoader(p);
+	}
+
+}

+ 22 - 20
hide/tools/MaterialScript.hx

@@ -25,27 +25,25 @@ class RendererScript extends h3d.scene.Renderer {
 
 }
 
-class ResourceLoader {
+class Properties extends hxd.impl.Properties {
 
-	var __path : Array<String>;
+	public var obj : Dynamic;
+	var interp : Interp;
 
-	public function new(p) {
-		__path = p;
+	public function new(interp) {
+		this.interp = interp;
 	}
 
-	public function toTexture() {
-		return hide.comp.Scene.getCurrent().loadTextureDotPath(__path.join("."));
+	override function getField( o : Dynamic, f : String ) {
+		if( o == obj && interp.variables.exists(f) )
+			return interp.variables.get(f);
+		return @:privateAccess interp.get(o, f);
 	}
 
-	public function hscriptGet( field : String ) {
-
-		var f = Reflect.field(this,field);
-		if( f != null )
-			return Reflect.makeVarArgs(function(args) return Reflect.callMethod(this, f, args));
-
-		var p = __path.copy();
-		p.push(field);
-		return new ResourceLoader(p);
+	override function setField( o : Dynamic, f : String, v : Dynamic ) {
+		if( o == obj )
+			throw "TODO";
+		@:privateAccess interp.set(o, f, v);
 	}
 
 }
@@ -90,23 +88,26 @@ class MaterialScript extends h3d.mat.MaterialScript {
 
 	function makeClass( c : hscript.Expr.ClassDecl, ?args : Array<Dynamic> ) {
 		var interp = new Interp();
-		var obj = null;
+		var makeObj = null;
 		if( c.extend != null )
 			switch( c.extend ) {
 			case CTPath(["h3d", "scene", "Renderer"], _):
-				obj = function() return new RendererScript(interp.variables.get("render"));
+				makeObj = function() return new RendererScript(interp.variables.get("render"));
 				interp.shareEnum(hxsl.Output);
 				interp.shareEnum(h3d.impl.Driver.Feature);
 				interp.shareEnum(h3d.mat.Data.Wrap);
 				interp.shareEnum(h3d.mat.BlendMode);
 			default:
 			}
-		if( obj == null )
+		if( makeObj == null )
 			throw "Don't know what to do with " + c.name;
 
 		interp.variables.set("loadShader", function(name) return ide.shaderLoader.load(name));
 		interp.variables.set("lookupShader", lookupShader);
-		interp.variables.set("hxd", { Res : new ResourceLoader([]) });
+		interp.variables.set("getS3D", function() return hide.comp.Scene.getCurrent().s3d);
+
+		var props = new Properties(interp);
+		interp.variables.set("applyProperties", props.apply);
 
 		for( f in c.fields )
 			switch( f.kind ) {
@@ -121,7 +122,8 @@ class MaterialScript extends h3d.mat.MaterialScript {
 
 
 		// share functions
-		var obj = obj();
+		var obj = makeObj();
+		props.obj = obj;
 		interp.shareObject(obj);
 		interp.variables.set("super", obj);
 		interp.variables.set("this", obj);