Howdy, Stranger!

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

[3D Modeler] Codeler [Code Generator] Easily create 3D models!

edited July 2013 in Code Sharing Posts: 1,976

Version 1.1.5

Here's what, as far as I know, is the first 3D modeler for Codea.

I've been working really hard for a few hours, and here it is. A 3D modeler that lets you create cubes, move them, resize them, and export them as Lua. A few notes:

1: This is an early version, it will have bugs.

2: When you first start it up, you will have a white screen with a bunch of parameters Here's what they do:

Export - exports your model into lua code.

New cube - adds a new cube to the model.

Selected cube - this is a value, the ID of your selected cube. Change it to edit a different cube.

Model name - this is the name of your 3D model, used in export.

Show sprite picker - brings up the Sprite Picker for choosing the model texture.

3: Before you export or change which cube you are editing, make sure to save your work by pressing "Update Cube," this is not done automatically as it creates bugs. When you first change a value, nothing will happen. Update it to see it in action.

4: When your model is done (Make sure it is, you cannot import it and edit it later!), press the "Export" button. This will save a tab the name of your model, containing all the code for your model. It will generate vertex coordinates, texture coordinates, and a mesh that can render your model, with the texture you chose.

I think that's about it.

Installer: https://gist.github.com/SkyTheCoder/5897922

Have fun codeling!

To-Do List:

Animation Lab

Vector Lab

Delete selected box button

Undo

Redo

Model import

In the next update:

Shaders

Minecraft style texture coordinates

Custom texture coordinates

Change log:

1.0.0

Initial release

1.1.0

Sprite Picker

Planet Cute texture support

Auto-updates

1.1.1

Auto-update bug fix

1.1.2

Auto-update now installs the new update's installer

Minor description tweak

1.1.3

Finally fixed all auto-updating bugs

1.1.4

REALLY fixed all auto-updating bugs

1.1.5

Removed auto-updater because nothing was working and it wasn't worth it

