Aha, I understand now! The MTL file contains the UV mapping data. That was what I didn't understand. I found that L3DT (the terrain generator I'm using) only outputs this info in the pro version. I performed the mapping in Blender and did the output, with the MTL file, and it loads properly now (and now I see that the loader can import the texture as well, once I got all the pieces in the right place).
Thanks Rob and Pete for your great help! Dave p.s. charglerode: I've been following your issue as I was also trying to get an OBJ to load, so I can report now that if I have the OBJ, MTL, and JPG all in the same dir the loader works correctly with just Obj.load(myURL). I did verify that the MTL has a reference to the JPG texture in it. I did all of this as an OBJ export from Blender. Perhaps I can suggest trying to import the whole thing into a typical 3D utility, verifying it's working and exporting it again. I used that technique to hone in on my problems successfully (and now that I know what my problems were I can go back to steam line the workflow). From: [email protected] [mailto:[email protected]] On Behalf Of Rob Bateman Sent: Tuesday, July 28, 2009 12:51 AM To: [email protected] Subject: [away3d] Re: Newbie question: how to apply a texture to a mesh Since writing this I did get the texture to apply to the mesh using the BitmapFileMaterial (code below), but the entire JPG image is applied to each face independently rather than stretched smoothly across all faces. sounds like a classic case of missing uvs. even if you have them innblender, they may not be exporting correctly with the obj exporter. Is there an options panel you can check? Also in the near future there may be a chance Away3D has the ability to map your object for you if the UV isn't present, from different angles, (in your case top down), but you didn't hear that from me :) actually, that's already possible with transformBitmapMaterial and any material that inherits from it: var material:TransformBitmapMaterial = new TransformBitmapMaterial(myBitmap); material.projectionVector = new Number3D(0,1,0); material.scaleX = 0.1; material.scaleY = 0.1; material.repeat = true; give that a go and see if it improves matters. I'm assuming your terrain is oriented y-up, otherwise you may need to adjust the projectionVector values to get it correct. cheers Rob On Mon, Jul 27, 2009 at 4:48 PM, Peter Kapelyan <[email protected]> wrote: If your object doesn't have UV mapping, maybe try to load it into another program and apply a top down projection UV mapping to it. UV maps are triangles which tell you what part of the JPG or image to use for which triangles on the mesh. If the UV mapping isnt present, then Away3D will not know where to apply the jpg on your mesh. Being that it's a terrain you can get away easily by mapping it staright down from the top. If you have trouble applying a UV map to it, or checking if it exists in the first place, I do you the favor and check , and/or apply the UV map for you, but of course it would be better for you to find an app or process to apply the UV mapping to your models yourself. Also in the near future there may be a chance Away3D has the ability to map your object for you if the UV isn't present, from different angles, (in your case top down), but you didn't hear that from me :) -Pete On Mon, Jul 27, 2009 at 11:41 AM, David Parks <[email protected]> wrote: I'll be honest, I'm pretty new at everything 3D, so I'm not sure how to verify that my object "has UV mapping", I understand UV mapping, but don't follow what you are asking, or how to verify. I used a terrain generation app called L3DT which builds a terrain map & heightmap, and can export a mesh from the heightmap. I started by importing that mesh into blender, then loaded the JPG texture and applied it to the object in Blender. Everything looked perfect there, but not so good yet in the Away3D environment. Since writing this I did get the texture to apply to the mesh using the BitmapFileMaterial (code below), but the entire JPG image is applied to each face independently rather than stretched smoothly across all faces. Mesh(my3DLoaderObj.handle).material = myBitmapFileMaterial; I'm not clear if that's really the best approach (or even the right approach at all), and I must be doing something reasonably simple wrong to have the image apply independently to each face rather than across the entire mesh. Thanks! Dave From: [email protected] [mailto:[email protected]] On Behalf Of Peter Kapelyan Sent: Monday, July 27, 2009 7:45 PM To: [email protected] Subject: [away3d] Re: Newbie question: how to apply a texture to a mesh Are you sure your object has UV mapping? If so, a simple apply of any material would suffice. -Pete On Mon, Jul 27, 2009 at 3:30 AM, David Parks <[email protected]> wrote: Hi, I hate to ask simple questions, but, well, here goes. I have an OBJ mesh generated by the terrain generated L3DT, and I have a separate JPG texture map it generated. It does not generate an MRT file (I'm not familiar with what that is, but I have seen it mentioned in relation to OBJ files). As far as I can see the OBJ file has no reference to the JPG. I can import the OBJ mesh just fine, but I haven't found a good example of how to apply the texture. I just need to load the mesh and materials from a URL at runtime. But the Object3D provided by the loader only has a null-value MaterialsLibrary object which I haven't been able to work out how to use. Other examples only apply textures to primitives which all have a primObj.material attribute - unlike the Object3D in which the mesh is stored. Also I notice there's a TextureLoader class as well as a BitmapMaterialFile class. I don't understand if one is better to use over the other, or even if they do similar or different things (I haven't noticed any docs for TextureLoader). I have loaded the material into the BitmapFileMaterial class successfully, but haven't gotten that to apply to my Object3D mesh yet. If there's a document or tutorial that I missed I would love to know about it. I've been through the code examples and tutorials on away3d.com site so far and am still scratching my head. Thanks as always! David -- ___________________ Actionscript 3.0 Flash 3D Graphics Engine HTTP://AWAY3D.COM -- ___________________ Actionscript 3.0 Flash 3D Graphics Engine HTTP://AWAY3D.COM -- Rob Bateman Flash Development & Consultancy [email protected] www.infiniteturtles.co.uk www.away3d.com
