/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/dzmN
*/
package {
import flash.display.BitmapData;
import flash.events.Event;
import alternativ7.engine3d.containers.*;
import alternativ7.engine3d.core.*;
import alternativ7.engine3d.objects.*;
import alternativ7.engine3d.objects.Mesh;
import alternativ7.engine3d.primitives.*;
import alternativ7.engine3d.materials.*;
// import alternativ7.types.*;
import alternativ7.*;
import alternativ7.engine3d.lights.*;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public var cam:Camera3D;
public var cont:ConflictContainer;
public var contb:ConflictContainer;
public var mat:TextureMaterial;
public var light:OmniLight;
public var lm:Box;
public function FlashTest() {
// write as3 code here..
cont = new ConflictContainer();
contb = new ConflictContainer();
cam = new Camera3D();
cam.z = -100;
cam.view = new View(460,460);
addChild(cam.view);
cont.addChild(cam);
cont.addChild(contb);
var col:uint = 0xFFffFF;
//var light:OmniLight;
light = new OmniLight(col,1,500);
cont.addChild(light);
lm = new Box(4,4,4);
lm.setMaterialToAllFaces(new FillMaterial(col,1));
cont.addChild(lm);
var b:BitmapData;
b = new BitmapData(32,32,false,0xaaAAaa);
var sp:Sphere;
sp = new Sphere(80,8,8,true);
sp.calculateFacesNormals();
sp.calculateVerticesNormals();
//sp.setMaterialToAllFaces( new FillMaterial(0x0000FF,0.5,1,0));
sp.setMaterialToAllFaces(new VertexLightMaterial(b));
contb.addChild(sp);
vecPart = new Vector.<Part>;
var i:int;
var p:Part;
for (i = 0; i < 64; i++)
{
p = new Part();
vecPart.push(p);
contb.addChild(p.box);
}//nexti
/*
var box:Box;
var bm:BitmapData = new BitmapData(32,32);
bm.noise(1);
mat = new TextureMaterial(bm);
box = new Box(50,50,50);
box.setMaterialToAllFaces(mat);
cont.addChild(box);
*/
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var vecPart:Vector.<Part>;
public var ang:Number = 0;
public function onEnter(e:Event):void
{
var i:int;
var p:Part;
var num:int;
num = vecPart.length;
for (i = 0; i < num; i++)
{
p = vecPart[i];
p.update();
}//nexti
// cont.rotationX += 2;
/*
ang += 0.01;
cam.x = Math.cos(ang) * 40;
cam.z = Math.sin(ang) * 40;
cam.rotationY = ang - 1.57;
//cam.lookAt(0,0,0);
//cam.rotationY += 1.57;
*/
ang += 0.01;
light.x = Math.cos(ang)*50;
light.z = Math.sin(ang)*50;
lm.x = light.x;
lm.z = light.z;
contb.rotationY += 0.01;
cam.render();
}//onenter
}//classend
}
import flash.display.BitmapData;//package
import alternativ7.engine3d.containers.*;
import alternativ7.engine3d.core.*;
import alternativ7.engine3d.objects.*;
import alternativ7.engine3d.objects.Mesh;
import alternativ7.engine3d.primitives.*;
import alternativ7.engine3d.materials.*;
// import alternativ7.types.*;
import alternativ7.*;
import alternativ7.engine3d.lights.*;
internal class Part
{
public var box:Box;
public var cx:Number = 0;
public var cy:Number = 0;
public var cz:Number = 0;
public var vx:Number = 0;
public var vy:Number = 0;
public var vz:Number = 0;
public var tex:BitmapData;
public function Part()
{
tex = new BitmapData(16,16,false,Math.random()*0xFFffFF);
box = new Box(4,4,4);
box.calculateFacesNormals();
box.calculateVerticesNormals();
// box.setMaterialToAllFaces(new FillMaterial(0xFF0000,1));
box.setMaterialToAllFaces(new VertexLightMaterial(tex));
reset();
}//part
public function reset():void
{
cx = 0; cy = 0; cz = 0;
vy = Math.random() * -4;
vx = (Math.random()-Math.random()) * 3;
vz = (Math.random()-Math.random()) * 3;
}//reset
public function update():void
{
vy += 0.1;
vx *= 0.99;
vz *= 0.99;
cx += vx;
cy += vy;
cz += vz;
box.x = cx;
box.y = cy;
box.z = cz;
box.rotationX += vx * 0.3;
box.rotationY += vy * 0.2;
if (cy >= 10) {reset();}
}//update
};//classend