Hello everyone,
I’m new to Away3D and am continually impressed with the quality of the package, but I have run into a problem with using PhongBitmapMaterial with PointLight3D.
(A similar question was posted upstream a little but didn’t get any answers, and didn’t seem to be quite the same issue anyway, so I’m trying again.)
The issue is that the Phong material doesn’t appear to respond to the light at all—it is just completely bright with no shading.
I’m running Flex 4.5.1 and have tried this using both the 3.6.0 release codebase and the latest trunk from svn. Attached is an .as file that demonstrates the issue.
Thanks for any help!
Edit:
The code attachment link doesn’t seem to work… is it supposed to?
Anyway here it is:
package test {
import away3d.cameras.Camera3D;
import away3d.containers.ObjectContainer3D;
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.core.utils.Cast;
import away3d.lights.PointLight3D;
import away3d.materials.PhongBitmapMaterial;
import away3d.materials.WhiteShadingBitmapMaterial;
import away3d.primitives.Sphere;
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.geom.Vector3D;
import flash.net.URLRequest;
import mx.core.UIComponent;
import mx.events.FlexEvent;
import spark.components.Application;
import spark.components.BorderContainer;
import spark.components.Label;
public class Away3DPhongTestApplication extends Application {
private static const BITMAP_PATH:String = “bitmap_file_path_here”;
private static const RADIUS:Number = 100;
private static const OFFSET:Number = 50;
private static const SEGMENTS_W:Number = 40;
private static const SEGMENTS_H:Number = 20;
private static const MARGIN:Number = 200;
private static const LIGHT_DISTANCE:Number = 23088;
protected var _phong_container:ObjectContainer3D = null;
protected var _phong_sphere:Sphere = null;
protected var _white_shading_container:ObjectContainer3D = null;
protected var _white_shading_sphere:Sphere = null;
protected var _lighting:PointLight3D = null;
protected var _view:View3D = null;
function Away3DPhongTestApplication() {
this.addEventListener(FlexEvent.CREATION_COMPLETE, this.handleCreation);
}
private function createStandardSphere():Sphere {
var new_sphere:Sphere = new Sphere();
new_sphere.radius = RADIUS;
new_sphere.segmentsW = SEGMENTS_W;
new_sphere.segmentsH = SEGMENTS_H;
return new_sphere;
}
private function handleCreation(creation:FlexEvent):void {
this.removeEventListener(creation.type, arguments.callee);
var bitmap_loader:Loader = new Loader();
bitmap_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleBitmapLoaded);
bitmap_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleBitmapLoadError);
bitmap_loader.load(new URLRequest(BITMAP_PATH));
}
private function handleBitmapLoadError(failed:IOErrorEvent):void {
this.removeEventListener(failed.type, arguments.callee);
var error_label:Label = new Label();
error_label.x = 10;
error_label.y = 10;
error_label.setStyle(“color”, 0xff0000);
error_label.text = failed.text;
this.addElement(error_label);
}
private function handleBitmapLoaded(loaded:Event):void {
this.removeEventListener(loaded.type, arguments.callee);
var event_target:LoaderInfo = loaded.target as LoaderInfo;
var loaded_bitmap:Bitmap = (event_target? event_target.content as Bitmap : null);
var child_holder:UIComponent = new UIComponent();
var phong_material:PhongBitmapMaterial = new PhongBitmapMaterial(Cast.bitmap(loaded_bitmap));
var white_shading_material:WhiteShadingBitmapMaterial = new WhiteShadingBitmapMaterial(Cast.bitmap(loaded_bitmap));
this._view = new View3D();
this._view.scene = new Scene3D();
this._view.camera = new Camera3D();
this._view.camera.z = -1000;
phong_material.shininess = 10;
white_shading_material.shininess = 10;
this._phong_sphere = createStandardSphere();
this._phong_sphere.material = phong_material;
this._white_shading_sphere = createStandardSphere();
this._white_shading_sphere.material = white_shading_material;
this._lighting = new PointLight3D();
this._lighting.x = Math.sqrt(Math.pow(LIGHT_DISTANCE, 2) / 2);
this._lighting.y = 0;
this._lighting.z = -Math.sqrt(Math.pow(LIGHT_DISTANCE, 2) / 2);
this._lighting.brightness = 20;
this._lighting.diffuse = 120;
this._lighting.specular = 10;
this._lighting.ambient = 0;
this._phong_container = new ObjectContainer3D(this._phong_sphere);
this._white_shading_container = new ObjectContainer3D(this._white_shading_sphere);
this._white_shading_container.x = this._phong_container.x + (RADIUS * 2) + MARGIN;
this._view.scene.addChild(this._phong_container);
this._view.scene.addChild(this._white_shading_container);
this._view.scene.addLight(this._lighting);
child_holder.x = RADIUS + MARGIN;
child_holder.y = RADIUS + MARGIN;
child_holder.addChild(this._view);
this.setStyle(“backgroundColor”, 0x000000);
this.addElement(child_holder);
this.addEventListener(Event.ENTER_FRAME, this.handleFrame);
}
private function handleFrame(ev:Event):void {
this._phong_sphere.rotationY += 1;
this._white_shading_sphere.rotationY += 1;
this._view.render();
}
} // class Away3DPhongTestApplication
} // package test