Getting hands dirty with molehill

Few weeks ago I played with molehill and Away3D engine. Creating 3D scene is straightforward with an engine, but I still wanted to get deeper inside and understand the low level api and agal. So I took another approach and created pure molehill version of 3ddm. Soon I realized that I have been already familiar with some procedures from drawTriangles version so I could easily use algorithm for defining vertices, indices and uv.

Here is the result of my approach, you need flash player 11 or later…

See it fullscreen, download .zip sources or see .as code.

Some things to remember… to map texture over triangle, you have to use UV mapping:

// 5 = x, y, z, u, v
var vertexBuffer:VertexBuffer3D = context.createVertexBuffer(vertices.length / 5, 5);
vertexBuffer.uploadFromVector(vertices, 0, vertices.length / 5);

…split vertexBuffer to xyz and uv:

var program:Program3D = createProgram();
var float3:String = Context3DVertexBufferFormat.FLOAT_3;
var float2:String = Context3DVertexBufferFormat.FLOAT_2;
context.configureBackBuffer(viewportWidth, viewportHeight, 4, true);
context.setVertexBufferAt(0, vertexBuffer, 0, float3);  // x, y, z
context.setVertexBufferAt(1, vertexBuffer, 3, float2);  // u, v

…preparing program for positioning vertices and texture mapping:

    "m44 op, va0, vc0 \n" +  // position = vertex * matrix
    "mov v0, va1");          // move uv data

    "tex ft1, v0, fs0 <2d,linear,nomip> \n" + // sample texture for uv
    "mov oc, ft1");                           // use texture

A lot of has been written about molehill already, so from here I would like to just point you to some nice sources I have been through before started:

5 comments so far

  1. focus April 28, 2011 10:40

    Very nice!

  2. Terrence Tee June 2, 2011 15:44

    It has been quite a while since i visited ur blog. I am here now to look for your 3d image codes and i m glad to see new updates from u!
    have u thought about monetize the codes.
    I think if u add a 3d picture frame to wrap around the object, then, this file can sell like crazy!

  3. YopSolo June 29, 2011 21:55

    well done 🙂

  4. kag October 16, 2011 06:23


    Very impressive work !!!

    I need to show some 3D pics on a web page.
    How much do you charge for this great player (without the debug square on top left)?


  5. Jozef Chúťka October 18, 2011 15:36

    hi kag,
    stage3D/molehill player for fp11 will be available free on once I have time to finish it. ’till then, visit to see other fp10 versions…

Leave a comment

Please be polite and on topic. Your e-mail will never be published.