Saturday, 13 April 2013

Minecraft: Pi Edition - 3d Models - Version 2

I created a program, which using the Minecraft: Pi Edition API, takes 3d models and creates them in Minecraft, but version 1 only created the models as wire-frames and only in one block.

Version 2 is now out which uses the same concept of taking a 3d model as an obj file and using the api to render it in Minecraft but it now draw's complete polygons rather than wire-frames and gives the ability to specify a minecraft block for each material, allowing models to be created completely and in 'colour'.

The first model to try, well that of a Raspberry Pi of course!  Thanks to mnt and his Sketchup model of a Raspberry Pi which I exported as an obj file and my program made in Minecraft.




Adding the use of materials to the program was relatively easy, the obj file specifies which material should be used for a face (or faces), my program just uses a python dictionary object to specify the mapping between material and block type/data in python e.g. MATERIALS= {"Material1": [block.STONE, None], "Material2": [block.WOOL.id, 0]}, using polygons rather wire-frames was much more difficult.

To support drawing polygons, which when put together would create 3d polyhedrons I wrote a MinecraftDrawing class to implement the following algorithm:

  • Find all the points on all the edges of the polygon (red lines)
  • Draw lines between the edges of the polygon
    • Sort all the points by the dimensions (x,y,z)
    • Draw lines using a 3d version of the bresenham line algorithm (thick black lines)
This was complicated due to the Minecraft 'screen' being 3d, not 2d and google totally failing me in finding some example code!  So I had to write it myself, ridiculous!

I ended up creating several versions of this function, trying to create a more performant version, but as the faces became more complicated (i.e. bigger with more than 3 points) my performant versions ended up missing blocks, so I settled on a simple implementation that was slow but always filled the gap!

I'll get the code onto github shortly and update the post.

I then went on to re-draw the space shuttle and manhattan of previous posts.

Space Shuttle
Manhattan

6 comments:

  1. I love what you're doing with MC pi edition
    Great work !
    Keep doin'

    :)

    ReplyDelete
  2. hi there! my kids are finally getting into programming thanks to your excellent book! btw, have you updated the code for this to include the solid version (with filled in polygons)? if so, can you provide a link to it? thanks again

    ReplyDelete
  3. oops, just discovered your v2 program is already in the git!

    ReplyDelete
  4. Hey could you please tell me how to do that without downloading

    ReplyDelete
  5. Hey could you please tell me how to do that without downloading

    ReplyDelete

Note: only a member of this blog may post a comment.