Hi Rob!

I'm setting the material as you are saying, on the Obj parse before it
is used on an
obj file. And everything works fine.

Once the obj file is loaded I cannot change the material.

This is what I do:

private function loadModels(matURL:String):void {

  objParser = new Obj();
  objParser.material = new BitmapFileMaterial(matURL); // works good,
there is material on loaded obj file

  loader = new Loader3D();
  loader.addOnSuccess(onSuccess);
  loader.loadGeometry("my.obj", objParser);

}

function onSuccess(event:Event):void {

  _sceneMesh = loader.handle as Mesh;
  _sceneMesh.scale(100);
  _sceneMesh.rotationY = 180;
  _sceneMesh.ownCanvas = true; //all props work
  scene.addChild(_sceneMesh);

  loader.removeOnSuccess(onSuccess);

  MonsterDebugger.trace(this, _sceneMesh.material); //
WireColorMaterial (say what? ;) )
  MonsterDebugger.trace(this, _sceneMesh.materialLibrary); //null

  MonsterDebugger.trace(this, objParser.material); //
BitmapFileMaterial
  MonsterDebugger.trace(this, objParser.materialLibrary); //
MaterialLibrary (matFileName = null; mtlLoadRequired = false;,
textureLoadRequired = false; texturePath = null) only these props,
nothing more

  _sceneMesh.material = new WireframeMaterial(0xff0000); //does
nothing
  objParser.material = new WireframeMaterial(0xff0000); //does nothing

}

I cannot do:
myObject.materialLibrary.getMaterial("myMaterialName").material =
myNew Material
because myObject.materialLibrary = null

Also, this is null:
objParser.materialLibrary.getMaterial("myMaterialName") = null

I'm using Lightwave as exporter of obj, maybe here is the problem?
maybe my obj are incorrect?

Greetz
Paul

On 2 Lip, 14:13, Rob Bateman <[email protected]> wrote:
> Hey Pawel
>
> if you can't get an mtl file for your obj, then you can always try
> overriding your materials with a single material for the entire obj file.
>
> the material property on the Obj parse can be set before it is used on an
> obj file. With this in place, all materials encountered in the file use this
> material definition. So you can set it to BitmapMaterial, ColorMaterial...
> whataver you want
>
> Once an obj file is loaded, the materialLibrary property on the parser or
> the returned away3d object hold the names of all materials defined in the
> obj format. If you want, you can set the material of each individually by
> doing something like:
>
> myObject.materialLibrary.getMaterial("myMaterialName").material = myNew
> Material
>
> This approach will preserve multiple materials in an obj loaded file
>
> hth!
>
> Rob
>
>
>
>
>
> On Fri, Jul 2, 2010 at 11:43 AM, Michael Iv <[email protected]> wrote:
> > Let' me explain you.When you export obj with material on it from 3d
> > modelling program there is additional file being generated that is mtl .It
> > holds references to materials and textures.If you have one then the texture
> > will get loaded even automatically.That is the way .obj format works
>
> > 2010/7/2 Paweł Stanisławczuk <[email protected]>
>
> > Hi!
>
> >> I'm not using MTL, never did, they are not required. Don't think MTL
> >> have any connection with my problem.
>
> >> Paweł
>
> >> On 2 Lip, 12:01, Michael Iv <[email protected]> wrote:
> >> > Do you know that you need to have also MTL file with obj material
> >> > definitions?
>
> >> > Sent from my iPhone
>
> >> > On Jul 2, 2010, at 12:49 PM, Paweł Stanisławczuk
> >> <[email protected]
>
> >> > om> wrote:
> >> > > What is the proper way to apply material on loaded obj model?
>
> >> > > Obj loads good, everything works OK. I'm loading material this way:
>
> >> > > initO:Object = {useGroups:false};
> >> > > var obj:Obj = new Obj(initO);
> >> > > obj.material = new BitmapFileMaterial("res/uv.jpg"); //this is the
> >> > > only one spot where the material can be applied
>
> >> > > loader = new Loader3D();
> >> > > loader.addOnSuccess(onSuccess);
> >> > > loader.loadGeometry("res/my.obj", obj);
>
> >> > > function onSuccess(event:Event):void {
>
> >> > >  mesh = loader.handle as Mesh;
> >> > >  mesh.scale(100);
> >> > >  mesh.rotationY = 180;
>
> >> > >  scene.addChild(mesh);
> >> > > }
>
> >> > > The only place (AFAIK) to apply material on loaded obj file is the var
> >> > > obj:Obj parser. I tried to change material:
>
> >> > > loader.handle.material = new WireframeMaterial(0xff0000);
>
> >> > > But it does nothing.
>
> >> > > I tried with:
> >> > > function onSuccess(event:Event):void {
> >> > >  initO:Object = {useGroups:true};
> >> > >  var obj:ObjectContainer3D = (event.target.handle as
> >> > > ObjectContainer3D);
> >> > >  mesh = obj.children[0] as Mesh;
> >> > >  mesh.material = new WireframeMaterial(0xff0000);
> >> > > }
>
> >> > > Nothing.
>
> >> > > I also have tried this:
> >> > > var meshfaces = _sceneMesh.faces;
> >> > > for each (var i:Face in meshfaces.faces) {
> >> > >    i.material = new ColorMaterial(0xFF00FF);
> >> > > }
>
> >> > > Still nothing.
>
> >> > > I always used:
>
> >> > > var _objLoader:Object3DLoader = Obj.load(_resourceURL,
> >> > > {material:_material, name:"OBJ", scaling:10});
>
> >> > > But now as I see its obsolete.
> >> > > I cannot use AWD because client would like to add models on his own.
>
> >> > > Regards
> >> > > Paweł
>
> > --
> > Michael Ivanov ,Programmer
> > Neurotech Solutions Ltd.
> > Flex|Air |3D|Unity|
> >www.neurotechresearch.com
> >http://blog.alladvanced.net
> >http://www.meetup.com/GO3D-Games-Opensource-3D/
> > Tel:054-4962254
> > [email protected]
> > [email protected]
>
> --
> Rob Bateman
> Flash Development & Consultancy
>
> [email protected]

Reply via email to