Applying Lighting

Software: Away3D 4.x

Bubby4j, Newbie
Posted: 25 February 2012 10:14 PM   Total Posts: 5

I’m trying to make lighting work, what material settings do I need?
Here’s all of my lighting and material code:

light = new PointLight();
light.x = 15000;
light.z = 15000;
light.color = 0xFFCC99;
light.ambient = 0;
light.specular = 1;
   
scene.addChild(light); 

and

var material:ColorMaterial = new ColorMaterial(0xFFFFFF);
cube = new Mesh(new CubeGeometry(200,100,300),material);
view.scene.addChild(cube); 

How do I apply the lighting to it, so the side away from the light is dark?
Right now it’s just a cube that’s white all over.
I’m using Away3D beta, which I downloaded from git yesterday.

   

Avatar
kurono, Sr. Member
Posted: 25 February 2012 10:25 PM   Total Posts: 103   [ # 1 ]

Use “LightPicker” to pick the lights you need.

material.lightPicker = new StaticLightPicker([light]);
material.diffuseLightSources = LightSources.LIGHTS; 

Small of-topic:
You can also make your code short & clean, using the “with” statement for your light as follows:

with (light) {
x 
= 15000;
z = 15000;
color = 0xFFCC99;
ambient = 0;
specular = 1;
} 

The same is for material, of course.

Cheers!

   

Bubby4j, Newbie
Posted: 25 February 2012 10:39 PM   Total Posts: 5   [ # 2 ]

Worked great, thanks.

   

Avatar
kurono, Sr. Member
Posted: 25 February 2012 10:42 PM   Total Posts: 103   [ # 3 ]

You’re welcome

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X