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_COMPLETE, onResourceComplete, false, 0, true); _loader.loadData(new Ship_obj()); _model = _loader; //.... private function onResourceComplete(e:LoaderEvent):void{ for(var i:int = 0; i < _model.numChildren; ++i){ var m:Mesh = (_model.getChildAt(i) as Mesh) if(m) m.material = _shipMaterial; }
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.
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.
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.
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