- Home /
loading mesh from .obj-file by script
Hi guys,
i need to create a prefab by script, the goal is to load a mesh from an .obj-file and attach a material to it. For example load the mesh out of model_wood.obj and automatically attach the material wood to it. I have already found this Link but i don't really understand it. Does anyone know a simple way to do this? My biggest problem is loading the mesh from an external file.
Thank you very much...
Answer by anonymousUser · Jul 30, 2012 at 07:01 PM
You can consider Starscene Software's Obj Reader (link) which is created for Unity specifically.
Or if you don't feel like spending bucks. You could Google some of the generic obj reader, like http://gitorious.org/objreader, since I think the Wavefront obj format isn't too complicated. However, you might need to spend some time to implement it in Unity in whatever language you're using.
Note that Unity provides script functions for us to create a GameObject from low level, ie constructing the mesh, adding uv mapping info and stuff. So once you've found your solution to parse/read the obj file and grab all the information about the mesh, you can pretty much reconstruct the GameObject in the scene.
Good luck!