This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Mikeemoo's profile picture

3d model builder

Started by Mikeemoo, 20 November 2012 - 11:01 PM
Mikeemoo #1
Posted 21 November 2012 - 12:01 AM
Hi all,

I've been making something recently I thought you might be interested in.

I've written code that takes any 3d model (in .obj format), voxelizes it - but also finds the textures and maps the color of each voxel to the closest matching minecraft texture. It then converts it all to code which turtles understand.

I then have a 'parent' turtle which spawns 50+ turtles and gives each of them instructions for how to build their part of the ship.

The turtles work out exactly what materials they need and collect them from an array of chests, then start building!


They've been building a ship for me..

Starts off looking a bit random…



Taking shape..



Looking shippy….



80% done…




As you can see, it's not perfect. there's a few issues to work out where every now and then it'll miss a block, and there's a few bits of nether brick in there that don't really belong there. However, it's pretty good. It's very easy to manually tweak those after anyway.

This is only a really simple model with two main block types - I'll try a more complicated colourful model tonight to see how it gets on.

I may eventually release the code for this - although some of the processing is done out of the game and it all needs a lot of tidying before I dare show anyone! :(/>/>
Cruor #2
Posted 21 November 2012 - 03:37 AM
It's so fancy .-. i love it
PixelToast #3
Posted 21 November 2012 - 05:09 AM
:3 looks awesome
CoolisTheName007 #4
Posted 21 November 2012 - 09:17 AM
Uau, this is impressive. Questions:
-do you break the structure down to large cells for each turtle to process?
-does each turtle refills its inventory more than one time?
-do you optimize the building process, e.g. the turtle goes directly to the next block to be placed instead of walking through empty rows?

Orwell made a similar program, with different functionality: http://www.computercraft.info/forums2/index.php?/topic/1949-turtle-schematic-file-builder/page__fromsearch__1
Mikeemoo #5
Posted 21 November 2012 - 01:24 PM
Uau, this is impressive. Questions:
-do you break the structure down to large cells for each turtle to process?
-does each turtle refills its inventory more than one time?
-do you optimize the building process, e.g. the turtle goes directly to the next block to be placed instead of walking through empty rows?

Orwell made a similar program, with different functionality: http://www.computerc...__fromsearch__1

(note, I keep referring to 'commands' when explaining. Think of them as a simple object like this {x=1, y=1, z=1, blockId=1}

Each "command" (i.e. place a block at x,y,z) is sorted into x, then z, then y. So in reality each turtle goes from south to north stacking up columns. If they hit the end of a row, they'll move on the east/west axis and start the next row.
This is the best method to avoid collisions, however, it starts to get a bit tricky when deciding which materials each turtle takes for his journey - especially considering turtles have no awareness of their own inventory.
So when a turtle goes to collect his materials he only accepts as many "commands" as he can manage within his inventory space. The 'interesting' thing about this part is that each command is only referring to a single block placement, yet stacks go up to 64, so he has to keep a tally and a offsets to optimize his inventory space as much as possible, but at the same time making it so he still knows which inventory slot each item is in (and which ones aren't empty).

You generally end up with an inventory ordered similar to this:

64 cobble
64 cobble
64 cobble
64 cobble
64 cobble
64 cobble
64 Wool
64 Wool
64 Wool
64 Wool
64 Sandstone
64 Sandstone
64 Sandstone
64 Sandstone
64 Sandstone
64 Sandstone

I store an array of offsets for each material, similar to this:

materials = {
"cobblestone" = 384,
"wool" = 640,
"sandstone" = 1024
}

each time he places a block, I reduce that particular material by 1, so if I placed a wool I'd have..



materials = {
"cobblestone" = 384,
"wool" = 639,
"sandstone" = 1024
}

To work out which slot to select for each material, I can simply do this:

turtle.select(math.ceil(materials[material]/64))

Turtles don't refuel because they just don't need to. They suck up a stack of coal at the start and that's more than enough to do what they need to do. I might optimize this eventually because I know from the start exactly how many movements they'll need to take.
The idea of turtles returning to base to be reused is a bit of a null point for me - Each individual turtle takes ages to complete his section, so to do the bigger models I spawn 70+ turtles at once and give them all smaller patches to do.
In survival mode or without mods like EE, I'd probably change this a bit to make them a bit more.. reusable.



Oh yeah, this is part of the pre-processing code that does the voxelizing:


http://www.mikeefran.../3d/dragon.html (warning, may crash your browser!)
CoolisTheName007 #6
Posted 22 November 2012 - 11:28 PM
snip

Thanks for the long explanation; I hope to be able to pack those functionalities on a set of APIS, cause then it would be easier to do more epic stuff; well, it's one of those programming rules, right? 'If you are repeating it you should generalize it'.