Bladeren bron

CoreObject -> Drawable

Nicolas Cannasse 12 jaren geleden
bovenliggende
commit
cc270bade2

+ 1 - 0
.gitignore

@@ -2,3 +2,4 @@
 /engine.swf
 /engine.swf
 /samples/*.swf
 /samples/*.swf
 *.n
 *.n
+*.swf

+ 1 - 1
engine.hxproj

@@ -15,7 +15,7 @@
   </output>
   </output>
   <!-- Other classes to be compiled into your SWF -->
   <!-- Other classes to be compiled into your SWF -->
   <classpaths>
   <classpaths>
-    <class path="samples" />
+    <class path="samples\basic" />
   </classpaths>
   </classpaths>
   <!-- Build options -->
   <!-- Build options -->
   <build>
   <build>

+ 1 - 1
h2d/Scene.hx

@@ -1,6 +1,6 @@
 package h2d;
 package h2d;
 
 
-class Scene extends Layers {
+class Scene extends Layers, implements h3d.IDrawable {
 
 
 	public var width(default,null) : Int;
 	public var width(default,null) : Int;
 	public var height(default, null) : Int;
 	public var height(default, null) : Int;

+ 8 - 8
h2d/Tools.hx

@@ -109,10 +109,10 @@ private class CoreObjects  {
 	public var tmpUVScale : h3d.Vector;
 	public var tmpUVScale : h3d.Vector;
 	public var tmpColor : h3d.Vector;
 	public var tmpColor : h3d.Vector;
 	public var tmpMatrix : h3d.Matrix;
 	public var tmpMatrix : h3d.Matrix;
-	public var bitmapObj : h3d.CoreObject<BitmapShader>;
-	public var cachedBitmapObj : h3d.CoreObject<CachedBitmapShader>;
-	public var tileObj : h3d.CoreObject<TileShader>;
-	public var tileColorObj : h3d.CoreObject<TileColorShader>;
+	public var bitmapObj : h3d.Drawable<BitmapShader>;
+	public var cachedBitmapObj : h3d.Drawable<CachedBitmapShader>;
+	public var tileObj : h3d.Drawable<TileShader>;
+	public var tileColorObj : h3d.Drawable<TileColorShader>;
 	var emptyTexture : h3d.mat.Texture;
 	var emptyTexture : h3d.mat.Texture;
 	
 	
 	public function new() {
 	public function new() {
@@ -131,21 +131,21 @@ private class CoreObjects  {
 			new h3d.Point(1, 1),
 			new h3d.Point(1, 1),
 		]);
 		]);
 		
 		
-		var b = new h3d.CoreObject(plan, new BitmapShader());
+		var b = new h3d.Drawable(plan, new BitmapShader());
 		b.material.culling = None;
 		b.material.culling = None;
 		b.material.depth(false, Always);
 		b.material.depth(false, Always);
 		bitmapObj = b;
 		bitmapObj = b;
 		
 		
-		var b = new h3d.CoreObject(plan, new CachedBitmapShader());
+		var b = new h3d.Drawable(plan, new CachedBitmapShader());
 		b.material.culling = None;
 		b.material.culling = None;
 		b.material.depth(false, Always);
 		b.material.depth(false, Always);
 		cachedBitmapObj = b;
 		cachedBitmapObj = b;
 		
 		
-		tileObj = new h3d.CoreObject(null, new TileShader());
+		tileObj = new h3d.Drawable(null, new TileShader());
 		tileObj.material.depth(false, Always);
 		tileObj.material.depth(false, Always);
 		tileObj.material.culling = None;
 		tileObj.material.culling = None;
 		
 		
-		tileColorObj = new h3d.CoreObject(null,new TileColorShader());
+		tileColorObj = new h3d.Drawable(null,new TileColorShader());
 		tileColorObj.material.depth(false, Always);
 		tileColorObj.material.depth(false, Always);
 		tileColorObj.material.culling = None;
 		tileColorObj.material.culling = None;
 	}
 	}

+ 1 - 1
h3d/CoreObject.hx → h3d/Drawable.hx

@@ -4,7 +4,7 @@ package h3d;
 	A core object is a rendering context but completely outside of the 3d scene.
 	A core object is a rendering context but completely outside of the 3d scene.
 	It is meant to be able to share a rendering context between several similar physical objects.
 	It is meant to be able to share a rendering context between several similar physical objects.
  **/
  **/
