Browse Source

rearchitectured (single CoreObject, factorized 2d shaders in h2d.Tools), ready for adding scene

ncannasse 12 years ago
parent
commit
87173b3ea9
12 changed files with 218 additions and 236 deletions
  1. 3 39
      h2d/CachedBitmap.hx
  2. 1 1
      h2d/Tile.hx
  3. 11 46
      h2d/TileColorGroup.hx
  4. 13 42
      h2d/TileGroup.hx
  5. 139 32
      h2d/Tools.hx
  6. 24 0
      h3d/CoreObject.hx
  7. 0 40
      h3d/Engine.hx
  8. 6 1
      h3d/Quat.hx
  9. 1 15
      h3d/fbx/XBXFile.hx
  10. 7 7
      h3d/fx/Bitmap.hx
  11. 3 4
      h3d/fx/Skybox.hx
  12. 10 9
      samples/Test.hx

+ 3 - 39
h2d/CachedBitmap.hx

@@ -1,27 +1,5 @@
 package h2d;
 
-private class BitmapMatrixShader extends h3d.Shader {
-	static var SRC = {
-		var input : {
-			pos : Float2,
-		};
-		var tuv : Float2;
-		function vertex( size : Float3, mat1 : Float3, mat2 : Float3, skew : Float, uvScale : Float2 ) {
-			var tmp : Float4;
-			var spos = pos.xyw * size;
-			tmp.x = spos.dp3(mat1);
-			tmp.y = spos.dp3(mat2);
-			tmp.z = 0;
-			tmp.w = 1 - skew * pos.y;
-			out = tmp;
-			tuv = pos * uvScale;
-		}
-		function fragment( tex : Texture, mcolor : M44, acolor : Float4 ) {
-			out = tex.get(tuv, nearest) * mcolor + acolor;
-		}
-	}
-}
-
 class CachedBitmap extends Sprite {
 
 	var tex : h3d.mat.Texture;
@@ -70,29 +48,15 @@ class CachedBitmap extends Sprite {
 		return h;
 	}
 
-	static var BITMAP_OBJ : h3d.CustomObject<BitmapMatrixShader> = null;
-	static var TMP_VECTOR = new h3d.Vector();
-	
 	override function draw( engine : h3d.Engine ) {
 		if( colorMatrix == null && colorAdd == null && skew == 0. ) {
 			Tools.drawTile(engine, this, tile, new h3d.Color(1, 1, 1, 1), blendMode);
 			return;
 		}
-		var b = BITMAP_OBJ;
-		if( b == null ) {
-			var p = new h3d.prim.Quads([
-				new h3d.Point(0, 0),
-				new h3d.Point(1, 0),
-				new h3d.Point(0, 1),
-				new h3d.Point(1, 1),
-			]);
-			b = new h3d.CustomObject(p, new BitmapMatrixShader());
-			b.material.culling = None;
-			b.material.depth(false, Always);
-			BITMAP_OBJ = b;
-		}
+		var core = Tools.getCoreObjects();
+		var b = core.cachedBitmapObj;
 		Tools.setBlendMode(b.material,blendMode);
-		var tmp = TMP_VECTOR;
+		var tmp = core.tmpVector;
 		tmp.x = tile.width;
 		tmp.y = tile.height;
 		tmp.z = 1;

+ 1 - 1
h2d/Tile.hx

@@ -32,7 +32,7 @@ class Tile {
 	
 	function getTexture() {
 		if( innerTex == null || innerTex.isDisposed() )
-			return Tools.emptyTexture();
+			return Tools.getCoreObjects().getEmptyTexture();
 		return innerTex;
 	}
 		

+ 11 - 46
h2d/TileColorGroup.hx

@@ -1,30 +1,5 @@
 package h2d;
 
-private class TileShader2D extends h3d.Shader {
-	static var SRC = {
-		var input : {
-			pos : Float2,
-			uv : Float2,
-			color : Float4,
-		};
-		var tuv : Float2;
-		var tcolor : Float4;
-		function vertex( mat1 : Float3, mat2 : Float3 ) {
-			var tmp : Float4;
-			tmp.x = pos.xyw.dp3(mat1);
-			tmp.y = pos.xyw.dp3(mat2);
-			tmp.z = 0;
-			tmp.w = 1;
-			out = tmp;
-			tcolor = color;
-			tuv = uv;
-		}
-		function fragment( tex : Texture ) {
-			out = tex.get(tuv, nearest) * tcolor;
-		}
-	}
-}
-
 private class TileLayerContent extends h3d.prim.Primitive {
 
 	var tmp : flash.Vector<Float>;
@@ -92,9 +67,6 @@ private class TileLayerContent extends h3d.prim.Primitive {
 
 class TileColorGroup extends Sprite {
 	
-	static var SHADER : TileShader2D = null;
-
-	var object : h3d.Object;
 	var content : TileLayerContent;
 	var curColor : h3d.Color;
 	
@@ -105,12 +77,6 @@ class TileColorGroup extends Sprite {
 		tile = t;
 		curColor = new h3d.Color(1, 1, 1, 1);
 		content = new TileLayerContent();
-		if( SHADER == null )
-			SHADER = new TileShader2D();
-		object = new h3d.Object(content, new h3d.mat.Material(SHADER));
-		object.material.depth(false, Always);
-		object.material.culling = None;
-		setTransparency(true);
 	}
 	
 	public function reset() {
@@ -118,7 +84,7 @@ class TileColorGroup extends Sprite {
 	}
 	
 	override function onDelete() {
-		object.primitive.dispose();
+		content.dispose();
 		super.onDelete();
 	}
 	
@@ -137,18 +103,17 @@ class TileColorGroup extends Sprite {
 		content.add(x, y, r, g, b, a, t);
 	}
 	
-	public function setTransparency(a) {
-		if( a )
-			object.material.blend(SrcAlpha, OneMinusSrcAlpha);
-		else
-			object.material.blend(One,Zero);
-	}
-	
 	override function draw(engine:h3d.Engine) {
-		var shader = SHADER;
+		var core = Tools.getCoreObjects();
+		var shader = core.tileColorObj.shader;
 		shader.tex = tile.getTexture();
-		shader.mat1 = new h3d.Vector(matA, matC, absX);
-		shader.mat2 = new h3d.Vector(matB, matD, absY);
-		object.render(engine);
+		var tmp = core.tmpVector;
+		tmp.set(matA, matC, absX);
+		shader.mat1 = tmp;
+		tmp.set(matB, matD, absY);
+		shader.mat2 = tmp;
+		Tools.setBlendMode(core.tileColorObj.material, blendMode);
+		engine.selectMaterial(core.tileColorObj.material);
+		content.render(engine);
 	}
 }

+ 13 - 42
h2d/TileGroup.hx

@@ -1,27 +1,5 @@
 package h2d;
 
-private class TileShader2D extends h3d.Shader {
-	static var SRC = {
-		var input : {
-			pos : Float2,
-			uv : Float2,
-		};
-		var tuv : Float2;
-		function vertex( mat1 : Float3, mat2 : Float3 ) {
-			var tmp : Float4;
-			tmp.x = pos.xyw.dp3(mat1);
-			tmp.y = pos.xyw.dp3(mat2);
-			tmp.z = 0;
-			tmp.w = 1;
-			out = tmp;
-			tuv = uv;
-		}
-		function fragment( tex : Texture, color : Float4 ) {
-			out = tex.get(tuv, nearest) * color;
-		}
-	}
-}
-
 private class TileLayerContent extends h3d.prim.Primitive {
 
 	var tmp : flash.Vector<Float>;
@@ -75,9 +53,6 @@ private class TileLayerContent extends h3d.prim.Primitive {
 
 class TileGroup extends Sprite {
 	
-	static var SHADER : TileShader2D = null;
-
-	var object : h3d.Object;
 	var content : TileLayerContent;
 	
 	public var tile : Tile;
@@ -87,11 +62,6 @@ class TileGroup extends Sprite {
 		tile = t;
 		color = new h3d.Color(1, 1, 1, 1);
 		content = new TileLayerContent();
-		if( SHADER == null )
-			SHADER = new TileShader2D();
-		object = new h3d.Object(content, new h3d.mat.Material(SHADER));
-		object.material.depth(false, Always);
-		object.material.culling = None;
 		super(parent);
 	}
 	
@@ -100,7 +70,7 @@ class TileGroup extends Sprite {
 	}
 	
 	override function onDelete() {
-		object.primitive.dispose();
+		content.dispose();
 		super.onDelete();
 	}
 	
@@ -113,18 +83,19 @@ class TileGroup extends Sprite {
 		return c;
 	}
 	
-	override function set_blendMode(b) {
-		this.blendMode = b;
-		Tools.setBlendMode(object.material, b);
-		return b;
-	}
-	
 	override function draw(engine:h3d.Engine) {
-		var shader = SHADER;
+		var core = Tools.getCoreObjects();
+		var shader = core.tileObj.shader;
+		var tmp = core.tmpVector;
+		tmp.set(matA, matC, absX);
+		shader.mat1 = tmp;
+		tmp.set(matB, matD, absY);
+		shader.mat2 = tmp;
+		tmp.set(color.r, color.g, color.b);
+		shader.color = tmp;
 		shader.tex = tile.getTexture();
-		shader.mat1 = new h3d.Vector(matA, matC, absX);
-		shader.mat2 = new h3d.Vector(matB, matD, absY);
-		shader.color = color.toVector();
-		object.render(engine);
+		Tools.setBlendMode(core.tileObj.material, blendMode);
+		engine.selectMaterial(core.tileObj.material);
+		content.render(engine);
 	}
 }

+ 139 - 32
h2d/Tools.hx

@@ -1,6 +1,5 @@
 package h2d;
 
-
 private class BitmapShader extends h3d.Shader {
 	static var SRC = {
 		var input : {
@@ -23,30 +22,151 @@ private class BitmapShader extends h3d.Shader {
 	}
 }
 
-class Tools {
+private class CachedBitmapShader extends h3d.Shader {
+	static var SRC = {
+		var input : {
+			pos : Float2,
+		};
+		var tuv : Float2;
+		function vertex( size : Float3, mat1 : Float3, mat2 : Float3, skew : Float, uvScale : Float2 ) {
+			var tmp : Float4;
+			var spos = pos.xyw * size;
+			tmp.x = spos.dp3(mat1);
+			tmp.y = spos.dp3(mat2);
+			tmp.z = 0;
+			tmp.w = 1 - skew * pos.y;
+			out = tmp;
+			tuv = pos * uvScale;
+		}
+		function fragment( tex : Texture, mcolor : M44, acolor : Float4 ) {
+			out = tex.get(tuv, nearest) * mcolor + acolor;
+		}
+	}
+}
+
+private class TileShader extends h3d.Shader {
+	static var SRC = {
+		var input : {
+			pos : Float2,
+			uv : Float2,
+		};
+		var tuv : Float2;
+		function vertex( mat1 : Float3, mat2 : Float3 ) {
+			var tmp : Float4;
+			tmp.x = pos.xyw.dp3(mat1);
+			tmp.y = pos.xyw.dp3(mat2);
+			tmp.z = 0;
+			tmp.w = 1;
+			out = tmp;
+			tuv = uv;
+		}
+		function fragment( tex : Texture, color : Float4 ) {
+			out = tex.get(tuv, nearest) * color;
+		}
+	}
+}
 
-	static var BITMAP_OBJ : h3d.CustomObject<BitmapShader> = null;
-	static var TMP_VECTOR = new h3d.Vector();
+private class TileColorShader extends h3d.Shader {
+	static var SRC = {
+		var input : {
+			pos : Float2,
+			uv : Float2,
+			color : Float4,
+		};
+		var tuv : Float2;
+		var tcolor : Float4;
+		function vertex( mat1 : Float3, mat2 : Float3 ) {
+			var tmp : Float4;
+			tmp.x = pos.xyw.dp3(mat1);
+			tmp.y = pos.xyw.dp3(mat2);
+			tmp.z = 0;
+			tmp.w = 1;
+			out = tmp;
+			tcolor = color;
+			tuv = uv;
+		}
+		function fragment( tex : Texture ) {
+			out = tex.get(tuv, nearest) * tcolor;
+		}
+	}
+}
+
+private class CoreObjects  {
+	
+	public var tmpVector : h3d.Vector;
+	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>;
+	var emptyTexture : h3d.mat.Texture;
+	
+	public function new() {
+		tmpVector = new h3d.Vector();
+		tmpMatrix = new h3d.Matrix();
+		
+		var plan = new h3d.prim.Quads([
+			new h3d.Point(0, 0),
+			new h3d.Point(1, 0),
+			new h3d.Point(0, 1),
+			new h3d.Point(1, 1),
+		]);
 		
+		var b = new h3d.CoreObject(plan, new BitmapShader());
+		b.material.culling = None;
+		b.material.depth(false, Always);
+		bitmapObj = b;
+		
+		var b = new h3d.CoreObject(plan, new CachedBitmapShader());
+		b.material.culling = None;
+		b.material.depth(false, Always);
+		cachedBitmapObj = b;
+		
+		tileObj = new h3d.CoreObject(null, new TileShader());
+		tileObj.material.depth(false, Always);
+		tileObj.material.culling = None;
+		
+		tileColorObj = new h3d.CoreObject(null,new TileColorShader());
+		tileColorObj.material.depth(false, Always);
+		tileColorObj.material.culling = None;
+	}
+	
+	public function getEmptyTexture() {
+		if( emptyTexture == null || emptyTexture.isDisposed() ) {
+			emptyTexture = h3d.Engine.getCurrent().mem.allocTexture(1, 1);
+			var o = haxe.io.Bytes.alloc(4);
+			o.set(0, 0xFF);
+			o.set(2, 0xFF);
+			o.set(3, 0xFF);
+			emptyTexture.uploadBytes(o);
+		}
+		return emptyTexture;
+	}
+	
+}
+
+class Tools {
+	
+	static var CORE = null;
+	
 	@:allow(h2d)
-	static function drawTile( engine : h3d.Engine, spr : Sprite, tile : Tile, color : h3d.Color, blendMode : BlendMode ) {
-		var b = BITMAP_OBJ;
-		if( b == null ) {
-			var p = new h3d.prim.Quads([
-				new h3d.Point(0, 0),
-				new h3d.Point(1, 0),
-				new h3d.Point(0, 1),
-				new h3d.Point(1, 1),
-			]);
-			b = new h3d.CustomObject(p, new BitmapShader());
-			b.material.culling = None;
-			b.material.depth(false, Always);
-			BITMAP_OBJ = b;
+	static function getCoreObjects() {
+		var c = CORE;
+		if( c == null ) {
+			c = new CoreObjects();
+			CORE = c;
 		}
+		return c;
+	}
+		
+	@:allow(h2d)
+	static function drawTile( engine : h3d.Engine, spr : Sprite, tile : Tile, color : h3d.Color, blendMode : BlendMode ) {
+		var core = getCoreObjects();
+		var b = core.bitmapObj;
 		setBlendMode(b.material, blendMode);
 		if( tile == null )
-			tile = new Tile(emptyTexture(), 0, 0, 5, 5);
-		var tmp = TMP_VECTOR;
+			tile = new Tile(core.getEmptyTexture(), 0, 0, 5, 5);
+		var tmp = core.tmpVector;
 		// adds 1/10 pixel size to prevent precision loss after scaling
 		tmp.x = tile.width + 0.1;
 		tmp.y = tile.height + 0.1;
@@ -93,18 +213,5 @@ class Tools {
 			mat.blend(Zero, OneMinusSrcAlpha);
 		}
 	}
-
-	static var ETEX : h3d.mat.Texture = null;
-	public static function emptyTexture() {
-		if( ETEX == null || ETEX.isDisposed() ) {
-			ETEX = h3d.Engine.getCurrent().mem.allocTexture(1, 1);
-			var o = haxe.io.Bytes.alloc(4);
-			o.set(0, 0xFF);
-			o.set(2, 0xFF);
-			o.set(3, 0xFF);
-			ETEX.uploadBytes(o);
-		}
-		return ETEX;
-	}
 	
 }

+ 24 - 0
h3d/CoreObject.hx

@@ -0,0 +1,24 @@
+package h3d;
+
+/**
+	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.
+ **/
+class CoreObject<S:h3d.Shader> {
+
+	public var shader : S;
+	public var primitive : h3d.prim.Primitive;
+	public var material : h3d.mat.Material;
+	
+	public function new(prim, shader) {
+		this.primitive = prim;
+		this.shader = shader;
+		this.material = new h3d.mat.Material(shader);
+	}
+	
+	public function render( engine : h3d.Engine ) {
+		engine.selectMaterial(material);
+		primitive.render(engine);
+	}
+	
+}

+ 0 - 40
h3d/Engine.hx

@@ -6,7 +6,6 @@ class Engine {
 	var s3d : flash.display.Stage3D;
 	var ctx : flash.display3D.Context3D;
 
-	public var camera : h3d.Camera;
 	public var mem(default,null) : h3d.impl.MemoryManager;
 
 	public var hardware(default, null) : Bool;
@@ -27,8 +26,6 @@ class Engine {
 	var curAttributes : Int;
 	var curTextures : Array<h3d.mat.Texture>;
 	var antiAlias : Int;
-	var debugPoint : h3d.CustomObject<h3d.impl.Shaders.PointShader>;
-	var debugLine : h3d.CustomObject<h3d.impl.Shaders.LineShader>;
 	var inTarget : Bool;
 
 	public function new( width = 0, height = 0, hardware = true, aa = 0, stageIndex = 0 ) {
@@ -46,7 +43,6 @@ class Engine {
 		stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
 		stage.addEventListener(flash.events.Event.RESIZE, onStageResize);
 		s3d = stage.stage3Ds[stageIndex];
-		camera = new Camera();
 		if( CURRENT == null )
 			CURRENT = this;
 	}
@@ -274,7 +270,6 @@ class Engine {
 		this.height = height;
 		this.antiAlias = aa;
 		ctx.configureBackBuffer(width, height, aa);
-		camera.ratio = width / height;
 	}
 
 	public function begin() {
@@ -347,41 +342,6 @@ class Engine {
 		ctx = null;
 	}
 
-	// debug functions
-	public function point( x : Float, y : Float, z : Float, color = 0x80FF0000, size = 1.0, depth = false ) {
-		if( debugPoint == null ) {
-			debugPoint = new CustomObject(new h3d.prim.Plan2D(), new h3d.impl.Shaders.PointShader());
-			debugPoint.material.blend(SrcAlpha, OneMinusSrcAlpha);
-			debugPoint.material.depthWrite = false;
-		}
-		debugPoint.material.depthTest = depth ? LessEqual : Always;
-		debugPoint.shader.mproj = camera.m;
-		debugPoint.shader.delta = new Vector(x, y, z, 1);
-		var gscale = 1 / 200;
-		debugPoint.shader.size = new Vector(size * gscale, size * gscale * width / height);
-		debugPoint.shader.color = color;
-		debugPoint.render(this);
-	}
-
-	public function line( x1 : Float, y1 : Float, z1 : Float, x2 : Float, y2 : Float, z2 : Float, color = 0x80FF0000, depth = false ) {
-		if( debugLine == null ) {
-			debugLine = new CustomObject(new h3d.prim.Plan2D(), new h3d.impl.Shaders.LineShader());
-			debugLine.material.blend(SrcAlpha, OneMinusSrcAlpha);
-			debugLine.material.depthWrite = false;
-			debugLine.material.culling = None;
-		}
-		debugLine.material.depthTest = depth ? LessEqual : Always;
-		debugLine.shader.mproj = camera.m;
-		debugLine.shader.start = new Vector(x1, y1, z1);
-		debugLine.shader.end = new Vector(x2, y2, z2);
-		debugLine.shader.color = color;
-		debugLine.render(this);
-	}
-
-	public function lineP( a : { x : Float, y : Float, z : Float }, b : { x : Float, y : Float, z : Float }, color = 0x80FF0000, depth = false ) {
-		line(a.x, a.y, a.z, b.x, b.y, b.z, color, depth);
-	}
-
 	static var BLEND = [
 		flash.display3D.Context3DBlendFactor.ONE,
 		flash.display3D.Context3DBlendFactor.ZERO,

+ 6 - 1
h3d/Quat.hx

@@ -59,6 +59,12 @@ class Quat {
 	}
 	
 	public function toMatrix() {
+		var m = new Matrix();
+		saveToMatrix(m);
+		return m;
+	}
+	
+	public function saveToMatrix( m : h3d.Matrix ) {
 		var xx = x * x;
 		var xy = x * y;
 		var xz = x * z;
@@ -68,7 +74,6 @@ class Quat {
 		var yw = y * w;
 		var zz = z * z;
 		var zw = z * w;
-		var m = new Matrix();
 		m._11 = 1 - 2 * ( yy + zz );
 		m._12 = 2 * ( xy - zw );
 		m._13 = 2 * ( xz + yw );

+ 1 - 15
h3d/fbx/XBXFile.hx

@@ -15,24 +15,10 @@ class XBXFile extends flash.utils.ByteArray {
 		if( root.compressed )
 			ba.inflate();//??
 		
-		//trace(ba);
 		var inStream = new haxe.io.BytesInput( haxe.io.Bytes.ofData(ba) );
 		
-		var a = [];
 		var rdr = new XBXReader( inStream );
-		while ( true )
-		{
-			try {
-				a.push( rdr.read() );
-			}
-			catch( d:Dynamic )
-			{
-				trace("finished on " + d);
-				break;
-			}
-		}
-		l.load( a );
-		
+		l.load(rdr.read());
 		return l;
 	}
 }

+ 7 - 7
h3d/fx/Bitmap.hx

@@ -20,7 +20,7 @@ private class BitmapShader extends h3d.Shader {
 
 }
 
-class Bitmap extends h3d.CustomObject<BitmapShader> {
+class Bitmap extends h3d.CoreObject<BitmapShader> {
 
 	public var bmp(default,null) : h3d.mat.Bitmap;
 	
@@ -31,15 +31,15 @@ class Bitmap extends h3d.CustomObject<BitmapShader> {
 	public var scaleX : Float;
 	public var scaleY : Float;
 	
-	static var shader = null;
-	static var prim = null;
+	static var SHADER = null;
+	static var PRIM = null;
 	
 	public function new( bmp ) {
-		if( shader == null ) {
-			shader = new BitmapShader();
-			prim = new h3d.prim.Plan2D();
+		if( SHADER == null ) {
+			SHADER = new BitmapShader();
+			PRIM = new h3d.prim.Plan2D();
 		}
-		super(prim,shader);
+		super(PRIM,SHADER);
 		material.depth(false, Compare.Always);
 		material.blend(Blend.SrcAlpha, Blend.OneMinusSrcAlpha);
 		material.culling = Face.None;

+ 3 - 4
h3d/fx/Skybox.hx

@@ -17,20 +17,19 @@ class Skybox extends h3d.Shader {
 		}
 	};
 
-	var obj : h3d.Object;
+	var obj : h3d.CoreObject<Skybox>;
 	
 	public function new(tex) {
 		super();
 		this.texture = tex;
 		var prim = new h3d.prim.Cube(2, 2, 2);
         prim.translate( -1, -1, -1);
-		obj = new h3d.Object(prim, new h3d.mat.Material(this));
+		obj = new h3d.CoreObject(prim, this);
 		obj.material.depth(false, Compare.Always);
 		obj.material.culling = Face.Front;
 	}
 	
-	public function render( engine : h3d.Engine, ?pos : h3d.Matrix ) {
-		var camera = engine.camera;
+	public function render( engine : h3d.Engine, camera : h3d.Camera, ?pos : h3d.Matrix ) {
         var size = camera.zFar / Math.sqrt(3);
         var m;
         if( pos == null ) {

+ 10 - 9
samples/Test.hx

@@ -22,14 +22,15 @@ class Test {
 	
 	var root : flash.display.Sprite;
 	var e : h3d.Engine;
-	var rgb : RGBShader;
 	var time : Float;
-	var obj : h3d.Object;
+	var camera : h3d.Camera;
+	var obj : h3d.CoreObject<RGBShader>;
 	
 	function new(root) {
 		this.root = root;
 		time = 0;
 		e = new h3d.Engine();
+		camera = new h3d.Camera();
 		e.debug = true;
 		e.backgroundColor = 0x202020;
 		e.onReady = start;
@@ -38,11 +39,11 @@ class Test {
 	
 	function start() {
 		root.addEventListener(flash.events.Event.ENTER_FRAME, update);
-		rgb = new RGBShader();
+		var rgb = new RGBShader();
 		var prim = new h3d.prim.Cube();
 		prim.translate( -0.5, -0.5, -0.5);
 		prim.addTCoords();
-		obj = new h3d.Object(prim, new h3d.mat.Material(rgb));
+		obj = new h3d.CoreObject(prim, rgb);
 		var bmp = new flash.display.BitmapData(256, 256);
 		bmp.perlinNoise(64, 64, 3, 0, true, true, 7);
 		rgb.tex = e.mem.makeTexture(bmp);
@@ -52,13 +53,13 @@ class Test {
 	function update(_) {
 		var dist = 5;
 		time += 0.01;
-		e.camera.pos.set(Math.cos(time) * dist, Math.sin(time) * dist, 3);
-		e.camera.update();
-		rgb.mproj = e.camera.m;
+		camera.pos.set(Math.cos(time) * dist, Math.sin(time) * dist, 3);
+		camera.update();
+		obj.shader.mproj = camera.m;
 		e.begin();
 		obj.render(e);
-		e.camera.m.prependRotate(new h3d.Vector(-0.5, 2, Math.cos(time)), time + Math.PI / 2);
-		rgb.mproj = e.camera.m;
+		camera.m.prependRotate(new h3d.Vector(-0.5, 2, Math.cos(time)), time + Math.PI / 2);
+		obj.shader.mproj = camera.m;
 		obj.render(e);
 		e.end();
 	}