Paste
Pasted by Bubby4j ( 15 years ago )
/*
StageFunctions.as for Away3D by Bubby4j.
Copyright 2011 Bubby4j
Do not distribute.
*/
import flash.display.*;
import flash.events.*;
import away3d.core.base.*;
import away3d.core.math.*;
import away3d.containers.*;
import away3d.primitives.*;
import away3d.cameras.*;
import away3d.core.render.*;
import away3d.materials.*;
import away3d.core.utils.*;
import away3d.loaders.*;
var view:View3D;
//FPS counter
var last:uint = getTimer();
var ticks:uint = 0;
//End FPS counter
function init3D(){
stage.frameRate=30;
addChild(view=new View3D({x:stage.width/2, y:stage.height/2}));
addEventListener(Event.ENTER_FRAME,away3dloop);
view.camera.x = 0;
view.camera.y = 0;
view.camera.z = 0;
view.camera.moveBackward(2000);
}
function sphere(name:String,x:int,y:int,z:int):Sphere {
var sphereA = new Sphere({material:new WireColorMaterial()});
sphereA.x = x;
sphereA.y = y;
sphereA.z = z;
sphereA.name = name;
view.scene.addChild(sphereA);
return sphereA;
}
function load3ds(url:String, namer:String, xp, yp, zp){//This loads the 3ds model
/*var obj:Object3D = new Object3D({material:new WireColorMaterial()});
obj.x = xp;
obj.y = yp;
obj.z = xp;
view.scene.addChild(obj);
var loader:Loader3D = Max3DS.load(url, obj);
return loader;*/
// start mesh loading
var loader = Max3DS.load(url, {material:null, name:"turtle", scaling:0.1, y:50, x:10, z:10, rotationX:-90, loadersize:300});
// add the loader object to the scene
//view.scene.addChild(loader);
//return loader;
}
function away3dloop(event:Event):void {
/*if (view.scene.getChildByName("moo")){
view.scene.getChildByName("moo").rotationX+=2;
view.scene.getChildByName("moo").rotationY+=2;
}*/
//Loop and rotate objects
var objs = view.scene.children;
for (var i:int = 0; i < objs.length; i++) {
//objs[i].rotationX+=2;
objs[i].rotationY+=2;
}
avcount.text = String(view.scene.children.length) + " objects"; //Object counter
view.render();
//FPS counter
ticks++;
var now:uint = getTimer();
var delta:uint = now - last;
if (delta >= 1000) {
var fps:Number = ticks / delta * 1000;
fpstxt.text = String(int((fps)*100)/100);
ticks = 0;
last = now;
}
//End FPS counter
}
init3D();
sphere("moo",0,0,0);
load3ds("model.3ds", "PenPen", 0,100,0);//Triggers the load function
Revise this Paste