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

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



Model import

In the next update:


Minecraft style texture coordinates

Custom texture coordinates

Change log:


Initial release


Sprite Picker

Planet Cute texture support



Auto-update bug fix


Auto-update now installs the new update's installer

Minor description tweak


Finally fixed all auto-updating bugs


REALLY fixed all auto-updating bugs


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

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.

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.

@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 :slight_smile: )


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

@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 :slight_smile: -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 :slight_smile:

rotate(self.view.angle,0,1,0) -- rotates around origin

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.

@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 :slight_smile:

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

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

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

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.

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

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!

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

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

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

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 :smiley:

What do you think?

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

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