Permalink
Browse files

CoreObject -> Drawable

  • Loading branch information...
ncannasse committed Dec 9, 2012
1 parent d3498b2 commit cc270bade22148cbc72d4c33f9eac9a6d78abf13
View
@@ -2,3 +2,4 @@
/engine.swf
/samples/*.swf
*.n
+*.swf
View
@@ -15,7 +15,7 @@
</output>
<!-- Other classes to be compiled into your SWF -->
<classpaths>
- <class path="samples" />
+ <class path="samples\basic" />
</classpaths>
<!-- Build options -->
<build>
View
@@ -1,6 +1,6 @@
package h2d;
-class Scene extends Layers {
+class Scene extends Layers, implements h3d.IDrawable {
public var width(default,null) : Int;
public var height(default, null) : Int;
View
@@ -109,10 +109,10 @@ private class CoreObjects {
public var tmpUVScale : h3d.Vector;
public var tmpColor : 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>;
+ 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;
public function new() {
@@ -131,21 +131,21 @@ private class CoreObjects {
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.depth(false, Always);
bitmapObj = b;
- var b = new h3d.CoreObject(plan, new CachedBitmapShader());
+ var b = new h3d.Drawable(plan, new CachedBitmapShader());
b.material.culling = None;
b.material.depth(false, Always);
cachedBitmapObj = b;
- tileObj = new h3d.CoreObject(null, new TileShader());
+ tileObj = new h3d.Drawable(null, new TileShader());
tileObj.material.depth(false, Always);
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.culling = None;
}
@@ -4,7 +4,7 @@ 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:hxsl.Shader> {
+class Drawable<S:hxsl.Shader> implements IDrawable {
public var shader : S;
public var primitive : h3d.prim.Primitive;
View
@@ -28,8 +28,8 @@ class Engine {
var antiAlias : Int;
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)
var curProjMatrix : h3d.Matrix;
@@ -104,7 +104,7 @@ class Engine {
ctx.setTextureAt(curTextures.length, null);
}
// 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;
curShader = s;
}
@@ -340,7 +340,7 @@ class Engine {
if( curProjMatrix == null )
return;
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.depthWrite = false;
}
@@ -357,7 +357,7 @@ class Engine {
if( curProjMatrix == null )
return;
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.depthWrite = false;
debugLine.material.culling = None;
View
@@ -0,0 +1,5 @@
+package h3d;
+
+interface IDrawable {
+ public function render( engine : Engine ) : Void;
+}
View
@@ -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;
View
@@ -17,14 +17,14 @@ class Skybox extends hxsl.Shader {
}
};
- var obj : h3d.CoreObject<Skybox>;
+ var obj : h3d.Drawable<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.CoreObject(prim, this);
+ obj = new h3d.Drawable(prim, this);
obj.material.depth(false, Compare.Always);
obj.material.culling = Face.Front;
}
View
@@ -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;
for( c in curves ) {
+ if( c.joint.bindId < 0 ) continue;
var m = palette[c.joint.bindId];
- if( m == null ) continue;
m.loadFrom(c.joint.transPos);
var mf = c.frames[frame];
if( mf != null ) m.multiply3x4(m, mf);
@@ -89,7 +89,7 @@ class Animation {
for( c in curves )
if( c.joint.bindId >= max )
max = c.joint.bindId;
- var a = [];
+ var a = new Table();
for( i in 0...max + 1 )
a.push(new h3d.Matrix());
return a;
View
@@ -1,6 +1,6 @@
package h3d.scene;
-class Scene extends Layers {
+class Scene extends Layers, implements h3d.IDrawable {
public var camera : h3d.Camera;
var extraPasses : Array<{ function render( engine : h3d.Engine ) : Void; }>;
File renamed without changes.
@@ -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 = {
var input : {
pos : Float3,
@@ -42,11 +55,12 @@ class LightShader extends h3d.Shader {
class Anim {
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 anim : h3d.prim.Skin.Animation;
var time : Float;
- var palette : Array<h3d.Matrix>;
+ var palette : flash.Vector<h3d.Matrix>;
var flag : Bool;
var view : Int;
@@ -58,6 +72,7 @@ class Anim {
engine.backgroundColor = 0xFF808080;
engine.onReady = onReady;
engine.init();
+ scene = new h3d.scene.Scene();
}
function onReady() {
@@ -75,13 +90,13 @@ class Anim {
});
var shader = new LightShader();
- var name = "", aname = "Take 001";
+ var name = "";
var file = new Model();
var lib = new h3d.fbx.Library();
lib.loadTextFile(file.readUTFBytes(file.length));
model = new h3d.prim.FBXModel(lib.getMesh(name));
-
+ var aname = model.listAnimations().first().split("::")[1];
try {
anim = model.getAnimation(aname);
} catch( d:Dynamic ) {
@@ -90,41 +105,40 @@ class Anim {
anim.computeAbsoluteFrames();
palette = anim.allocPalette();
- obj = new h3d.CustomObject(model, shader);
+ obj = new h3d.Drawable(model, shader);
obj.material.culling = None;
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() {
if( !engine.begin() )
return;
var dist = 50., height = 10.;
-
+ var camera = scene.camera;
switch( view ) {
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:
- 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:
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:
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:
view = 0;
}
@@ -139,17 +153,13 @@ class Anim {
var lspeed = 0.03;
var light = new h3d.Vector( -Math.cos(time * lspeed), -Math.sin(time * lspeed), 3 );
light.normalize();
+ camera.update();
obj.shader.light = light;
- obj.shader.mproj = engine.camera.m;
+ obj.shader.mproj = camera.m;
obj.shader.mpos = h3d.Matrix.I();
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() {
File renamed without changes.
File renamed without changes.
@@ -11,19 +11,19 @@
<movie version="11" />
<movie minorVersion="3" />
<movie platform="Flash Player" />
- <movie background="#FFFFFF" />
+ <movie background="#000000" />
</output>
<!-- Other classes to be compiled into your SWF -->
<classpaths>
- <class path=".." />
+ <class path="..\.." />
</classpaths>
<!-- Build options -->
<build>
<option directives="" />
<option flashStrict="True" />
<option mainClass="Anim" />
<option enabledebug="False" />
- <option additional="-lib format" />
+ <option additional="-lib hxsl&#xA;-D h3d" />
</build>
<!-- haxelib libraries -->
<haxelib>
File renamed without changes.
File renamed without changes.

0 comments on commit cc270ba

Please sign in to comment.