Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Is it possible to import 3D models in Codea?

edited December 2012 in Questions Posts: 52

It's quite a hard work to code the mesh,I think.So I'm wondering are there any possibilities to import some 3D model(like .obj) modeling by GUI?It would be much easier to build a 3D program,specially a game.Can anyone helps?


  • Jmv38Jmv38 Mod
    edited December 2012 Posts: 3,295

    I wrote this program post for this purpose: easy loadin and sharing meshes... Does that fit your question? I am currently woarking on more advanced tools to build 3d objects and share them via this utility. Would you be interested?

  • Posts: 563

    I have been grappling with the same issue. Apparently @Xavier has put together a Blender model import to mesh function. I'm trying to work out if you can do something similar with Illustrator.

  • Posts: 666

    I have written a ply and x3d importer, so the answer to your question is yes, depending on the format.

  • Posts: 563

    .@aciolino - what do you recommend for drawing very simple models which can export as ply or obj? Blender?

  • edited December 2012 Posts: 666

    I use meshlab but it's buggy and cumbersome, though it does WONDERS for vertex and face reduction.

    I also use Google's sketch lab for buildings and some shrubs/trees.

    If you already know blender, use it. I don't use it because I'm no good with it.

  • Posts: 666

    Illustrator should output some 3d type...which ones?

  • Posts: 52

    .@aciolino.That's really cool.But where could I get it?

  • Posts: 666

    I have a gist for ReadPLY and WritePLY. Check out

  • Posts: 563

    Thanks @aciolino - I will give your ply reader a go. Illustrator looks to be a bust, it doesn't seem to have any useful 3d types. You can export as an autocad file but Im not sure if that is much use. I'm having a play with Blender - it is complicated but at least you cant complain about the price.

  • Posts: 666

    How did it work out?

  • Posts: 1,255

    I was a long time user of TrueSpace — long time as in starting over 20 years ago on the Amiga. Microsoft bought them out several years ago when a 3D modeling tool seemed like something all the big dogs were adding to their portfolio, then promptly closed them down. But it's still available on the web, and I'd highly recommend it for ease of use.

  • Posts: 563

    .@aciolino - I'm still trying to build my 3D model in Blender! Talk about a frustrating program. I'll have another go over the weekend. If that doesn't work I might have a play with TrueSpace.

  • Posts: 666

    Truespace or SketchLab. What kind of model are you trying to build?

  • Posts: 563

    .@aciolino - just a simple spaceship. I'm having problems with the mirror modifier. I got it working once but I'm not sure how I did it. I'm sure I will work it out and if not I'll try the other programs suggested. Blender reminds me of Gimp and Scribus when I first started using them.

  • edited December 2012 Posts: 563

    .@aciolino - ok I drew my space ship!

    Edit: Looks like your readPly class may need a bit of tweaking to get it to load a ply file from the iPad. The good news is that if I look at my ply file in a text editor its format is similar to your example file. I will see if i can use my Codea File Manager class to locate the file and load it using your ReadPLY class. I might even do a tutorial on it so others can do the same if that is ok?

  • Posts: 666

    I use my defereredloader and DropBox to do reads,but the code is set up so that you can bypass all that hooey.

    If that's the version without the deferredloader code (lne 18), just pass the string representation of the .PLY file to the constructor, so try this:

    obj = ReadPLY()

    The resultant obj file should have a collection of self.renderitems, which has a single entry, so self.renderitems[1] will be your mesh. The reason for this is because the code for X3D, which this is based off of, allows for a single file (X3D world) to containt multiple meshes. PLY doesn't do that so there's only one valid mesh.

    Note that if you have a texturefile and load this thing without the deferredloader, you won't get your texture file, and likely the renderer will fail becuase it expects one.

  • Posts: 563

    That sounds easier - trying now...

    I don't have any textures at this stage - I havent worked out how to attach a texture to the model yet.

  • Posts: 666

    Good luck.

  • Posts: 563

    All good - I have got my model displaying in Codea. Codea on the iPad 1 doesn't handle large files like the PLY model very well - I'm using a relatively small model (456 triangles) but it stretches over 1500 lines as a string in Lua. Codea crashes whenever I try and edit the model file. On the upside it renders very quickly.

    As an aside - I'm sure that there is a simple way to do this but it isn't obvious to me, how do you display your mesh as a wireframe? I'm not using any textures and the model lacks definition.

  • edited December 2012 Posts: 666

    Can't do wireframe (thinking of a way to do it, true wireframe vs. a triangle pair texture mesh). See

    Also, read the file from an external source instead of loading it as a big string...yes, Codea editor tends to crash the way you did it, which is why I wrote a file loader long ago :)

  • Jmv38Jmv38 Mod
    edited December 2012 Posts: 3,295

    @reefwing to draw a mesh as a wireframe i have 2 methods:
    .1. Draw all the ines in a trnsparent texture image, and use it.
    .2. Use a small texture image with a triangle drawn, und apply the textCoords of the 3 corners to all the triangles of the mesh.
    Here is some parts of code for method1:

    -- first create image         self.img = image(1000,500)         setContext(self.img) pushStyle()         background(0,0,0,0)         setContext() popStyle() -- then apply this to all triangles: function MeshTexturer:createWireFrame(k,ms,w,h,img)     -- prepares the shadow image     local v1,v2,v3         -- get triangle vertices         v1 = ms:texCoord(k+1)         v2 = ms:texCoord(k+2)         v3 = ms:texCoord(k+3)         -- draw lines         line(v1.x*w, v1.y*h, v2.x*w, v2.y*h)         line(v1.x*w, v1.y*h, v3.x*w, v3.y*h)         line(v3.x*w, v3.y*h, v2.x*w, v2.y*h) end

    Make sure you use ms:texCoords() and not ms.texCoords[] to read it, because y is 1-y in the memory.

  • @Reefwing, I have tried models with 900 triangles up to 69.000 triangles and were done with PLYs inside a LUA source. I can't edit them, but I just copied them into the project with my PC. Have a look here at the screenshots and code:

    I use blender, because I can create lightmaps there and don't need lighting calculation for the model. Will work for sure with other modellers too, but I got used to it ;-) I have implemented lighting calculation too, but it takes pretty long for the 69k triangles model.

    The PLY loader is very simple, it can only load triangles, but it was enough for me. I hope, that Codea will implement a model loader in the next versions. There is also a discussion about future model loading in Codea and about the formats to be used in that post.

Sign In or Register to comment.