minecraft mesh renderer is working

This commit is contained in:
Vadim Lopatin 2016-03-25 14:39:10 +03:00
parent 1ebecc8bc8
commit 695003ba2b
4 changed files with 24 additions and 10 deletions

View File

@ -128,15 +128,20 @@ class UiWidget : VerticalLayout, CellVisitor {
_minerMesh = new Mesh(VertexFormat(VertexElementType.POSITION, VertexElementType.NORMAL, VertexElementType.COLOR, VertexElementType.TEXCOORD0));
_world = new World();
for (int x = -100; x < 100; x++)
for (int z = -100; z < 100; z++)
_world.setCell(x, 0, z, 1);
_world.setCell(0, 11, 10, 2);
_world.setCell(5, 11, 15, 2);
for (int x = -100; x < 100; x++)
for (int z = -100; z < 100; z++)
_world.setCell(x, 0, z, 2);
Random rnd;
rnd.setSeed(12345);
for(int i = 0; i < 1000; i++)
_world.setCell(rnd.next(6)-32, rnd.next(4), rnd.next(6)-32, 3);
for(int i = 0; i < 1000; i++) {
int bx = rnd.next(6)-32;
int by = rnd.next(4);
int bz = rnd.next(6)-32;
Log.fd("Setting cell %d,%d,%d", bx, by, bz);
_world.setCell(bx, by, bz, 3);
}
_world.camPosition = Position(Vector3d(0, 3, 0), Vector3d(0, 0, 1));
updateMinerMesh();
@ -205,6 +210,8 @@ class UiWidget : VerticalLayout, CellVisitor {
_world.visitVisibleCells(_world.camPosition, this);
long duration = currentTimeMillis - ts;
Log.d("DiamondVisitor finished in ", duration, " ms ", "Vertex count: ", _minerMesh.vertexCount);
for (int i = 0; i < 20; i++)
Log.d("vertex: ", _minerMesh.vertex(i));
}
World _world;

View File

@ -65,7 +65,7 @@ public:
ushort startVertexIndex = cast(ushort)mesh.vertexCount;
float[VERTEX_COMPONENTS * 4] vptr;
ushort[6] iptr;
createFaceMesh(vptr.ptr, face, pos.x + 0.5f, pos.y + 0.5f, pos.z + 0.5f, txIndex);
createFaceMesh(vptr.ptr, face, pos.x, pos.y, pos.z, txIndex);
for (int i = 0; i < 6; i++)
iptr[i] = cast(ushort)(startVertexIndex + face_indexes[i]);
//if (HIGHLIGHT_GRID && ((pos.x & 7) == 0 || (pos.z & 7) == 0)) {
@ -149,10 +149,9 @@ static void fillFaceMesh(float * data, const float * src, float x0, float y0, fl
for (int i = 0; i < 4; i++) {
const float * srcvertex = src + i * VERTEX_COMPONENTS;
float * dstvertex = data + i * VERTEX_COMPONENTS;
for (int j = 0; j < 11; j++) {
for (int j = 0; j < VERTEX_COMPONENTS; j++) {
float v = srcvertex[j];
switch (j) {
default:
case 0: // x
v += x0;
break;
@ -166,7 +165,10 @@ static void fillFaceMesh(float * data, const float * src, float x0, float y0, fl
v = ((tileX + v * BLOCK_SPRITE_SIZE)) / cast(float)BLOCK_TEXTURE_DX;
break;
case 11: // tx.v
v = (BLOCK_TEXTURE_DY - (tileY + v * BLOCK_SPRITE_SIZE)) / cast(float)BLOCK_TEXTURE_DY;
//v = (BLOCK_TEXTURE_DY - (tileY + v * BLOCK_SPRITE_SIZE)) / cast(float)BLOCK_TEXTURE_DY;
v = ((tileY + v * BLOCK_SPRITE_SIZE)) / cast(float)BLOCK_TEXTURE_DY;
break;
default:
break;
}
dstvertex[j] = v;

View File

@ -726,7 +726,7 @@ int mySign(int n) {
return 0;
}
immutable ulong RANDOM_MULTIPLIER = ((cast(ulong)1 << 48) - 1);
immutable ulong RANDOM_MULTIPLIER = 0x5DEECE66D;
immutable ulong RANDOM_MASK = ((cast(ulong)1 << 48) - 1);
immutable ulong RANDOM_ADDEND = cast(ulong)0xB;

View File

@ -174,6 +174,11 @@ class Mesh {
_dirtyVertexBuffer = true;
}
const(float[]) vertex(int index) {
int i = _vertexFormat.vertexFloats * index;
return _vertexData[i .. i + _vertexFormat.vertexFloats];
}
void reset() {
_vertexCount = 0;
_vertexData.length = 0;