Why PointLight keep complaining null data parameter, full code and model attached

Software: Away3D 4.x

davy, Newbie
Posted: 23 November 2011 11:01 AM   Total Posts: 15

I guess something is wrong with my model, I export this obj model from blender, Thanks for any hints.

package
{
 import away3d
.cameras.Camera3D;
 
import away3d.containers.Scene3D;
 
import away3d.containers.View3D;
 
import away3d.controllers.HoverController;
 
import away3d.debug.AwayStats;
 
import away3d.entities.Mesh;
 
import away3d.events.AssetEvent;
 
import away3d.library.AssetLibrary;
 
import away3d.library.assets.AssetType;
 
import away3d.library.assets.IAsset;
 
import away3d.lights.PointLight;
 
import away3d.loaders.misc.AssetLoaderContext;
 
import away3d.loaders.parsers.Parsers;
 
import away3d.materials.BitmapMaterial;
 
import away3d.materials.ColorMaterial;
 
import away3d.materials.methods.BasicDiffuseMethod;
 
import away3d.materials.methods.BasicSpecularMethod;
 
 
import flash.display.Sprite;
 
import flash.display.StageAlign;
 
import flash.display.StageScaleMode;
 
import flash.events.Event;
 
import flash.events.MouseEvent;
 
import flash.utils.getTimer;
 
 public class 
LightTest extends Sprite
 {
  [Embed
(source="/../embeds/simpleland.obj"mimeType="application/octet-stream")]
  
private var Cube : Class;
  
  private var 
camera:Camera3D;
  private var 
scene:Scene3D;
  private var 
view:View3D;
  private var 
cameraController:HoverController;
  private var 
light:PointLight;
  private var 
cubeModel:Mesh;
  private var 
move:Boolean;
  private var 
lastPanAngle:Number;
  private var 
lastTiltAngle:Number;
  private var 
lastMouseY:Number;
  private var 
lastMouseX:Number;
  private var 
cubeMaterial:BitmapMaterial;
  
  private var 
diffuseMethod:BasicDiffuseMethod;
  private var 
specularMethod:BasicSpecularMethod;
  private var 
assetLoaderContext:AssetLoaderContext;
  private var 
colorMaterial:ColorMaterial;
  public function 
LightTest()
  
{
   super
();
   
init();
  
}
  
  
private function init():void
  {
   initEngine
();
   
initLights();
   
initMaterials();
   
initObjects();
   
initListener();
  
}
  
private function initMaterials():void
  {
   colorMaterial 
= new ColorMaterial(0x52c167);
//just can not enable this line, 
//   colorMaterial.lights = [light];
  
}
  
private function initLights():void
  {
   light 
= new PointLight();
   
light.200;
   
light.200;
   
light.color 0xff00ff;
   
scene.addChild(light);
  
}
  
private function initEngine():void
  {
   stage
.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
   
scene = new Scene3D();
   
camera = new Camera3D();
   
   
view = new View3D();
   
view.scene scene;
   
view.camera camera;
   
view.antiAlias 6;
   
   
cameraController = new HoverController(camera,null,45,10,1500);
   
   
addChild(view);
   
addChild(new AwayStats(view));
  
}
  
private function initListener():void
  {
   stage
.addEventListener(MouseEvent.MOUSE_DOWNonMouseDown);
   
stage.addEventListener(MouseEvent.MOUSE_UPonMouseUp);
   
addEventListener(Event.ENTER_FRAME,onEnterFrame);
  
}
  
private function initObjects():void
  {
   Parsers
.enableAllBundled();
   
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE,onAssetComplete);
   
assetLoaderContext = new AssetLoaderContext(true,'../embeds/');
   
   
AssetLibrary.loadData(new Cube(),assetLoaderContext);
  
}
  
protected function onAssetComplete(event:AssetEvent):void
  {
   
if (event.asset.assetType == AssetType.MESH){
    cubeModel 
event.asset as Mesh;
    
cubeModel.geometry.scale(100);
    
cubeModel.= -50;
    
cubeModel.material colorMaterial;
    
scene.addChild(cubeModel);
   
}
  }   
  
protected function onEnterFrame(event:Event):void
  {
   
if (move{
    cameraController
.panAngle 0.3 * (stage.mouseX lastMouseX) + lastPanAngle;
    
cameraController.tiltAngle 0.3 * (stage.mouseY lastMouseY) + lastTiltAngle;
   
}
   
   light
.Math.sin(getTimer()/10000) * 200;
   
light.1000;
   
light.Math.cos(getTimer()/10000) * 200;
   
view.render();
  
}
  
/**
   * Mouse down listener for navigation
   */
  
private function onMouseDown(event:MouseEvent):void
  {
   lastPanAngle 
cameraController.panAngle;
   
lastTiltAngle cameraController.tiltAngle;
   
lastMouseX stage.mouseX;
   
lastMouseY stage.mouseY;
   
move true;
   
stage.addEventListener(Event.MOUSE_LEAVEonStageMouseLeave);
  
}
  
  
/**
   * Mouse up listener for navigation
   */
  
private function onMouseUp(event:MouseEvent):void
  {
   move 
false;
   
stage.removeEventListener(Event.MOUSE_LEAVEonStageMouseLeave);
  
}
  
/**
   * Mouse stage leave listener for navigation
   */
  
private function onStageMouseLeave(event:Event):void
  {
   move 
false;
   
stage.removeEventListener(Event.MOUSE_LEAVEonStageMouseLeave);
  
}
 }

 

File Attachments
embeds.zip  (File Size: 6KB - Downloads: 188)
   

John Brookes, Moderator
Posted: 23 November 2011 11:17 AM   Total Posts: 732   [ # 1 ]

Your model probably doesnt have normals.
Either find a way to re export the model with normals or

set

yourMesh.geometry.subGeometries[0].autoDeriveVertexNormals

   

davy, Newbie
Posted: 23 November 2011 12:54 PM   Total Posts: 15   [ # 2 ]

Wow, it’s so nice you can answer this question so quickly and precisely

I found the way how to export obj with normals in blender here:

and the code above works like a charm

http://www.blender.org/forum/viewtopic.php?p=90925&sid=dbb2e3f3273671377e10d3117bf5caaf

thanks so much

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X