Home > Uncategorized > Lighting

Lighting

package
{
import away3d.containers.View3D;
import away3d.lights.PointLight3D;
import away3d.materials.WhiteShadingBitmapMaterial;
import away3d.primitives.Sphere;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
/**
* …
* @author Shiu
*/
public class AssignLighting extends Sprite
{
private var _view:View3D;
private var sp:Sphere;
private var light:PointLight3D;

[Embed(source = “../lib/Earth_Diffuse_2.jpg”)]
private var Earth:Class;

public function AssignLighting()
{
_view = new View3D(); addChild(_view);
_view.x = stage.stageWidth >> 1;
_view.y = stage.stageHeight >> 1;

//one fill color, perlin noise and bitmap
var bmp:BitmapData = new BitmapData(100, 100, true, 0xffAAAAAA);
//var bmp : BitmapData = new BitmapData(200, 200);
//bmp.perlinNoise(200, 200, 2, Math.random(), true, true);

//var earthBmp:Bitmap = new Earth as Bitmap;
//var bmp:BitmapData = new BitmapData(640, 320);
//bmp.draw(earthBmp);

sp = new Sphere(); _view.scene.addChild(sp);
sp.segmentsH = 10; sp.segmentsW = 10;
sp.material = new WhiteShadingBitmapMaterial(bmp);

light = new PointLight3D(); _view.scene.addLight(light);
light.z = -500; light.brightness = 0.1;

addEventListener(MouseEvent.MOUSE_DOWN, interact);
_view.addEventListener(MouseEvent.MOUSE_MOVE, interact);
_view.addEventListener(MouseEvent.MOUSE_WHEEL, interact);
_view.addEventListener(Event.ENTER_FRAME, refresh);
}

private function interact(e:MouseEvent):void
{
if (e.type == “mouseDown”) {
light.brightness += 0.1;
}
if(e.type == “mouseMove”){
sp.x = mouseX – stage.stageWidth * 0.5;
sp.y = -(mouseY – stage.stageHeight * 0.5);
}
if (e.type == “mouseWheel”) {
if (e.delta > 0) sp.z -= 100;
if (e.delta < 0) sp.z += 100;
}
}

private function refresh(e:Event):void
{
sp.rotationY += 1;
_view.render();
}

}

}

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: