How to import fully 3D objects (Final post)

See here for a demo of how object data can be downloaded and viewed. It gets stored in Documents so it downloads only once.

@Ignatz. I have today downloaded your 3D Object viewer on CC. Very impressive. Thank you very much for the code.

The github version above has several models to choose from(and I will add more), try that

@Bri_G - I’ve settled on creating a textfile containing a list of point positions and vertices, that can be downloaded into Codea and saved to the documents folder. It can be read in from there, and loadstring used to activate the lists. This also means we can include anything we like in this textfile, eg texture mappings, normals and any code we want to run, giving us a lot of versatility.

The one thing that puzzles me is texture mappings, in particular how to store the images. Some models have a lot of little images, and I don’t want those cluttering the Documents folder of anyone running the models.

Hi @Ignatz,

Just downloaded your latest 3D viewer, using gist file/document file - superb, that’s the way to go. Like the new models. I assume that the models are vertices only as the colour data has been lost, or should I say fixed with shader lighting to give the perspective.

This certainly gives me a way forward - thanks for the code. You seem to have an excellent grasp of coding (and loadsa time to use it!!).

Thanks again.



@Bri_G - being recently retired helps :smiley:

Yes, all the models are vertices only, with some diffuse lighting. I was amused to find my algorithm for calculating normals works well most of the time, except on the teapot image, where it reverses them, so the inside is lit!! I also have one or two images with strange artifacts, but I’ll deal with those later.

Yes, I think this approach is extremely flexible and allows us to include all sorts of data and code for different models. Also, I’m hoping Codea can hold a lot more data in memory than it can in the code editor!

I’m scouting for all sorts of different models at the moment, but I’ll have to think about texturing next. I have a couple of ideas, but managing texture images is messy - perhaps the best approach is to approximate with straight colours where possible.

so how many verts can you handle? any chance of getting distance clipping and other tools for optimization, so we can use this for loading a 3d level map/scene?

HI @Ignatz,

Started playing with your code and tried to set up one of your models on my Gist depository, in a public Gist. But I keep getting an error from the loadstring(s)() saying that it gets a nil value. I think this may be because I am not putting in the correct address to the file. I am using :

which points to my Gist file page. I have tried adding raw etc like:


but it still fails.

I’ve never read from a Gist file directly before - is there a trick to this?



Yes, there’s a trick. When you’ve created your gist, look at the right of the header just above your text, you’ll see a link symbol, then < > . Press on the < > and you will get the raw text. Copy that URL.

Note that if you edit your gist and resave it, you need to do this again, because the raw text url will change too.

Note - I tried Dropbox and Google drive, and their links returned web pages rather than the raw text. That’s why I used gists.

@se24vad - I don’t know what the limits are, but I’m guessing they’re much greater than the editors limits.

It’s fairly easy to test. Just create a file with everything you want in it, including any code you want to run. Store it in a gist and get the link as described immediately above, and substitute for one of the links in my code. Then see if you can break Codea .

And if you can show me what some of these tools do, I’m happy to help test it…

As an aside, I notice that several of these models are not centred, ie 0,0,0 is not at the centre of mass, so rotation is uneven. I think I may have to calculate this and translate to it…

@Ignatz a bit of topic but congratulations on being retired!!! <:-P

I updated the project (on Github) with more models. The shuttle model has colouring based simply on splitting the model into 8 meshes, each with a different colour. This was based on the comments in the obj file.

I’ve tried to add the capability to touch the model on screen and see which vertex number you touched. This may give the ability to split the model into additional meshes or selectively colour certain vertices. At the moment, I don’t think it’s printing the correct vertex that was touched, though.

Very nice.

Hi @Ignatz,

Just a quick note - am now building up my own library of small simple models. Will release them when I get to know how to colour and wire-frame them, hopefully soon.

Just a simple note - wasted a lot of time when I fed in a bad model file (face and vertice data confused). Any changes seemed to have little effect, when I realised that the model loaded was the Document saved model with the corrupt file present.

I’m going to modify the code but may take some time to get it right. I intend having the app load a model up from the document folder when run. Then all other models to be downloaded from the Dropbox source so that changes can be tested. Also to put in a parameter option for ‘save’ or ‘no save’ so that when you load a new model it can be saved to documents if set (automatically resets to no save after the new model has been saved. This should help development and keep the Document folder tidy.

Hope to have this soon but my time is limited at the moment - home decoration!!




@Bri_G - hold your horses, I am writing a Codea project that stores and reads OBJ files (and the MTL files that come with them), and applies the correct colours to different parts of the model. At the moment I am working on also storing the texture images and applying texture coords as well.

Below is an example with shading applied according to the Obj file, before texturing.

If I can achieve this, then I can import and display any Obj file directly from Codea.

Hi @Ignatz,

Wow - I know you’re retired, so am I; but I don’t seem to be able to find the time to spend on these projects. Also when I do it takes me a while to digest resources and understand what’s required to produce the package. You’ve obviously got the right background and abilities.

I’ve started to use Blender but I recently found an excellent little package for model conversion. This should help anyone interested in this field. Look up:


Hope that helps you with the project, I’ve only just started playing with it but am finding it really useful.




@Bri_G - this took me all morning, but now I can read in an OBJ format image, including its texture mappings and images

This is a complex model, with 20 texture images and 65000 lines of settings, and it only runs at about 25 FPS.

There is a .obj and .mtl text files, which I’m storing as local data, and the texture images, which I’m storing in Documents. The important thing about both of these is that they can be listed or viewed in Codea, allowing manual editing. (If I stored the text files in Documents, then there would be no way to list them, and therefore no way to delete them unless you knew their names).

I’m going to try with some other images now…