Real time loading of .obj and .png

Software: Away3D 4.x

Monguron, Newbie
Posted: 21 November 2011 04:41 PM   Total Posts: 27

Hello,

Up to now I made an model viewer, which loads an object file and a texture.
I was using embed, but as I want to have the loading real-time, I need to load loader3D, or loaderAsset.

My aim is to give the filename of the object and the texture through flashvar, and then I can define in .php, which object and textures I want to load.—> then the swf file loads them.

Problems:
- how can I use the loader3D instead of Embed?
- how should I insert my variables (name of the object and the texture) into the .as code?

This is the actual code, which I should change somehow smile

package
{
 import away3d
.containers.View3D;
 
import away3d.debug.AwayStats;
 
import away3d.entities.Mesh;
 
import away3d.events.LoaderEvent;
 
import away3d.lights.PointLight;
 
import away3d.loaders.Loader3D;
 
import away3d.loaders.misc.AssetLoaderContext;
 
import away3d.loaders.parsers.OBJParser;
 
import away3d.materials.BitmapMaterial;
 
import away3d.materials.methods.BasicDiffuseMethod;
 
import away3d.materials.methods.BasicSpecularMethod;
 
import away3d.materials.methods.FresnelSpecularMethod;
 
import away3d.materials.methods.SubsurfaceScatteringDiffuseMethod;
 
import away3d.tools.Mirror;
 
 
import flash.geom.Vector3D;  
 
import flash.display.Sprite;
 
import flash.display.StageAlign;
 
import flash.display.StageScaleMode;
 
import flash.events.Event;
 
import flash.events.MouseEvent;
 
import flash.events.KeyboardEvent;

 
[SWF(width="400"height="320"frameRate="60"backgroundColor="0xffffff")]
 
public class sample extends Sprite
 {
  
private var _view View3D;
  private var 
_loader Loader3D;

  private var 
_light PointLight;
  
  
[Embed(source="/../embeds/model.obj"mimeType="application/octet-stream")]
  
private var OBJData : Class;

  
[Embed(source "/../embeds/model_diff.png")]
  
private var Albedo : Class;

  
[Embed(source="/../embeds/model_spec.png")]
  
private var Specular : Class;
  
  
//signature variables
  
private var Signature Sprite;

  
//signature swf
  
[Embed(source="/../embeds/DF_signature.swf"symbol="Signature")]
  
private var SignatureSwf:Class;
  
  private var 
_camController HoverDragController;
  private var 
_count Number 0;
  private var 
_subsurfaceMethod SubsurfaceScatteringDiffuseMethod;
  private var 
_diffuseMethod BasicDiffuseMethod;
  private var 
_material BitmapMaterial;
  private var 
_fresnelMethod FresnelSpecularMethod;
  private var 
_specularMethod BasicSpecularMethod;
     
  public function 
sample()
  
{
   _view 
= new View3D();
   
_view.antiAlias 4;
   
_view.backgroundColor 0x0f1010;
   
this.addChild(_view);

   
Signature Sprite(new SignatureSwf());
   
Signature.stage.stageHeight Signature.height;
   
   
addChild(Signature);
   
   
_light = new PointLight();
   
_light.15000;
   
_light.15000;
   
_light.color 0xffddbb;
   
_view.scene.addChild(_light);
   
//_camController = new HoverDragController(_view.camera, stage);
   
   //new camera
   
_view.camera.1100;
   
_view.camera.600;
   
_view.camera.0;
   
_view.camera.lookAt(new Vector3D(05000));  

   
//addChild(new AwayStats(_view));
   
initMesh();

   
addEventListener(Event.ENTER_FRAMEonEnterFrame);
   
stage.addEventListener(KeyboardEvent.KEY_UPonKeyUp);
   
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 initMesh() : void
  {
   Loader3D
.enableParser(OBJParser);

   
_loader = new Loader3D();
   
_loader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
   
_loader.parseData(OBJDatanull, new AssetLoaderContext(false));
   
_loader.0;
   
_loader.100;
   
_loader.0;
   
_loader.rotationX 90;
   
_view.scene.addChild(_loader);

   
_material = new BitmapMaterial(new Albedo().bitmapData);
   
_diffuseMethod = new BasicDiffuseMethod();
   
_specularMethod = new BasicSpecularMethod();

   
_material.specularMap = new Specular().bitmapData;
   
_material.lights [ _light ];
   
_material.gloss 10;
   
_material.specular 3;
   
_material.ambientColor 0xe3a471;
   
_material.ambient 1;
   
_material.specularMethod _fresnelMethod;  
  
  
}

  
private function onResourceComplete(event LoaderEvent) : void
  {
   
var mesh Mesh;
   for (var 
int 0_loader.numChildren; ++i{
   mesh 
Mesh(_loader.getChildAt(i));
   
mesh.geometry.scale(100);
   
mesh.material _material
   } 
  }   

  
private function onKeyUp(event KeyboardEvent) : void
  {
   _material
.diffuseMethod _material.diffuseMethod == _diffuseMethod _subsurfaceMethod _diffuseMethod;
  
//  _material.specularMethod = _material.specularMethod == _specularMethod? _fresnelMethod : _specularMethod;
  
}

  
private function onEnterFrame(ev Event) : void
  {
   _loader
.rotationY = -* (stage.mouseX stage.stageWidth 2);
   
_view.render();
  
}
 }

I tried to implement this:

loader = new Loader3D();
loader.load(new URLRequest("url"),  assetLoaderContext); 

... but I don’t know how to link it to the OBJData variable. Or even the other parts of the code (for example the parsing) should be changed?

Thanks for your help in advance!

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X