How to import fully 3D objects (Final post)

Hi @Ignatz,

Amazing !!!

The work that goes into these models is staggering - the detail and complexity. Got to congratulate you on understanding both the model itself and the ability to put this into Codea =D> =D> =D> .

When you say local data, and editing it, I assume you mean placing it in a Tab? Wouldn’t it be better loading from the remote file and editing on a PC/Mac. I find the editing with Codea on large files slow and messy.

25 FPS sounds good for the amount of data handled - what iPad version and OS are you using? Is there any scope for streamlining your code I usually find my initial code a little bloated and inefficient and can usually find faster alternatives - but in this case it’s probably just the sheer level of data.

Apart from the CPU, buses and ram speeds in the newer pads - have there been any additional improvements in the graphic processors so that the pipelines are faster and more efficient. It would be interesting to compare FPS on different systems.

Are you planning another Codea report on how to display models? Seems like you’ve done the groundwork.

The different model formats generally appear to have all the same data in - have you looked at different file formats? Are you reading in the actual files or have you extracted and compacted the data from them. If so you may find the 3DRACS useful.

Finally - morning! Where are you based it’s 08:18 here in the UK, my mornings only just beginning.

Thanks again,

Bri_G

=D>

@Bri_G - I’m in Perth Australia, 8 hours ahead of you.

What I mean by local data is the command saveLocalData, which can be used to save strings to the iPad hard disk. This is ideal for the .obj and .mtl text files. There is also a command to list all stored strings, which is important because there is a tendency to get messy and lost track of all the stuff you’ve stored.

I’m using an iPad 3 on iOS7. I’m sure I can find some performance improvements, but all I’m doing is replicating the instructions in the data files to create textured meshes, and some of them have tens of thousands of vertices.

I’m storing the original .obj, .mtl and image files, and not compacting them. This provides much greater flexibility in importing new models (no need to pre-process them), but may cause some delay in loading each model, of course. Compacting can come later if need be.

I haven’t looked at all the model formats, just .obj, but that one is quite logical and (generally) not too complicated.

I will do a post(s) on this, as soon as I feel I have mastered it. I’m still wrestling with little issues, like models that don’t work, or some vertices that vibrate. I’ll load a few more models and when I think it’s reasonably stable, I’ll share the code. (If I can get a couple of little quirks sorted out, I’ll send it to you soon).

Hi @Ignatz,

Thanks for the update - so you’re a working day ahead of me, explains your rapid progress.

On the vibrating vertices - is this down to overlapping faces? I think your first model showed this in the engine housing - (looked a bit like a circular spacecraft) as the object rotated you could see a flickering. I think this may be due to the algorithm for drawing the faces in the correct depth order. Saw something about it on a WebGL course - I’ll try to find it to see how you can resolve it.

I’ve probably got a model junkyard on my pad’s disk now - I’ll have to tidy it up. I use iExplorer for that. Perhaps @Simeon could include a simple file command structure in the next big release of Codea - ‘Son of Codea’. Ooops better not get into the naming game here - there’s a thread on that now - my preference is ‘Codea’.

Thanks,

Bri_G

:))

@Bri_G - the flickering is most probably caused by overlapping (or too close) faces, wrong z order, or misreading the vertex points in some way. I got a good dose of that when I was learning to build 3D scenes! I’ll look at it soon.

@Bri_G - try the code below. It contains specs for 6 models, but none of the data. That is downloaded on demand (the first time) and then stored on the iPad.

https://gist.github.com/dermotbalson/7871147

Choose a model with the slider at the top and press Load, then wait for the files to download. The model should then show itself (you can zoom in and out).

Don’t try model #5, it doesn’t work (yet).

When you’re done, there’s a button at the bottom of the parameters to delete all the downloaded files for whatever model is selected at the top.

wrt the flickering on #6 (shuttle), it might also be because some obj files define “faces” with more than 3 vertices (ie polygons). What I do is calculate the average of all the face positions, then create a triangle between each pair of points and this average. Possibly this is responsible for the flickering, but I don’t know yet.

@Ignatz You mentioned above that if you store files in Documents, you have no way to list them, so you store information with saveLocalData. The bad part of that is, if you saveLocalData in a project and then delete that project, that local data is still there and there’s no way to see it unless you create another project with that same name. You have to clearLocalData before deleting the project. So if you create test projects and save these large obj file as local data and then delete those test projects, you can have a lot of memory tied up without a way to clear it unless you remember the project names that created them. The same thing goes for project data.

@dave1707 - well, I’m open to suggestions!

Why not use global data? That way you can always go back and remove it, or use it in other projects

@Ignatz I’m not saying don’t use local or project data, just remember to clear it if you’re going to delete the project. Like @JakAttak, I always use global data for saving things. That way I don’t have to remember to clear anything when I delete projects. Every now and then I’ll run a programs that lists all of the global data and let me delete what I don’t want anymore.

Hi @Ignatz,

