material problem.

Software: Away3D 3.x

Zcgiworks, Newbie
Posted: 03 February 2012 11:03 AM   Total Posts: 9

hello,

i parsed an obj file

cubeMesh2 = Obj.parse((modLoader.data), { z: 10, useMtl:false } );

i tried to apply a material to this model but it is not working

cubemesh2.material is not working becuase it is of object3d type instead of mesh

i am really stuck at this, could some one suggest a solution.

   

Stephen Hopkins, Sr. Member
Posted: 05 February 2012 11:53 PM   Total Posts: 110   [ # 1 ]

This is how I handled applying materials to Objs. It may not be the best or cleanest way but it worked for me

[Embed (source="../../embed/shipnegz/shipnegz.obj"mimeType="application/octet-stream")]
public static const Ship_obj:Class;
//.....
_loader = new Loader3D();  _loader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceCompletefalse0true);
_loader.loadData(new Ship_obj());
_model _loader;
//....
private function onResourceComplete(e:LoaderEvent):void{
for(var i:int 0_model.numChildren; ++i){
 
var m:Mesh = (_model.getChildAt(i) as Mesh)
 if(
m)
  
m.material _shipMaterial;
 Signature 

http://www-scf.usc.edu/~shopkins

   

Zcgiworks, Newbie
Posted: 06 February 2012 07:13 AM   Total Posts: 9   [ # 2 ]

i have problem with the code.
i want different models to be loadedaccording to user inputs so the models have to be loaded.

model = new URLRequest(“http://localhost/flash/models/3dfold.obj”);
modLoader.load(model);
modLoader.addEventListener(Event.COMPLETE, initObjects);

private function initObjects(event:Event):void
{

var TemplateModel : Mesh = Obj.parse((modLoader.data), { z: -200 , useMtl:false } ) as Mesh;
var testMaterial:ColorMaterial = new ColorMaterial(“1E90FF”);
TemplateModel.material = testMaterial;
scene.addChild(TemplateModel);
}

the model loads fine but for some reason i am not even able to put a simple color material to the object. the model does not update with the colormaterial it shows the same wire material.
is there any problem with the code.

   

Stephen Hopkins, Sr. Member
Posted: 06 February 2012 09:07 AM   Total Posts: 110   [ # 3 ]

if you looked at my example, the obj I got was actually an objectContainer3D, so I applied the material to each of its children.

 Signature 

http://www-scf.usc.edu/~shopkins

   

Zcgiworks, Newbie
Posted: 07 February 2012 04:50 AM   Total Posts: 9   [ # 4 ]

for some reason
cubeMesh.numChildren
and
cubeMesh.getChildAt(i)
is not working.. i have been stuck at that…
any suggestions??
i upgraded to flex 4.6 but its still not working.

   

Stephen Hopkins, Sr. Member
Posted: 07 February 2012 05:04 AM   Total Posts: 110   [ # 5 ]

sorry, those features might only be available in away3d 4.0, in which case i would suggest you try to upgrade your project as away3d 4.0 is much faster.

 Signature 

http://www-scf.usc.edu/~shopkins

   

Zcgiworks, Newbie
Posted: 07 February 2012 05:56 AM   Total Posts: 9   [ # 6 ]

thnks for the advice i will try to convert to away3d 4.0.
will i have to change the code a lot when porting to 4.0
i would like to know that as well.

   

Stephen Hopkins, Sr. Member
Posted: 07 February 2012 06:35 AM   Total Posts: 110   [ # 7 ]

Yes, there are some api changes, but I think the upgrade is worth it. Of course if you have a very large code base to convert, then you might reconsider. Away3D 4.0 also requires flash player 11 which not everyone has. That is also something to consider.

 Signature 

http://www-scf.usc.edu/~shopkins

   

Zcgiworks, Newbie
Posted: 07 February 2012 08:06 AM   Total Posts: 9   [ # 8 ]

Is there any way to change the material of a parsed object i tried many different format but i am unable to do so..
is there any way to overcome this..

   

Stephen Hopkins, Sr. Member
Posted: 07 February 2012 10:06 AM   Total Posts: 110   [ # 9 ]

If i remember, in 3.6 there might be a material property

Obj.parse((modLoader.data), {material:yourMaterial, z: 10, useMtl:false } );

 Signature 

http://www-scf.usc.edu/~shopkins

   

Zcgiworks, Newbie
Posted: 07 February 2012 11:59 AM   Total Posts: 9   [ # 10 ]

hi stephen,
what you suggested is still not working.
is there a way to completely remove the material and apply again??

   

Zcgiworks, Newbie
Posted: 09 February 2012 09:02 AM   Total Posts: 9   [ # 11 ]

finally it is working..
i had to change the format to awd through prefab to bring it to away3d 3.6
and everything worked fine.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X