blog
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 (SimpleDisplacerMH.zip) 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:
vertexAssembler.assemble(Context3DProgramType.VERTEX,
"m44 op, va0, vc0 \n" + // position = vertex * matrix
"mov v0, va1"); // move uv data
fragmentAssembler.assemble(Context3DProgramType.FRAGMENT,
"tex ft1, v0, fs0 <2d,linear,nomip> \n" + // sample texture for uv
"mov oc, ft1"); // use textureA 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:
Flash Platform SDK – AGALMiniAssembler, PerspectiveMatrix3D …
Flash 3D, Molehill and The Perspective Divide
Molehill Flash Tutorial: AGAL Basics
Súbor: SimpleDisplacerMH.zip