-class CoreObject<S:hxsl.Shader> {
+class Drawable<S:hxsl.Shader> implements IDrawable {
 
 
 	public var shader : S;
 	public var shader : S;
 	public var primitive : h3d.prim.Primitive;
 	public var primitive : h3d.prim.Primitive;

+ 5 - 5
h3d/Engine.hx

@@ -28,8 +28,8 @@ class Engine {
 	var antiAlias : Int;
 	var antiAlias : Int;
 	var inTarget : Bool;
 	var inTarget : Bool;
 
 
-	var debugPoint : h3d.CoreObject<h3d.impl.Shaders.PointShader>;
-	var debugLine : h3d.CoreObject<h3d.impl.Shaders.LineShader>;
+	var debugPoint : h3d.Drawable<h3d.impl.Shaders.PointShader>;
+	var debugLine : h3d.Drawable<h3d.impl.Shaders.LineShader>;
 	
 	
 	@:allow(h3d)
 	@:allow(h3d)
 	var curProjMatrix : h3d.Matrix;
 	var curProjMatrix : h3d.Matrix;
@@ -104,7 +104,7 @@ class Engine {
 				ctx.setTextureAt(curTextures.length, null);
 				ctx.setTextureAt(curTextures.length, null);
 			}
 			}
 			// force remapping of vertex buffer
 			// force remapping of vertex buffer
-			if( curShader == null || s.bufferFormat != curShader.bufferFormat /*|| s.stride != curShader.stride*/ )
+			if( curShader == null || s.bufferFormat != curShader.bufferFormat || s.stride != curShader.stride )
 				curBuffer = null;
 				curBuffer = null;
 			curShader = s;
 			curShader = s;
 		}
 		}
@@ -340,7 +340,7 @@ class Engine {
 		if( curProjMatrix == null )
 		if( curProjMatrix == null )
 			return;
 			return;
 		if( debugPoint == null ) {
 		if( debugPoint == null ) {
-			debugPoint = new h3d.CoreObject(new h3d.prim.Plan2D(), new h3d.impl.Shaders.PointShader());
+			debugPoint = new Drawable(new h3d.prim.Plan2D(), new h3d.impl.Shaders.PointShader());
 			debugPoint.material.blend(SrcAlpha, OneMinusSrcAlpha);
 			debugPoint.material.blend(SrcAlpha, OneMinusSrcAlpha);
 			debugPoint.material.depthWrite = false;
 			debugPoint.material.depthWrite = false;
 		}
 		}
@@ -357,7 +357,7 @@ class Engine {
 		if( curProjMatrix == null )
 		if( curProjMatrix == null )
 			return;
 			return;
 		if( debugLine == null ) {
 		if( debugLine == null ) {
-			debugLine = new h3d.CoreObject(new h3d.prim.Plan2D(), new h3d.impl.Shaders.LineShader());
+			debugLine = new Drawable(new h3d.prim.Plan2D(), new h3d.impl.Shaders.LineShader());
 			debugLine.material.blend(SrcAlpha, OneMinusSrcAlpha);
 			debugLine.material.blend(SrcAlpha, OneMinusSrcAlpha);
 			debugLine.material.depthWrite = false;
 			debugLine.material.depthWrite = false;
 			debugLine.material.culling = None;
 			debugLine.material.culling = None;

+ 5 - 0
h3d/IDrawable.hx

@@ -0,0 +1,5 @@
+package h3d;
+
+interface IDrawable {
+	public function render( engine : Engine ) : Void;
+}

+ 1 - 1
h3d/fx/Bitmap.hx

@@ -20,7 +20,7 @@ private class BitmapShader extends hxsl.Shader {
 
 
 }
 }
 
 
-class Bitmap extends h3d.CoreObject<BitmapShader> {
+class Bitmap extends h3d.Drawable<BitmapShader> {
 
 
 	public var bmp(default,null) : h3d.mat.Bitmap;
 	public var bmp(default,null) : h3d.mat.Bitmap;
 	
 	

+ 2 - 2
h3d/fx/Skybox.hx

@@ -17,14 +17,14 @@ class Skybox extends hxsl.Shader {
 		}
 		}
 	};
 	};
 
 
-	var obj : h3d.CoreObject<Skybox>;
+	var obj : h3d.Drawable<Skybox>;
 	
 	
 	public function new(tex) {
 	public function new(tex) {
 		super();
 		super();
 		this.texture = tex;
 		this.texture = tex;
 		var prim = new h3d.prim.Cube(2, 2, 2);
 		var prim = new h3d.prim.Cube(2, 2, 2);
         prim.translate( -1, -1, -1);
         prim.translate( -1, -1, -1);
-		obj = new h3d.CoreObject(prim, this);
+		obj = new h3d.Drawable(prim, this);
 		obj.material.depth(false, Compare.Always);
 		obj.material.depth(false, Compare.Always);
 		obj.material.culling = Face.Front;
 		obj.material.culling = Face.Front;
 	}
 	}

+ 3 - 3
h3d/prim/Skin.hx

@@ -73,11 +73,11 @@ class Animation {
 		}
 		}
 	}
 	}
 	
 	
