Howdy, Stranger!

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

How to import fully 3D objects (Final post)

2

Comments

  • IgnatzIgnatz Mod
    Posts: 5,396

    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.

    :-)

  • IgnatzIgnatz Mod
    Posts: 5,396

    @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!!

  • edited December 2013 Posts: 1,837

    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

    :)

  • IgnatzIgnatz Mod
    Posts: 5,396

    @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.

  • Posts: 1,837

    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

    :)

  • IgnatzIgnatz Mod
    edited December 2013 Posts: 5,396

    wikipedia

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

  • IgnatzIgnatz Mod
    Posts: 5,396

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

  • Posts: 1,837

    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

    :-/

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Bri_G - unfortunately all internet transfers are asynchronous in Codea, so the problem isn't with where the data is kept on the internet, but with the fact that your code has to pause itself while the data is being retrieved, not just once for the obj file, but also for each texture image.

    I think I have it working now, anyway.

    I also have the code in a class, allowing loading of multiple models. I'll modify it so it doesn't need an mtl section (in what is now a combined mtl and obj file). But if there are texture images, then you will need an mtl section to assign each image to the correct material.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Bri_G - here is my latest code. I hope it loads all the data correctly.

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

    The spitfire is magnificent, but the Merc is a mess, for some reason.

    It now loads a model into a class, but can't load more than one at a time, yet.

    If you open one of the urls in the Assets tab, you'll see the data layout. Essentially the mtl comes first, then a [obj] tag, then the obj file. Note the way images are defined in the mtl section

    It should work without an mtl section, but I haven't tested that.

    I've started thinking about how to fly these models....

  • edited December 2013 Posts: 1,837

    HI @Ignatz,

    Loaded up and ran - superb, Spitfire is really well detailed and the rest of the models (except Merc) are great. Have you solved your flickering problem? As I say one of the early models showed it - probably the first one that you ran - a sort of ring spaceship with engines attached. Flickering occurred in the engine vents.

    Will digest your file format next - is this an Ignatz home grown? Have you just combined the .obj and .mtl? The literature suggested .mtl is being phased out and variants now being used as alternatives - probably like your own file.

    Last phrase, not sure - if you mean on screen - fine!! Otherwise we'll start to worry about the amount of time you are putting in to this - do you actually get any sleep?

    I think there is something in the air down there - my old boss moved down to New Zealand and he spent most of his time flying model aircraft, driven by rubber bands. I spent many hours developing software for him so that he could change his designs to get longer flight times. He even went to the underground salt mines in Poland (or maybe Russia) for global competitions - even won awards!!! For me - doing it on a computer/pad is good enough.

    Be in touch when I've tried my models out on your viewer.

    Thanks.

    Bri_G

    =;

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Bri_G - my single file is simply the mtl file followed by the obj file, with a separator tag [obj] (on its own line) which goes between them.

    I haven't solved the flickering. Unless the artists made mistakes, it's probably to do with the way I calculate triangles for faces with more than three vertices, because that is the only adjustment I make to any of the data provided.

    Andrew Stacey is going to help me to actually fly these planes around in Codea. It involves quaternions, which I just cannot understand.

  • Posts: 1,837

    Hi @Ignatz,

    Checked out your files and it makes sense. Andrew's your man when it comes to matrix maths - he has written an article about it on his web-site. I'm interested in learning how it's done - I'd like to take models and put them through a figure of 8 loop flying into the screen from behind the camera and then flying back looping as they go. Andrew wrote the example for Codea (main panel) with 3D scrolling around a series of what look like steps or wooden beams - could possibly start to look there for the movement suggestions.

    Bri_G

    =;

  • @Ignatz - you'll probably find a fair number of the free models on the web have some sort of anomaly - so I wouldnt be too concerned when testing your code. Often some (or all!) of the normals being flipped is quite common, especially if they've been converted from another format, as well as badly laid out or overlapping texture co-ords which is another modeling no no and can cause rendering issues.

    With my .obj importer I got round this by cleaning up the geo first in Maya and also pre-tesselating any quads or n-gons first, so I then have only a clean, consistent set of triangles with outwardly facing normals to deal with prior to exporting the .obj. This makes everything a lot more predictable and simple when parsing the file and testing.

    Other 'gotchas' with 3d models are:

    1) Co-incident polys in the same place - the number one cause of flickering polygons, as the renderer cant work out which one is in front of the other.

    2) Dangling vertices or edges - edges or vertices not associated with any polys.

    3) A poly with collapsed vertices - a valid poly, but all the vertices are the same yielding to zero area and an apparently 'invisible' poly.

    4) Non-manifold geometry - three or more polys share an edge. Generally bad modeling practice and can cause renderers (and certain poly operations) to fail.

    You might want to look at these should any of your models yield odd results with your importer.. ;-)

  • IgnatzIgnatz Mod
    edited December 2013 Posts: 5,396

    @andymac3d - thanks for that. I'll go back and look at the models in Blender.

    Looking at your point 4 above, reminds me that when there is a face with more than three points, I need to break it into triangles, so I calculate the average vertex centre and make triangles with that point and every adjacent pair of points. This means the centre point can be shared between many triangles.

    Is there a better way to subdivide a large polygon?

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Bri_G - we're initially looking at following the plane with the camera, as with most or all air war games.

  • @Ignatz - the danger with this method is it works fine for a convex polygon, but if you have something thats concave (imagine a pacman type shape made up of say 8 vertices) then making an assumption you can find the mid point and tesselate from there quickly falls apart as you start getting overlapping polygons (see point 1 on my list!).

    I think my point is that its fairly difficult to accommodate every possible scenario of the sorts of polygons/models your importer is going to encounter. Much easier perhaps to assume (as I have) that any model should be composed of triangles and let your 3D package do the 'heavy lifting' in respect to cleanup and tesselation.

  • IgnatzIgnatz Mod
    edited December 2013 Posts: 5,396

    What a difference a 3D model makes!

    Here is my 3D lunar lander game, with a model of the actual Apollo lander, both in flight and on the ground after landing. This game is now a combined hack of several different projects I've worked on in the last 6 months!

    (as always, the video is murkier and less clear than the original).

  • BriarfoxBriarfox Mod
    Posts: 1,542

    @ignatz that is really amazing. So when do we get your skybox with stars added in?

  • IgnatzIgnatz Mod
    Posts: 5,396

    I wasn't going to add anything extra there, with FPS at just 15 (besides, you can't see stars in pictures taken on the moon, they are too faint :D )

  • Posts: 1,837

    Hi @Ignatz,

    The video is bl#!dy marvelous, particularly the 3D walk on the moon's surface. Bet that's whats soaking up your FPS. The curvature on the surface is very realistic.

    Best thread for ages!!

    Thanks,

    Bri_G

    =D> =D> =D>

  • @Ignatz - no stars because it was filmed in a studio.. :-D

    Good work fella!

  • Posts: 577

    @Ignatz Thats the smoothest 15 fps I've ever seen.

  • IgnatzIgnatz Mod
    Posts: 5,396

    Actually, I was getting 15FPS while flying, I'm not sure what it was on the ground.

    But the iPad does pretty well - that terrain is 3000 x 6000 pixels, made up of 10,000 vertices, and the lunar lander model has about 20,000 vertices.

  • IgnatzIgnatz Mod
    Posts: 5,396

    Here is an updated video of my spitfire flying (floating, rather) in a sky consisting of (the inside of) a sphere with a sky image mapped to it, so it provides a 360 degree sandpit to play in (once I can fly the plane).

    The spitfire turns as the iPad is tilted, and the (genuine Spitfire) sound is a beta Codea feature.

    I still have to learn to create flight controls (and manage the rotations involved), and Andrew Stacey is helping me with that.

    If anyone likes simulating real world stuff and would like to get involved in making this more realistic, let me know. My interest is mainly in the graphic part.

  • Posts: 1,595

    @Ignatz me and another user are creating a Flight Management System simulator which could work with it, possibly.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Luatee - cool, let me know when you have something.

  • Posts: 2,043

    @Ignatz, teasing us about sound, huh? :P

  • @Ignatz Terrific work!

    I really like the 3d chair model. Someone needs to make an eXtreme Sitting sim game. :)

  • IgnatzIgnatz Mod
    Posts: 5,396

    There are lots of models for household furniture and other objects on the net.

    But the problem with chairs is the people sitting in them. Finding good models of people is hard enough without trying to get them to move about.

  • Too many vertices to map and apply textures to. That's why animators use motion capture. And my animations look like South Park. First season.

    I have a friend that likes to design 3d models of buildings for one of the Sim games. They're just standing still and sometimes he's screaming...

  • IgnatzIgnatz Mod
    Posts: 5,396

    lol, I've been billboarding (using 2D images and turning them to always face the camera). This works well for trees but not so well for living things...

    So I figure vehicles are best because at least they don't change...

  • Posts: 2,820

    @syntonica - @John had made a cool entry for Ludum Dare where you had to get down stairs by breaking the chair and not killing yourself at the same time. It was really cool. Sadly, I can't find it.

  • Posts: 1,837

    Hi @Ignatz,

    Still making great strides in the 3D area - now into sound - very impressive!!!

    Not much into animation myself, but to add a little more realism - you need to make the prop rotate and move the landscape - the latter should be easier if you're in a Sky box. I think you are down to the model for the prop - Blender has these facilities built in but I haven't even tried to use them.

    Keep up the great work - I'm still trying to understand your 3D code and models in general.

    Bri_G

    ^:)^

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Bri_G - the landscape will move when the plane moves - at the moment it's pinned to one spot. The background is actually a complete sky sphere, and the plane is inside, so there is a 360 degree view.

    wrt the prop, that is a problem, how to find those vertices in 20,000 others and then alter them, but I'm not trying to make a finished game, so I'm not bothered.

    I'm not sure if "trying to understand" includes 3D in general, wrt OpenGL. If so, I started writing an ebook on 3D in Codea. I haven't got terribly far because I'm figuring out which way to approach it, but the basics are there. See below.

    https://www.dropbox.com/s/6rkqoqvvj7zhwhz/3D in Codea.pdf

    I also did a blog post on how the models are put together, here

    http://coolcodea.wordpress.com/2013/12/13/139-importing-full-3d-models-into-codea/

  • IgnatzIgnatz Mod
    Posts: 5,396

    I added a cloud effect, discovered almost by accident.

    It's really simple, just two white rectangles, one in front of the aircraft, and one behind, with the alpha value cycling up and down to create transparency, with some random variation.

    It gives quite a nice impression of swirling misty cloud even though each frame is a single colour.

  • Posts: 1,595

    @Ignatz is there anything you could do with noise to make it looks like you're travelling through a 3D cloud at speeds

  • Posts: 577

    @Ignatz Couldn't you make the propellers a different object, and rotate them that way it looks like they are working? But great work!

  • IgnatzIgnatz Mod
    edited December 2013 Posts: 5,396

    Funny you should mention propellors. I spent several hours this evening finding the propellor vertices in 25000 rows of data and extracting them to separate meshes so I could rotate them, as shown below.

    It looks better on the iPad because video recording slows FPS.

    Real cloud is possible but if I want to add other planes, I have to watch the strain on FPS.

  • Posts: 2,820

    =D>

  • edited December 2013 Posts: 398

    @Ignatz - Good work fella! Ideally, you'd delete the vertices of the prop and just put a 2d plane where the propeller blades are. You can then prep an image like the one below and map it to the plane:

    image

    The trick then is to animate it with a very slow rotation (and perhaps vary the opacity with a slow random change via the noise function) to give it a degree of realism.

    This is a standard 3D 'cheat' to fool the eye into thinking you're looking at a very fast rotating object - the motion blur is pre-computed in the propeller image and works surprisingly well.

    I'm a huge fan of optimising effects such as this in 3D, especially where resources are a bit tight. You could also poly-reduce your spitfire model significantly to keep your FPS high as high as possible.

    There's also other cheats I'd recommend, I might write a list over the weekend and post a few ideas. ;-)

  • IgnatzIgnatz Mod
    Posts: 5,396

    @andymac3d - all advice is very welcome, thank you!!

  • Jmv38Jmv38 Mod
    edited December 2013 Posts: 3,297

    @andymac3d i'd love reading your advices!

  • IgnatzIgnatz Mod
    edited December 2013 Posts: 5,396

    I've got the plane flying (with some basic quaternions managing rotation), and drew myself a spinning propellor

    Andrew Stacey is working on flight controls so I expect to improve what I have here, but I like it already!

    I'll post code as soon as we have all this sorted out. At the moment, the code is pretty messy.

  • Jmv38Jmv38 Mod
    Posts: 3,297

    Very impressive! I wonder if it will wok on ipad1, though...

  • Posts: 1,595

    Dog fighting!

  • IgnatzIgnatz Mod
    Posts: 5,396

    That's where I'm heading.....

  • Posts: 1,595

    Amazing work, keep it up! Could be the one to release Codea's first full 3D game =D>

  • IgnatzIgnatz Mod
    Posts: 5,396

    I doubt it, these models can't be used commercially, and there are just too many things still to do to make it a full game. I'm happy just to get a bit of dogfighting going...

Sign In or Register to comment.