I have an simple example that I’ve sorta converted from the broomstick version to Gold but it doesn’t cast the shadow.
When lights are added, I see the specular highlight (images are attached) but no shadows. What’s the issue here? Thanks in advance..
package {
// import packages not shown here
// [SWF(width="800", height="600", frameRate="60")]
public class PrefabProject extends Sprite {
private var _view : View3D;
private var _camera : Camera3D;
private var sLp0 : StaticLightPicker;
private var light : DirectionalLight;
private var _count : Number = 0;
private var sphere2 : Mesh;
public function PrefabProject() {
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e : Event) : void {
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.addEventListener(Event.RESIZE, onResize);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.showDefaultContextMenu = true;
stage.stageFocusRect = false;
initView();
initLights();
initContent();
addEventListener(Event.ENTER_FRAME, renderFrame);
}
private function initView() : void {
_view = new View3D();
_view.antiAlias = 2;
_view.backgroundColor = 0xFFFFFF;
_camera = _view.camera;
_camera.lens = new PerspectiveLens();
_camera.lens.near = 10;
_camera.lens.far = 15000;
_camera.x = -199.03759765625;
_camera.y = 1047.31494140625;
_camera.z = 584.86865234375;
addChildAt(_view, 0);
}
private function initContent() : void {
var planeMaterial : ColorMaterial = new ColorMaterial(0x009999);
planeMaterial.ambientColor = 0xCCCCCC;
planeMaterial.bothSides = true;
// SoftShadowMapMethod step size is to change the neighbour filtering
var plane : Mesh = new Mesh(new PlaneGeometry(2000, 2000, 1, 1, false, true));
planeMaterial.lightPicker = sLp0;
planeMaterial.specular = 2;
plane.rotationX = 90;
plane.material = planeMaterial;
plane.castsShadows = true;
planeMaterial.shadowMethod = new FilteredShadowMapMethod(light);
_view.scene.addChild(plane);
var material : ColorMaterial = new ColorMaterial(0xFFFF00);
material.lightPicker = sLp0;
material.ambientColor = 0xCCCCCC;
material.bothSides = true;
material.ambient = 1;
var sphere : Mesh = new Mesh(new SphereGeometry(50));
sphere.material = material;
sphere.y = 50;
sphere.castsShadows = true;
material.shadowMethod = new SoftShadowMapMethod(light);
_view.scene.addChild(sphere);
var material2 : ColorMaterial = new ColorMaterial(0xFF0000);
material2.ambientColor = 0xCCCCCC;
material2.bothSides = true;
material2.lightPicker = sLp0;
material2.ambient = 1;
sphere2 = new Mesh(new SphereGeometry(150));
sphere2.material = material2;
sphere2.y = 250;
sphere2.x = -250;
sphere2.z = 20;
sphere2.castsShadows = true;
material2.shadowMethod = new SoftShadowMapMethod(light);
_view.scene.addChild(sphere2);
_camera.lookAt(new Vector3D(0, 0, 0));
}
private function initLights() : void {
light = new DirectionalLight();
// light.shadowMapper = new NearDirectionalShadowMapper();
light.castsShadows = true;
// light.color = 0xFFFFFF;
light.position = new Vector3D(10, 1000, 50);
light.direction = new Vector3D(0, 0, 0);
light.specular = .5;
light.ambient = .5;
light.diffuse = 1;
sLp0 = new StaticLightPicker([light]);
}
public function renderFrame(e : Event) : void {
_view.render();
}
private function onResize(event : Event) : void {
_view.width = stage.stageWidth;
_view.height = stage.stageHeight;
}
}
}