Thanks Fabrice Turns out I had to use:
var mesh1:Mesh = (obj1 as ObjectContainer3D).children[0]; even though they are single seperate obj files (there is a g tag in the files I missed, so) Still no luck with with making the various objects' visibility true/ false using a button but I'll start a new thread for that. On Apr 24, 2:11 pm, Fabrice <[email protected]> wrote: > You now access with the wrong type. obj1 is Object3Dloader, it holds > the handle property which is an Object3D. > The Object3D, obj1object3D holds no property handle that's why you get > this error. > if you do: > > private function onLoaderSuccess(e:LoaderEvent):void > { > obj1 = e.loader.handle; > var mesh1:Mesh = obj1 as Mesh; --> no g tag in file single mesh > or > var mesh1:Mesh = (obj1 as ObjectContainer3D).children[0]; --> if you > > have a mesh in a group, tag g. > //but beware, since children[0] can also be an objectConatiner3D.... > > > } > > you should get no error... > > since you have also saved the instance Object3dLoader as obj1 > you also can access after its loaded like this: > > var mesh1:Mesh = obj1.handle as Mesh; --> no g tag in file single mesh > or > var mesh1:Mesh = (obj1.handle as ObjectContainer3D).children[0]; --> > > if you have a mesh in a group, tag g. > > Look inhttp://away3d.com/livedocs/on Obj class there is an example. > To write a little parser that works on any loaded objects, look into > Weld class or mirror class to see how its done. > > Fabrice > On Apr 24, 2009, at 8:48 PM, jojo wrote: > > > > > > > I went ahead and did this instead and did not get the same error > > anymore: > > > private var obj1:Object3DLoader; > > private var obj1object3d:Object3D; > > > obj1 = Obj.load("assett/teapot_1.obj", { material:material } ); > > > obj1.addOnSuccess(onLoaderSuccess); > > > private function onLoaderSuccess(e:LoaderEvent):void > > { > > obj1object3d = e.loader.handle; > > } > > > Now I have the handle (obj1object3d) to the read-in .obj, correct? > > > When I try: > > > private function onLoaderSuccess(e:LoaderEvent):void > > { > > obj1object3d = e.loader.handle; > > var mesh1:Mesh = obj1object3d as Mesh; > > trace(mesh1.handle is mesh); > > } > > > I get following errors: > > > 1119: Access of possibly undefined property handle through a reference > > with static type away3d.core.base:Mesh. > > 1120: Access of undefined property mesh. > > > On Apr 24, 5:38 am, Fabrice <[email protected]> wrote: > >> your loader "obj1" might not be declared... > > >> Also make sure it's a Mesh instance when you do not have the error > >> anymore.. > >> trace(obj1.handle is Mesh); > >> if not you'll get another error. If the handle is indeed a single > >> Mesh > >> object exported as obj and there is no g tag in the file, then the > >> code will run ok. > > >> Fabrice > > >> On Apr 24, 2009, at 11:49 AM, jojo wrote: > > >>> Thanks for the response, Fabrice :) > > >>> obj1.visible=false; ... Ah very good and should have been obvious to > >>> me ... I feel a bit silly ... > >>> tried it but didn't work but I think that is because button isn't > >>> working ... I'll get it working > > >>> All single meshes for now ... so I tried: > > >>> private var obj13d:Object3D; > > >>> obj1 = Obj.load("assett/teapot_1.obj", { material:material } ); > > >>> obj1.addOnSuccess(onLoaderSuccess); > > >>> private function onLoaderSuccess(e:LoaderEvent):void > >>> { > > >>> var mesh:Mesh = obj1.handle as Mesh; > >>> trace(mesh.vertices.length); > >>> } > > >>> but got compile "output": > >>> TypeError: Error #1009: Cannot access a property or method of a null > >>> object reference. > >>> at Basic_Cube/onLoaderSuccess() > >>> at flash.events::EventDispatcher/dispatchEventFunction() > >>> at flash.events::EventDispatcher/dispatchEvent() > >>> at away3d.loaders::Object3DLoader/notifySuccess() > >>> at away3d.loaders::Object3DLoader/onParserComplete() > >>> at flash.events::EventDispatcher/dispatchEventFunction() > >>> at flash.events::EventDispatcher/dispatchEvent() > >>> at away3d.loaders::AbstractParser/notifySuccess() > >>> at away3d.loaders::AbstractParser/parseNext() > >>> at away3d.loaders::Object3DLoader/startParsingGeometry() > >>> at away3d.loaders::Object3DLoader/onGeometryComplete() > >>> at flash.events::EventDispatcher/dispatchEventFunction() > >>> at flash.events::EventDispatcher/dispatchEvent() > >>> at flash.net::URLLoader/onComplete() > > >>> Do I have obj13d as the mesh or is that output saying something > >>> else? > > >>> Sorry for all the low level questions ... btw I'm excited to be > >>> "trying" to learn away3d because I've read so many things about it. > >>> Good job! > > >>> On Apr 24, 12:35 am, Fabrice <[email protected]> wrote: > >>>> Hi Jojo, > >>>> You need to save the Object3DLoader.handle object instead of the > >>>> Object3DLoader itself. > > >>>> the handle is the loaded geometry as Object3D > >>>> for the obj format this means it can be an ObjectContainer3D, > >>>> most of > >>>> the time because you grouped meshes into your editor, (G tag into > >>>> the > >>>> obj file) > >>>> Mesh(es) or both. So you need to parse the handle according to your > >>>> 3D > >>>> object (obj file). > > >>>> for instance on onLoaderSuccess > >>>> the obj1.handle Object3D can be a Mesh or an ObjectContainer3D > > >>>> If the obj file contains just a single mesh, you can access the > >>>> geometry information like this: > >>>> function addOnSuccessresult > >>>> var mesh:Mesh = obj1.handle as Mesh; > >>>> trace(mesh.vertices.length); > >>>> mesh.material = somenewMaterial; > > >>>> while if the obj file is a group of meshes the above code would > >>>> generate an error, since the handle is not a Mesh but an > >>>> ObjectContainer3D > >>>> trace("there are "+obj1.handle.children.length+" objects in > >>>> this > >>>> file"); > >>>> var mesh:Mesh = (obj1.handle as > >>>> ObjectContainer3D).children[0]; > > >>>> If you have variable structure and you want to automate, just add a > >>>> recursive parsing on loaded success, > >>>> Take a look in Weld class, Mirror class code to see how its done. > > >>>> hiding an object is as simple as adding the property visible true/ > >>>> false to it. > >>>> when set to false, the object is ignored by the engine for the > >>>> rendering. > > >>>> Welcome to Away! > > >>>> Fabrice > > >>>> On Apr 24, 2009, at 6:26 AM, jojo wrote: > > >>>>> Hello, > > >>>>> I'm new to oop, flash, and away3d but trying hard reading > >>>>> examples,etc ... just can't get mind around certain concepts ... > > >>>>> Couple questions ... > > >>>>> Suppose I read in an exported .obj file (textures come in fine) as > >>>>> such: > > >>>>> import away3d.loaders.Obj; > > >>>>> public var obj1:Object3DLoader; > > >>>>> var material:BitmapFileMaterial = new BitmapFileMaterial > >>>>> ("bitmap1.jpg"); > > >>>>> obj1 = Obj.load("teepot1.obj", { material:material } ); > > >>>>> All good to that point ... > > >>>>> 1. How do I get access to mesh vertices to be able to manipulate > >>>>> obj1? > >>>>> I know it's mesh.vertices but all examples I've seen just don't > >>>>> make > >>>>> sense (not sure the basic setup). Could I get a little extra > >>>>> clarification as to where to begin having obj1 in hand? > > >>>>> 2. If I then read in another obj file (which I verified can be > >>>>> read in > >>>>> and texture file is ok) how do I switch back and forth displaying > >>>>> one > >>>>> or the other? > > >>>>> I've tried: > > >>>>> if (objtoload=2) { scene.addChild(obj2);scene.removeChild(obj1); } > > >>>>> via a button handler but I get the original obj and then a cube of > >>>>> some sort with a texture of text saying "Loading Geometry ..." > >>>>> over > >>>>> top of original obj ... > > >>>>> using Flash CS4 (demo), away3D 3.3.3, btw > > >>>>> Thanks- Hide quoted text - > > >>>> - Show quoted text -- Hide quoted text - > > >> - Show quoted text -- Hide quoted text - > > - Show quoted text -
