, Jr. Member
for users and or the record, here is how to use away3d in haxe:
first, compile away3d as a swc (you can use export swc plugin in flash develop) asuming that you either do the above fixes manually or the dev team merge these fixes i the code base.
extract the swc and add the swf to you haxe project using the compiler command -swc-lib library.swf.
note: you can also make stub classes if you wish to link the haxe proejct into another as3 project that uses its own away3d later on.
class Main extends Sprite
{
private var camera:Camera3D;
private var view:View3D;
private var ground:Sphere;
private var cameraController:HoverController;
public var light:DirectionalLight;
public function init()
{
move= false;
//this is important or it wont work
var boot:Boot = new Boot();
flash.Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
flash.Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT;
camera = new Camera3D();
camera.lens.far = 2100;
view = new View3D();
view.scene = new Scene3D();
view.camera = camera;
//setup controller to be used on the camera
cameraController = new HoverController(camera, null, 45, 20, 1000, 10);
light = new DirectionalLight();
light.position = new Vector3D(3,3,3);
light.direction = new Vector3D( -1, -1, -1);
view.scene.addChild(light);
//view.addSourceURL("srcview/index.html");
Lib.current.addChild(view);
Lib.current.addEventListener(Event.ENTER_FRAME, onEnterFrame);
var ctr:ObjectContainer3D = new ObjectContainer3D();
var green : ColorMaterial = new ColorMaterial(0x00FF00);
green.lights = [light];
//ctr.addChild(new Sphere(green, 3));
//ground.material = green;
ground = new Sphere(green, 3);
ctr.addChild(ground);
ctr.scale(80);
view.scene.addChild(ctr);
}
private var move:Bool;
private var lastPanAngle:Float;
private var lastTiltAngle:Float;
private var lastMouseX:Int;
private var lastMouseY:Int;
function onEnterFrame(event:Event):Void
{
if (move) {
cameraController.panAngle = 0.3 * (stage.mouseX - lastMouseX) + lastPanAngle;
cameraController.tiltAngle = 0.3 * (stage.mouseY - lastMouseY) + lastTiltAngle;
}
view.render();
}
static var run : Bool = false;
static function added( event : flash.events.Event )
{
if( run )
return;
if( event.target != flash.Lib.current || flash.Lib.current.stage == null )
return;
run = true;
go();
}
static function go( )
{
var main:Main = new Main();
main.init();
}
static function main()
{
flash.Lib.current.addEventListener( flash.events.Event.ADDED, added);
}
}
hope this helps,