-	public function updateJoints( frame : Int, palette : Array<h3d.Matrix> ) {
+	public function updateJoints( frame : Int, palette : Table<h3d.Matrix> ) {
 		frame %= frameCount;
 		frame %= frameCount;
 		for( c in curves ) {
 		for( c in curves ) {
+			if( c.joint.bindId < 0 ) continue;
 			var m = palette[c.joint.bindId];
 			var m = palette[c.joint.bindId];
-			if( m == null ) continue;
 			m.loadFrom(c.joint.transPos);
 			m.loadFrom(c.joint.transPos);
 			var mf = c.frames[frame];
 			var mf = c.frames[frame];
 			if( mf != null ) m.multiply3x4(m, mf);
 			if( mf != null ) m.multiply3x4(m, mf);
@@ -89,7 +89,7 @@ class Animation {
 		for( c in curves )
 		for( c in curves )
 			if( c.joint.bindId >= max )
 			if( c.joint.bindId >= max )
 				max = c.joint.bindId;
 				max = c.joint.bindId;
-		var a = [];
+		var a = new Table();
 		for( i in 0...max + 1 )
 		for( i in 0...max + 1 )
 			a.push(new h3d.Matrix());
 			a.push(new h3d.Matrix());
 		return a;
 		return a;

+ 1 - 1
h3d/scene/Scene.hx

@@ -1,6 +1,6 @@
 package h3d.scene;
 package h3d.scene;
 
 
-class Scene extends Layers {
+class Scene extends Layers, implements h3d.IDrawable {
 
 
 	public var camera : h3d.Camera;
 	public var camera : h3d.Camera;
 	var extraPasses : Array<{ function render( engine : h3d.Engine ) : Void; }>;
 	var extraPasses : Array<{ function render( engine : h3d.Engine ) : Void; }>;

+ 0 - 0
samples/Test.hx → samples/basic/Test.hx


+ 42 - 32
samples/Anim.hx → samples/fbx/Anim.hx

@@ -9,7 +9,20 @@ class Model extends flash.utils.ByteArray {
 	
 	
 }
 }
 
 
-class LightShader extends h3d.Shader {
+class Axis implements h3d.IDrawable {
+
+	public function new() {
+	}
+	
+	public function render( engine : h3d.Engine ) {
+		engine.line(0, 0, 0, 50, 0, 0, 0xFFFF0000);
+		engine.line(0, 0, 0, 0, 50, 0, 0xFF00FF00);
+		engine.line(0, 0, 0, 0, 0, 50, 0xFF0000FF);
+	}
+	
+}
+
+class LightShader extends hxsl.Shader {
 	static var SRC = {
 	static var SRC = {
 		var input : {
 		var input : {
 			pos : Float3,
 			pos : Float3,
@@ -42,11 +55,12 @@ class LightShader extends h3d.Shader {
 class Anim {
 class Anim {
 
 
 	var engine : h3d.Engine;
 	var engine : h3d.Engine;
-	var obj : h3d.CustomObject<LightShader>;
+	var scene : h3d.scene.Scene;
+	var obj : h3d.Drawable<LightShader>;
 	var model : h3d.prim.FBXModel;
 	var model : h3d.prim.FBXModel;
 	var anim : h3d.prim.Skin.Animation;
 	var anim : h3d.prim.Skin.Animation;
 	var time : Float;
 	var time : Float;
-	var palette : Array<h3d.Matrix>;
+	var palette : flash.Vector<h3d.Matrix>;
 	
 	
 	var flag : Bool;
 	var flag : Bool;
 	var view : Int;
 	var view : Int;
@@ -58,6 +72,7 @@ class Anim {
 		engine.backgroundColor = 0xFF808080;
 		engine.backgroundColor = 0xFF808080;
 		engine.onReady = onReady;
 		engine.onReady = onReady;
 		engine.init();
 		engine.init();
+		scene = new h3d.scene.Scene();
 	}
 	}
 	
 	
 	function onReady() {
 	function onReady() {
@@ -75,13 +90,13 @@ class Anim {
 		});
 		});
 
 
 		var shader = new LightShader();
 		var shader = new LightShader();
-		var name = "", aname = "Take 001";
+		var name = "";
 		
 		
 		var file = new Model();
 		var file = new Model();
 		var lib = new h3d.fbx.Library();
 		var lib = new h3d.fbx.Library();
 		lib.loadTextFile(file.readUTFBytes(file.length));
 		lib.loadTextFile(file.readUTFBytes(file.length));
 		model = new h3d.prim.FBXModel(lib.getMesh(name));
 		model = new h3d.prim.FBXModel(lib.getMesh(name));
-		
+		var aname = model.listAnimations().first().split("::")[1];
 		try {
 		try {
 			anim = model.getAnimation(aname);
 			anim = model.getAnimation(aname);
 		} catch( d:Dynamic ) {
 		} catch( d:Dynamic ) {
@@ -90,41 +105,40 @@ class Anim {
 		anim.computeAbsoluteFrames();
 		anim.computeAbsoluteFrames();
 		palette = anim.allocPalette();
 		palette = anim.allocPalette();
 		
 		
-		obj = new h3d.CustomObject(model, shader);
+		obj = new h3d.Drawable(model, shader);
 		obj.material.culling = None;
 		obj.material.culling = None;
 		obj.material.blend(SrcAlpha, OneMinusSrcAlpha);
 		obj.material.blend(SrcAlpha, OneMinusSrcAlpha);
-		obj.shader.tex = engine.mem.makeTexture(new Tex(0,0));
+		obj.shader.tex = engine.mem.makeTexture(new Tex(0, 0));
+	
+		scene.addPass(obj);
+		scene.addPass(new Axis());
 	}
 	}
-		
+	
 	function onUpdate() {
 	function onUpdate() {
 		if( !engine.begin() )
 		if( !engine.begin() )
 			return;
 			return;
 			
 			
 		var dist = 50., height = 10.;
 		var dist = 50., height = 10.;
-		
+		var camera = scene.camera;
 		switch( view ) {
 		switch( view ) {
 		case 0:
 		case 0:
-			engine.camera.pos.set(0, height, dist);
-			engine.camera.up.set(0, -1, 0);
-			engine.camera.target.set(0, height, 0);
-			engine.camera.update();
+			camera.pos.set(0, height, dist);
+			camera.up.set(0, -1, 0);
+			camera.target.set(0, height, 0);
 		case 1:
 		case 1:
-			engine.camera.pos.set(0, dist, 0);
-			engine.camera.up.set(0, 1, 0);
-			engine.camera.target.set(0, 0, 0);
-			engine.camera.update();
+			camera.pos.set(0, dist, 0);
+			camera.up.set(0, 1, 0);
+			camera.target.set(0, 0, 0);
 		case 2:
 		case 2:
 			var K = Math.sqrt(2);
 			var K = Math.sqrt(2);
-			engine.camera.pos.set(dist, height, 0);
-			engine.camera.up.set(1, 0, 0);
-			engine.camera.target.set(0, height, 0);
-			engine.camera.update();
+			camera.pos.set(dist, height, 0);
+			camera.up.set(1, 0, 0);
+			camera.target.set(0, height, 0);
 		case 3:
 		case 3:
 			var speed = 0.02;
 			var speed = 0.02;
-			engine.camera.pos.set(Math.cos(time * speed) * dist, Math.sin(time * speed) * dist, height);
-			engine.camera.up.set(0, 0, -1);
-			engine.camera.target.set(0, 0, height);
-			engine.camera.update();
+			camera.pos.set(Math.cos(time * speed) * dist, Math.sin(time * speed) * dist, height);
+			camera.up.set(0, 0, -1);
+			camera.target.set(0, 0, height);
 		default:
 		default:
 			view = 0;
 			view = 0;
 		}
 		}
@@ -139,17 +153,13 @@ class Anim {
 		var lspeed = 0.03;
 		var lspeed = 0.03;
 		var light = new h3d.Vector( -Math.cos(time * lspeed), -Math.sin(time * lspeed), 3 );
 		var light = new h3d.Vector( -Math.cos(time * lspeed), -Math.sin(time * lspeed), 3 );
 		light.normalize();
 		light.normalize();
+		camera.update();
 		obj.shader.light = light;
 		obj.shader.light = light;
-		obj.shader.mproj = engine.camera.m;
+		obj.shader.mproj = camera.m;
 		obj.shader.mpos = h3d.Matrix.I();
 		obj.shader.mpos = h3d.Matrix.I();
 		obj.shader.bones = palette;
 		obj.shader.bones = palette;
-		obj.render(engine);
 		
 		
-		engine.line(0, 0, 0, 50, 0, 0, 0xFFFF0000);
-		engine.line(0, 0, 0, 0, 50, 0, 0xFF00FF00);
-		engine.line(0, 0, 0, 0, 0, 50, 0xFF0000FF);
-
-		engine.end();
+		engine.render(scene);
 	}
 	}
 	
 	
 	static function main() {
 	static function main() {

+ 0 - 0
samples/FbxTree.hx → samples/fbx/FbxTree.hx


+ 0 - 0
samples/anim.hxml → samples/fbx/anim.hxml


+ 3 - 3
samples/anim.hxproj → samples/fbx/anim.hxproj

@@ -11,11 +11,11 @@
     <movie version="11" />
     <movie version="11" />
     <movie minorVersion="3" />
     <movie minorVersion="3" />
     <movie platform="Flash Player" />
     <movie platform="Flash Player" />
-    <movie background="#FFFFFF" />
+    <movie background="#000000" />
   </output>
   </output>
   <!-- Other classes to be compiled into your SWF -->
   <!-- Other classes to be compiled into your SWF -->
   <classpaths>
   <classpaths>
-    <class path=".." />
+    <class path="..\.." />
   </classpaths>
   </classpaths>
   <!-- Build options -->
   <!-- Build options -->
   <build>
   <build>
@@ -23,7 +23,7 @@
     <option flashStrict="True" />
     <option flashStrict="True" />
     <option mainClass="Anim" />
     <option mainClass="Anim" />
     <option enabledebug="False" />
     <option enabledebug="False" />
-    <option additional="-lib format" />
+    <option additional="-lib hxsl&#xA;-D h3d" />
   </build>
   </build>
   <!-- haxelib libraries -->
   <!-- haxelib libraries -->
   <haxelib>
   <haxelib>

+ 0 - 0
samples/res/model.fbx → samples/fbx/res/model.fbx


+ 0 - 0
samples/res/texture.gif → samples/fbx/res/texture.gif