Aplly new Material and light to a complex loaded object.

Software: Away3D 4.x

rgbox, Newbie
Posted: 03 October 2011 06:02 AM   Total Posts: 12

I’m loading a complex model made in Cinema 4d as .OBJ
Probably the geometry is not correct, but it can be rendered in 3D max.

After loading, I’m going to apply new material and a light to the loaded object.

Problems:
1. New Material is applied only to a fragment of the model. Not sure how to apply it to all.
2. When I add light (uncommenting the line), I get “RangeError: Error #3669:”

Can anybody help? Please!

package
{
 import away3d
.cameras.Camera3D;
 
import away3d.cameras.lenses.PerspectiveLens;
 
import away3d.containers.View3D;
 
import away3d.events.LoaderEvent;
 
import away3d.loaders.Loader3D;
 
import away3d.loaders.parsers.Max3DSParser;
 
import away3d.loaders.parsers.OBJParser;

 
import away3d.lights.DirectionalLight;
 
import away3d.lights.LightBase;
 
import away3d.lights.PointLight;

 
import away3d.materials.ColorMaterial
 import away3d
.materials.SegmentMaterial
 import away3d
.materials.methods.OutlineMethod

 import away3d
.entities.Mesh;

 
import flash.display.StageAlign;
 
import flash.display.StageScaleMode;

 
import flash.display.Sprite;
 
import flash.events.Event;
 
import flash.geom.Vector3D;
 
import flash.net.URLRequest;
 
[SWF(width="800"height="450"frameRate="60"backgroundColor="#ffffff")]



 
public class LoaderObject extends Sprite
 {
  
private var _view View3D;
  private var 
_container Loader3D;

  private var 
_light3 LightBase;


  public function 
LoaderObject()
  
{

   _view 
= new View3D();
   
_view.antiAlias 2;
   
_view.backgroundColor 0xffff00;
   var 
camera:Camera3D _view.camera;
   
camera.lens = new PerspectiveLens();
   
camera.800;

   
_light3 = new DirectionalLight(-1000000, -1000000, -1000000);
   
_light3.specular 0;
   
_light3.diffuse 0.3;
   
_light3.color 0xffffff;

   
_view.scene.addChild(_light3);

   
addChild(_view);

   
Loader3D.enableParser(OBJParser);

   
_container = new Loader3D();
   
_container.scale(10);
   
_container.addEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
   
_container.addEventListener(LoaderEvent.LOAD_ERRORonResourceLoadingError);

   
_container.load(new URLRequest('mymodels/wto.obj'));

   
_view.scene.addChild(_container);
   
_view.camera.lookAt(_container.position);
   
_view.camera.lens.far Vector3D.distance(_container.position_view.camera.position)+100000;
   
_view.camera.lens.near 10;

   
stage.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
stage.addEventListener(Event.RESIZEonStageResize);

  
}

  
private function onStageResize(event Event) : void
  {
   _view
.width stage.stageWidth;
   
_view.height stage.stageHeight;
  
}

  
private function onResourceComplete(away3d.events.LoaderEvent) : void
  {
   _view
.width stage.stageWidth;
   
_view.height stage.stageHeight;
   
this.addEventListener(Event.ENTER_FRAMEhandleEnterFrame);
   
setSub(_container)
  
}

  
private function setSub(Msh{
   
var mtr = new ColorMaterial(0x0000ff1)
   
mtr.ambientColor 0x0000ff

   
var nc Msh.numChildren
   
if (nc>0{
    
for (var i=0i<nci++) {
     
var subMesh Mesh(Msh.getChildAt(i));
     
subMesh.material mtr;
//           subMesh.material.lights=[_light3]
           
setSub(subMesh)
    
}
   }

  }

  
private function onResourceLoadingError(e:LoaderEvent) : void
  {
    trace
("oops, model load failed");
  
}

  
private function onResourceMapsLoadingError(e:LoaderEvent) : void
  {
    trace
("A map failed to load in this model: ["+e.url+"]");
  
}

  
private function handleEnterFrame(Event) : void
  {
   _container
.rotationY += .5;
   
_view.render();
  
}
 }

 

   

Avatar
theMightyAtom, Sr. Member
Posted: 03 October 2011 08:19 AM   Total Posts: 669   [ # 1 ]

Double post…

http://away3d.com/forum/viewthread/905/

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X