Comments

  • BriarfoxBriarfox Mod
    Posts: 1,542

    Neat idea! I'd suggest allowing moving of the object in real time. Also maybe allow touch instead of parameters. You should add your spritepicker to select textures.

  • Posts: 1,976

    I was going to re-enable real-time updates, because I think the reason I disabled them was a bug I fixed. And 2D touch coordinates to 3D model coordinates would be really hard. There are a million different problems with the scenario, which I consider the biggest being getting the depth of where the cube should be. And, yeah, I'll add my SpritePicker.

  • Posts: 175

    @SkyTheCoder this might help as guidelines for 2D screen point to 3D world point and 3D world point to 2D screen point (though the language isn't lua and it uses the top left corner instead of bottom left, it sounds like what your looking for :) )

    http://webglfactory.blogspot.co.uk/2011/05/how-to-convert-world-to-screen.html

  • edited June 2013 Posts: 1,976

    @XanDDemoX I actually know how to convert 3D points to 2D points, but the problem is the opposite. For instance, dragging on a model to move it. If you're looking at a solid side angle, how would you know the depth to move it?

    By the way, there's an update coming in a few seconds.

  • edited June 2013 Posts: 175

    @SkyTheCoder A touches deltaX or deltaY values tell you how much the touch has moved and the direction so i think if I've understood correctly you could those to calculate new positions. Take a look at SceneCamera I've just updated it with an example that sounds similar :) -but I think in your case it's applying it to a single mesh instead of the whole scene.

    Edit: or perhaps altering the camera position could be the way to allow you to move your cubes on different plains :)

    rotate(self.view.angle,0,1,0) -- rotates around origin
    
  • Posts: 1,976

    I don't mean delta, I mean depth. Say you're at a camera position where you're looking from the side and can see x and y but not z. If something had a lower z value than the other it would be hidden behind it. That's what I'm talking about. How would you know how much to move on the z coordinate if any? There a a lot of problems with touches to coordinates. Just leave it at that.

  • Posts: 175

    @SkyTheCoder sorry my last post is maybe a little unclear. Thinking it through, use the camera position to determine the axises to move (x,y,z) by which axises it is facing and delta to determine how much :)

  • edited June 2013 Posts: 1,976

    @XanDDemoX Yes, it is possible, but to do it would take hundreds of lines of code, calculating the 3D angle of eye to lookat, with an offset of touch.x/WIDTH-(WIDTH/2) times perspective and touch.y/HEIGHT-(HEIGHT/2) times perspective, calculating the 3D motion based on the angle determining which cube you are selecting, and I feel that would just be a bit too hard for now, too much work for one small feature, and not a must-have.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @SkyTheCoder - cubes are fairly easy, but I would extend to rectangular shapes, ie where width, depth and height can all be different. That's not too hard.

    The question, though, is what can you actually do with a cube? Not much that I know of. I built one a few months ago, and couldn't find anything useful to do with it. You could stack blocks, I suppose.

    I think the problems with 3D are that to make anything really cool is very difficult and strains the iPad, so it is almost impossible to create anything approaching the complexity of modern graphic game scenes. Sure, we can model little pieces like cubes, wavy grass, or water, or simple raytracing, but not a whole scene of such stuff.

    That's why I took a different approach, and built and shared a 3D tabletop library that helps you add buildings, objects, terrain, etc, so you can make a 3D shooter or whatever. The advantage of a tabletop scene is that it doesn't need gravity and you can get away without true raytracing, which requires too much processing.

    All the same, building a cube is good practice.

  • Posts: 2,161

    @SkyTheCoder Take a look at http://loopspace.mathforge.org/discussion/13/matrices-in-codea/?Focus=27#Comment_27 for a suggested system of translating touch events into 3D coordinates which is simple, robust, and already coded (with nowhere near "hundreds of lines of code"). If you need any help with the maths, just ask.

  • IgnatzIgnatz Mod
    Posts: 5,396

    I just posted a new topic with an alternative solution to selecting 3D objects, that doesn't involve matrices, and which I think is more accurate, because I understand a math solution can't give you the precise x,y,z position of the touch, only a directional vector. And if you have lots of objects, some in front of others, that leaves you quite a lot of work to do.

  • Posts: 2,161

    @Ignatz I'll post a comment on your algorithm in that thread, but I want here to express my amusement about the implication contained in your comment "which I think is more accurate, because I understand a math solution can't give you the precise x,y,z position". If math[s] can't give you the precise x,y,z position then neither can anything else.

  • IgnatzIgnatz Mod
    Posts: 5,396

    My method can precisely tell you which object was touched - because it creates a hidden image where every pixel is id tagged - whereas math can't determine an exact x,y,z coordinate from an x,y touch. There are multiple solutions to that equation.

    Before you get too amused, tell me how you intend to respect (ie ignore) transparent pixels, so I can touch a back image through the transparent pixels of a (to make it interesting, translated and rotated) front image containing an irregular picture shape. My method does that, pixel perfectly.

    I am happy to go with the best solution, but I haven't seen a math solution that does all this yet!

  • Posts: 1,976

    @Ignatz Ever heard of Minecraft? Cubes everywhere. And you can make rectangular shapes. Scroll down, there are width, height, and length values.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @SkyTheCoder- I know about minecraft, of course. I've created blocks of my own, as well as a class for 3D tabletop modelling, so I understand some of the issues around 3D. My tabletop is built around rectangular shapes, too.

    I'm not criticising your programming, just commenting on the difficulty of 3D programming, and especially of creating anything approaching a full 3D game.

    But if you can create something like minecraft in Codea, good for you!

  • edited July 2013 Posts: 1,976

    A Minecraft texture vertices option will come in the next update. So will custom texture vertices.

  • Posts: 398

    I do agree with @Ignatz that modelling with just cubes is fairly limiting unless your trying to recreate Minecraft or Lego :-).

    I've often been surprised that no-one else (to my knowledge!) has attempted to create a 'simple' modelling App in Codea. - similar to something like Spritely but for creating 'simple' 3d assets that can be used in Codea.

    @SkyTheCoder - I'd surmise that most people don't have the time or inclination to learn something like Blender, SketchUp, 3DSMax etc.. and really want a few basic tools for creating simple meshes - possibly exported as some sort of '3d Model Class' that sets up all the vertices, tex-coords semi-automatically. (Footnote: Even importing 3rd party models using some of the fantastic code posted on here is still quite involved and not as simple as using the color/sprite picker - but that's for another discussion!)

    Ideally, I guess a nice 'simple' modelling app should have:

    • A number of basic primitives as building blocks (Sphere, Cone, Cylinder, Cube etc)
    • A simple set of navigation, transformation and selection tools
    • A Revolve & Extrude tool (for more freeform shapes and extruded shapes like 3d text)
    • A tool for modifying/moving individual vertices

    I think this is the basic functionality to make it useful. Although, bonus points for implementing grouping/hierarchies and a gold medal for basic shader support :-D

    What do you think?

  • IgnatzIgnatz Mod
    Posts: 5,396

    @andymac3D- I have shared a custom library for creating a tabletop scene, with functions for buildings, roofs, terrain etc. That could be used for all kinds of things, eg an FPS.

    The sort of library you've suggested is more general but would be difficult to turn into anything more than a set of geometric shapes.

  • Posts: 398

    @Ignatz - I think your library is fab and super useful. My point is more to do with the 'mechanics' of creating interactively new 3D assets from scratch which is still a bind for most people with no experience. ;-)

  • Posts: 1,976

    I'm working on adding Spheres, but for some reason nothing rendered when I tried rendering it. After I get spheres done, I planned for cylinders. Custom vertices selection & movement, and revolve/extrude sounds cool, but might take a while to get in. I think I'll actually add shader support in the next update. I was thinking about rotations a while ago, too, but I'm still thinking about some of the equations required for it.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @SkyTheCoder- Jmv38 did some cool tutorials with spheres here (halfway down page, look for earth movies), they may help

    http://jmv38.comze.com/CODEAbis/server.php#3D

  • Posts: 1,976

    I actually used some of spacemonkey's sphere code for it, but I couldn't figure out why it didn't render anything. (Not just the sphere, but any boxes, too.) It was working as a textured sphere in another project.

  • IgnatzIgnatz Mod
    Posts: 5,396

    Tricky stuff, 3D, it might be right there just behind the camera where you can't see it!

  • Posts: 1,976

    I actually though of that. I tried scaling it down on a size of 10 and nothing appeared.

  • IgnatzIgnatz Mod
    Posts: 5,396

    Try looking behind you. A lot of my 3D stuff started out there ;)

  • IgnatzIgnatz Mod
    Posts: 5,396

    Actually, if you haven't included it already, I'd give yourself the ability to look around and up and down, maybe with parameters. Then you can see if you've misplaced your stuff!

  • Posts: 16

    If you're still looking for one, I have a .stl file importer I've been working on. Also, check out a post i may or may not have put up a while back that does a similar thing to what you are doing. It creates surfaces from equations. The equations have to be hard coded into the program... For now! But let me know and I will post my code :)

  • Posts: 502

    Here is my parser for the ascii OBJ format:

    https://gist.github.com/tnlogy/4690383

    To create an 3d modeler it would be nice to build it with my translation of the CSG.js code.

    https://github.com/tnlogy/csg.js/tree/master/lua

Sign In or Register to comment.