Ran your latest program - seemed to have it just about nailed. Interesting issue on global data, I never considered that - only used global data occasionally.

@dave1707 - could you point us to the way we should be managing our data, what is the app you run to check global data? Is it within Codea or external.

Thanks guys, learning a lot at the moment.

@Ignatz the viewer is now almost perfect, gonna try it with some simple models and I’ll feed back any findings.

Thanks,

Bri_G

=;

@Bri_G There really isn’t any special way to manage the data. I just wanted to point out that if you don’t clear any local or project data before deleting the project, then that data will still be there. There isn’t any way to remove it if you don’t remember the original project name. As for the program for global data, that’s all it is. It just lists the global data and allows you to delete what you don’t want. Not clearing small amounts of local/project data won’t matter that much, but the size of the data that @Ignatz is saving could take up a large amount of memory if it’s not cleared and you delete the project thinking it’s gone.

I’ll change it to use global data, I have no problem with that.

I’ve stuck with vehicle models so far, because unlike living things, they don’t change shape, which makes animation just too hard. It’s possible that we can model flying or racing or space 3D games with models like these.

As a footnote to these discussions (and the brilliant work done by @Ignatz) it’s worth mentioning that generally .obj models found on the interweb tend to be geared more towards 3d packages for use within pre-rendered sequences. Obviously, the vertex/poly counts quickly go through the roof for these more detailed models and need to be used with a bit of caution, especially if they are to be used as the basis of some sort of game within Codea.

Ideally, (as most game devs will testify) there’s really no substitute for good, efficiently built, low-poly models with good quality textures and bump/normal-maps used to add detail.

I think this is even more pertinent with Codea due to some of the technical/performance constraints mentioned previously.

:slight_smile:

@andymac3d - actually, most of the models I’m finding come from other formats like 3DS. I’m using Blender to convert them. I agree with the need to use low poly models, though!!

Hi @Ignatz,

Following up on the last couple of comments I tried three simple models - basic .obj with vertices, faces and colours for faces. They are valid files readable by Blender.

There is no .mtl file or images for UV mapping - so minimal size and requirements.

Wouldn’t load - error with first part of Asset loading. I’m assuming you don’t test for presence of .mtl files and ignore if not present. Files here:

Adder.obj - Adder ship

CobraFS.obj - Cobra ship

Coriolis.obj - Coriolis Station

I intend looking at shading these models before UV mapping, so I can show all levels of 3D modelling. They are three of the ships from the Elite game on the BBC (and others).

Could you point out which parts of your code I need to amend to load these - delving into other peoples code can take some time - the pointers would help.

Thanks,

Bri_G

:slight_smile:

@Bri_G - actually, my code does require an mtl file. Where it is missing, I’ve been making a simple one. I can of course modify the code so it doesn’t have to have an mtl file, but I’m juggling several issues at the same time, and that hasn’t been a priority.

However, I’ve begun combining the mtl and obj files into one, and specifying image URLs in the mtl section, which means that all you need, to specify a model in Codea, is the url of the mtl/obj file. It shouldn’t be hard to make the mtl part optional, but as I say, there are tricky little issues to sort out, and models that don’t behave as you would expect. All of that takes time to resolve, so I think it will be several days before I have something robust enough to deal with most obj files.

If you really want to do something right now, then I suggest making mtl files, and hopefully it will then work.

Hi @Ignatz,

Have already started to look at the file structures - could you point me to any good concise definitions for .obj and .mtl files. I’m looking to see if a general file importer is possible or a modular system.

Thanks,

Bri_G

:slight_smile:

wikipedia

and yes, a general file importer is possible - that’s what I’m writing!

Actually, the biggest problem I’m having is not the obj data format, but dealing with asynchronous downloads…

Hi @Ignatz,

Funnily enough I was thinking I might run into a problem of that type when I started working out file scanning. I assume you are still thinking of reading a file from a gist. That appears to work by opening a web page and transferring the data accordingly in a synchronous stream. I’m not sure if Dropbox offers the ability to load asynchronously, or if transfers are only synchronous. Perhaps it’s just a matter of of getting the HTTP protocols set up on the iPad to feed to a buffer (for interpretation) before transmitting the next datablock request overwriting the buffer?

My first thoughts were to do what you succeeded with - synchronous into a string and then interpret the string.

The alternatives would involve multiple small files, or data in an image file (which I’ve seen used in the forum), or set up a web site to hold the data in sections and use server side scripting to send files in sections. Probably with PHP or even Lua - you might consider Zoyts offer for the Web Lua webspace.

I’ve never felt comfortable with Codea’s lack of a robust filing system - taken it for granted in all systems I’ve used before. I’m sure there are other alternatives and there appear to be quite a few experts in the forum who could offer better suggestions. At the moment I’m using small files so I hope I can manage. Maybe we’ll find a better option with the release of the next Version of Codea.

Sorry that’s not likely to offer any resolution.

Bri_G

:-/