Hi All,
I am new to Away3D and this forum. I just started learning today away3D.
Actually I created a sphere and plane using premitive objects and added directional light.
For materials I added sahdow method and enabled castsShadows to true for mesh objects.
But still shadows not displaying, I am using latest version of Away3D swc.
Hope will get help…
Please check following code:
package {
import flash.display.MovieClip;
import flash.events.Event;
import away3d.entities.*;
import away3d.containers.View3D;
import away3d.primitives.*;
import away3d.utils.*;
import flash.display.*;
import flash.geom.Vector3D;
import away3d.tools.helpers.data.MeshDebug;
import flash.display3D.*;
import away3d.materials.TextureMaterial;
import away3d.lights.DirectionalLight;
import away3d.lights.shadowmaps.*;
import away3d.materials.lightpickers.StaticLightPicker;
import away3d.materials.methods.NearShadowMapMethod;
import away3d.materials.methods.FilteredShadowMapMethod;
[SWF(backgroundColor=”#000000”, frameRate=“60”, quality=“LOW”)]
public class try_2 extends MovieClip {
[Embed(source=“assets/Brkrun.jpg”)]
private var xBrick : Class;
[Embed(source=“assets/CONCRETE.jpg”)]
private var xConc : Class;
private var view : View3D;
private var plane : Mesh;
private var ball : Mesh;
var sunLight : DirectionalLight;
var oLightPicker : StaticLightPicker;
public function try_2() {
// constructor code
addEventListener(Event.ADDED_TO_STAGE, fAdded);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
}
private function fAdded(event:Event){
view = new View3D();
addChild(view);
view.camera.z = -600;
view.camera.y = 500;
view.camera.lookAt(new Vector3D());
sunLight = new DirectionalLight();
sunLight.color = 0xAAAAA9;
sunLight.ambientColor = 0xAAAAA9;
sunLight.ambient = 0.4;
sunLight.diffuse = 1;
sunLight.specular = 1;
sunLight.z = 0;
sunLight.y = 500;
sunLight.lookAt(new Vector3D());
sunLight.castsShadows = true;
sunLight.shadowMapper = new NearDirectionalShadowMapper(.1);
view.scene.addChild(sunLight);
oLightPicker = new StaticLightPicker([sunLight]);
//crete global shadow method
var _shadowMethod:FilteredShadowMapMethod = new FilteredShadowMapMethod(sunLight);
//_shadowMethod.epsilon = .0007;
var planeMaterial : TextureMaterial = new TextureMaterial(Cast.bitmapTexture(xBrick));
planeMaterial.lightPicker = oLightPicker;
planeMaterial.shadowMethod = _shadowMethod;
plane = new Mesh(new PlaneGeometry(500, 500, 10, 10), planeMaterial);
plane.castsShadows = true;
view.scene.addChild(plane);
var ballMaterial : TextureMaterial = new TextureMaterial(Cast.bitmapTexture(xConc));
ballMaterial.lightPicker = oLightPicker;
ballMaterial.shadowMethod = _shadowMethod;
ball = new Mesh(new SphereGeometry(50), ballMaterial);
ball.y += 60;
ball.castsShadows = true;
view.scene.addChild(ball);
addEventListener(Event.ENTER_FRAME, fAppLoop);
}
private function fAppLoop(event:Event):void{
plane.rotationY +=1;
//view.camera.rotationY += 1;
//view.camera.lookAt(new Vector3D());
view.render();
}
}
}