3D model loading from blender (PLY) and Suggestion: Need to load local files

As far as I remember, dxf 3d does not have texture coordinates and normals. the format is built upon the 2d dxf, so you also have lines, circles, arcs etc. in it.

Never heard of FBX before. It seems to be a proprietary format, so you can only read and write it with their SDK.

Hi @Phd - Fbx is a fantastic 3d interchange format for moving cameras, lights, animation channels and cached data (as well as geometry) from one 3d package to another within a VFX/CG pipeline.

Although from my experience implementing this is likely not to be trivial, as well as alot of its features being overkill for what most users currently can achieve within the real time 3D capabilities of Codea.

I suspect being able to import models, basic material definitions, textures and UV coordinates in a robust and efficient way via .obj or .ply seems a fairly sensible first step. :slight_smile:

As far as x3d I only implemented vertices, faces, colors and texture maps. Nothing else really was supportable in codea.

I’ll look into ply format, but I really hate blender - it’s too cumbersome to do simple stuff, but maybe it’s just me…

Ok, I’ll throw in my support for native .ply format if that is the simplest - keeping it simple is really what matters, since Codea is a tool that benefits from simplicity.

Guess I’ll go back to the drawing board and write a .ply reader/writer, too. KilamMailk, would you be amenable to sending me your read code for .ply files?

Yeah, Blender is a bit painful to learn… but when you got used to it, you are very fast :slight_smile: And there are tons of tutorials on YouTube.

I think, what John and andymac3d suggested to use OBJ would be best: It has the same limited feature set as PLY has, but it can be found as importer/exporter in nearly every 3d package. So maybe it would be better to do a obj reader now until it is done in codea.

My source is already referenced as link in the first post. its not a full ply reader, as i have simplified the header for my purpose.

Duh, missed the source!

Thanks @Fred, that worked perfectly. I just have to copy the ply to a lua file now and add the brackets. Tried it with the good old Stanford Bunny… it takes 15 seconds to parse and setup the mesh, but its nearly 70.000 triangles :slight_smile: Will be good for my game, I think my models will have about 500 to 1000 faces.

If you want to try it, here is the Bunny.lua and the texture for it. You have to change the main.lua in the first post to use that string and texture and change the camera a bit to display it larger.

https://dl.dropbox.com/u/80475380/CodeaForumPictures/Bunny.lua
https://dl.dropbox.com/u/80475380/CodeaForumPictures/standford_bunny.png

Yup, that bunny is a good one as a sample. It might be interesting to merge this with the code that does dynamic lighting to see how well the ipad can handle it as far as framerate. that would do away with the .png file. Curiosity more than anything…

So, sounds like I need to convert my models to .ply so I can be ready for Codea 1.5’s object load functions :slight_smile: … Did anyone put in an entry in the ideas bucket?

Ah I don’t know if we will have model loading in version 1.5 — there’s a lot of other features coming, and definitely some that will make meshes much more interesting, but I would like to take the time after 1.5 is released to really think about the best way to handle 3D models.

Did some research (sans wiki) and I came across this.

http://en.wikipedia.org/wiki/MeshLab

this part in particular may be of interest:
‘“MeshLab is available for most platforms, including Windows, Linux, Mac OS X, and, with reduced functionalities, on iOS and Android. The system supports input/output in the following formats: PLY, STL, OFF, OBJ, 3DS, VRML 2.0, U3D, X3D and COLLADA”’

Also check this out:
http://meshlab.sourceforge.net/

A multiplatform game engine such as Unity3d uses Fbx. It’s a very common expo format from all the main packages (max,maya,blender) and widely used.

Unity has tight integration with Maya/.fbx and currently has a far more sophisticated 3d engine than Codea. Hence, it may be tricky to implement some of the more advanced .fbx features (ie being able to export fully ‘rigged’ characters, blendshape animations, geometry cached data etc…) although I guess supporting a simplistic subset of the .fbx standard to allow geo and texture imports should be possible. Although, I guess this would defeat the purpose of using .fbx in the first place. I’d stick with a good old fashioned .obj importer at this stage. :slight_smile:

It seems like OBJ is a pretty popular request. I agree that FBX has a lot of advanced features and creating an importer for it may be more trouble that its worth. Stuff like rigging, blend shapes and such are pretty far outside the scope of mesh for the time being.

I agree with this completely. Although, it does start to raise a number of points relating to managing reasonably large 3d data sets, loading times and general performance issues as soon importing models becomes a common feature in Codea.

@John, on a similar note - when are we likely to see lights and some sort of very basic material properties (eg. lambert/blinn to simulate matte/glossy shading models) incorporated in Codea? I think this coupled with the ability to handle ‘Normal Maps’ (for surface detail/bumps) then really opens it up to develop some interesting creative possibilities - an .obj loader would then be the icing on the cake. :slight_smile:

.@andymac3d I’ll answer that for @John — next major release (1.5) will have those sorts of advanced features. We are going to start beta testing it soon.

@Simeon & @John - Nice one fellas!.

Is 1.5 likely to be out this side of Xmas? Exciting stuff :wink:

Exporting Blender objects to be used in Codea is for me a brilliant idea!
Will see if I can bring the files of post #1 to live on my Ipad ;-).

It depends what Codea will do in 1.5 with meshes (I have yet NO experience at all)

Maybe it is worthwhile to note that Blender’s latest versions use ‘polygons’ as faces for its 3D objects not only triangles and/or quad’s (thus more then 4 vertices in ONE face)

You have to triangulate in blender before you export if you want to use my loader. Its CTRL+T in mesh edit mode or you press Space and start typing “triangulate” until you see the command.

OBJ is a pretty easy lowest-common-denominator - I’ve written parsers for it, it’s pretty easy to deal with, and our meshes (to date) are fairly simple. I’d leave the more complex formats for when we have need of that complexity - as has been pointed out, Meshlab can convert between most formats, so if you have a COLLADA or something, you can drop the extra stuff and put out an OBJ for now.

In the long run, a meta-level above meshes would be nice - a full-on scenegraph model. At that point, you may want more complex formats with materials (OBJ has those already to a limited extent) and LOD and bones and who know what else. I want real lighting, I do. (I want three.js, really).

@KilamMalik You can do the same with Hash Animation Master. What you do is once you have a model you want to export you go to

File > Plug-ins > Export > Object Model (.OBJ)

Choose your polygons per patch. There’s even an option to generate model maps.

You want to click the Export only Triangles in mesh option

An MTL file will also automatically be created.

@aciolino, I have tested lighing calculation now. For the monkey (900 triangles) it takes 0.1 seconds, so only 10 fps possible. For the bunny (Nearly 70.000 triangles) its 7.7 seconds… no real time possible there :wink: Its fine for my current projects, I’ll do the calculation one time (non dynamic) or use the texture (which gives a more realistic static light with ambient occlusion) and wait for 1.5.

Screenshots for the “realtime” monkey and the one time bunny calculation: