瀏覽代碼

a bit of cleanup, still not fully ported to JS

ncannasse 12 年之前
父節點
當前提交
ca96f9fe9d
共有 10 個文件被更改,包括 38 次插入9 次删除
  1. 4 2
      engine.hxml
  2. 1 1
      engine.hxproj
  3. 1 1
      h2d/comp/Context.hx
  4. 11 3
      h3d/mat/PartMaterial.hx
  5. 3 1
      h3d/scene/Particles.hx
  6. 12 0
      hxd/res/Embed.hx
  7. 4 0
      hxd/res/EmbedFileSystem.hx
  8. 2 1
      samples/basic/Test.hx
  9. 二進制
      samples/basic/texture.png
  10. 0 0
      samples/res/hxlogo.png

+ 4 - 2
engine.hxml

@@ -3,16 +3,18 @@
 -main Test
 --macro include('h3d')
 --macro include('h2d')
---macro include('hxd')
+--macro include('hxd',true,['hxd.res.FileTree'])
 -lib format
+-D resourcesPath=samples/res
 --next
 -swf engine.swf
 -swf-header 800:600:60:000000
 -swf-version 11.6
 -lib hxsl
 -D h3d
+-D resourcesPath=samples/res
 -cp samples/basic
 -main Test
 --macro include('h3d')
 --macro include('h2d')
---macro include('hxd')
+--macro include('hxd',true,['hxd.res.FileTree'])

+ 1 - 1
engine.hxproj

@@ -23,7 +23,7 @@
     <option flashStrict="True" />
     <option mainClass="Test" />
     <option enabledebug="False" />
-    <option additional="--macro include('h3d')&#xA;--macro include('h2d')&#xA;--macro include('hxd')&#xA;-lib format&#xA;&#xA;--next&#xA;&#xA;-swf engine.swf&#xA;-swf-header 800:600:60:000000&#xA;-swf-version 11.6&#xA;-lib hxsl&#xA;-D h3d&#xA;-cp samples/basic&#xA;-main Test&#xA;--macro include('h3d')&#xA;--macro include('h2d')&#xA;--macro include('hxd')" />
+    <option additional="--macro include('h3d')&#xA;--macro include('h2d')&#xA;--macro include('hxd',true,['hxd.res.FileTree'])&#xA;-lib format&#xA;-D resourcesPath=samples/res&#xA;&#xA;--next&#xA;&#xA;-swf engine.swf&#xA;-swf-header 800:600:60:000000&#xA;-swf-version 11.6&#xA;-lib hxsl&#xA;-D h3d&#xA;-D resourcesPath=samples/res&#xA;-cp samples/basic&#xA;-main Test&#xA;--macro include('h3d')&#xA;--macro include('h2d')&#xA;--macro include('hxd',true,['hxd.res.FileTree'])" />
   </build>
   <!-- haxelib libraries -->
   <haxelib>

+ 1 - 1
h2d/comp/Context.hx

@@ -36,7 +36,7 @@ class Context {
 
 	static var FONTS = new Map<String,h2d.Font>();
 	
-	public static var DEFAULT_CSS = hxd.Resource.getFileContent("h2d/css/default.css");
+	public static var DEFAULT_CSS = hxd.res.Embed.getFileContent("h2d/css/default.css");
 	
 	static var DEF = null;
 	public static function getDefaultCss() {

+ 11 - 3
h3d/mat/PartMaterial.hx

@@ -55,6 +55,11 @@ private class PartShader extends h3d.impl.Shader {
 	
 	}
 
+#else
+
+	static var VERTEX = "TODO";
+	static var FRAGMENT = "TODO";
+	
 #end
 
 }
@@ -91,10 +96,13 @@ class PartMaterial extends Material {
 		return m;
 	}
 
-	function setup( mpos, mproj, sizeX : Float, sizeY : Float, frameCount : Int, hasRotation, hasSize ) {
-		pshader.mpos = mpos;
-		pshader.mproj = mproj;
+	override function setup( ctx : h3d.scene.RenderContext ) {
+		pshader.mpos = ctx.localPos;
+		pshader.mproj = ctx.camera.m;
 		pshader.tex = texture;
+	}
+	
+	public function init( sizeX : Float, sizeY : Float, frameCount : Int, hasRotation, hasSize ) {
 		pshader.hasRotation = hasRotation;
 		pshader.hasSize = hasSize;
 		pshader.partSize.x = sizeX;

+ 3 - 1
h3d/scene/Particles.hx

@@ -146,7 +146,9 @@ class Particles extends Object {
 		var buffer = ctx.engine.mem.alloc(nverts, stride, 4);
 		buffer.uploadVector(tmpBuf, 0, nverts);
 		var size = partSize;
-		material.setup(this.absPos, ctx.camera.m, size, size * ctx.engine.width / ctx.engine.height, frameCount, hasRotation, hasSize);
+		ctx.localPos = this.absPos;
+		material.setup(ctx);
+		material.init(size, size * ctx.engine.width / ctx.engine.height, frameCount, hasRotation, hasSize);
 		ctx.engine.selectMaterial(material);
 		ctx.engine.renderQuadBuffer(buffer);
 		buffer.dispose();

+ 12 - 0
hxd/res/Embed.hx

@@ -0,0 +1,12 @@
+package hxd.res;
+
+class Embed {
+	
+	public static macro function getFileContent( file : String ) {
+		var file = haxe.macro.Context.resolvePath(file);
+		var m = haxe.macro.Context.getLocalClass().get().module;
+		haxe.macro.Context.registerModuleDependency(m, file);
+		return macro $v{sys.io.File.getContent(file)};
+	}
+	
+}

+ 4 - 0
hxd/res/EmbedFileSystem.hx

@@ -213,6 +213,10 @@ class EmbedFileSystem #if !macro implements FileSystem #end {
 	
 	#end
 	
+	public static macro function init() {
+		return macro hxd.Res.loader = new hxd.res.Loader(hxd.res.EmbedFileSystem.create());
+	}
+	
 	public static macro function create( ?basePath : String, ?options : EmbedOptions ) {
 		var f = new FileTree(basePath);
 		var data = f.embed(options);

+ 2 - 1
samples/basic/Test.hx

@@ -24,7 +24,7 @@ class Test {
 		prim.addUVs();
 		prim.addNormals();
 		
-		var tex = hxd.Resource.embed("texture.png").toTexture();
+		var tex = hxd.Res.hxlogo.toTexture();
 		var mat = new h3d.mat.MeshMaterial(tex);
 		
 		scene = new Scene();
@@ -53,6 +53,7 @@ class Test {
 		#if flash
 		haxe.Log.setColor(0xFF0000);
 		#end
+		hxd.res.EmbedFileSystem.init();
 		new Test();
 	}
 	

二進制
samples/basic/texture.png


+ 0 - 0
samples/2d/texture.png → samples/res/hxlogo.png