Triplanar mapping textures to marching cubes
This commit is contained in:
parent
edaa7c8ce2
commit
c30f30b8a0
@ -30,11 +30,11 @@ public class TerrainChunk {
|
|||||||
//row 1
|
//row 1
|
||||||
{-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,},
|
{-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,},
|
||||||
//row 2
|
//row 2
|
||||||
{-1.0f,1.0f,1.0f,1.0f,-1.0f,},
|
{-1.0f,0.3f,0.6f,0.3f,-1.0f,},
|
||||||
//row 3
|
//row 3
|
||||||
{-1.0f,1.0f,1.0f,1.0f,-1.0f,},
|
{-1.0f,0.6f,1.0f,0.6f,-1.0f,},
|
||||||
//row 4
|
//row 4
|
||||||
{-1.0f,1.0f,1.0f,1.0f,-1.0f,},
|
{-1.0f,0.3f,0.6f,0.3f,-1.0f,},
|
||||||
//row 5
|
//row 5
|
||||||
{-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,},
|
{-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,},
|
||||||
},
|
},
|
||||||
@ -43,11 +43,11 @@ public class TerrainChunk {
|
|||||||
//row 1
|
//row 1
|
||||||
{-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,},
|
{-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,},
|
||||||
//row 2
|
//row 2
|
||||||
{-1.0f,1.0f,1.0f,1.0f,-1.0f,},
|
{-1.0f,0.7f,1.0f,0.7f,-1.0f,},
|
||||||
//row 3
|
//row 3
|
||||||
{-1.0f,1.0f,1.0f,1.0f,-1.0f,},
|
{-1.0f,1.0f,1.0f,1.0f,-1.0f,},
|
||||||
//row 4
|
//row 4
|
||||||
{-1.0f,1.0f,1.0f,1.0f,-1.0f,},
|
{-1.0f,0.7f,1.0f,0.7f,-1.0f,},
|
||||||
//row 5
|
//row 5
|
||||||
{-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,},
|
{-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,},
|
||||||
},
|
},
|
||||||
@ -56,11 +56,11 @@ public class TerrainChunk {
|
|||||||
//row 1
|
//row 1
|
||||||
{-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,},
|
{-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,},
|
||||||
//row 2
|
//row 2
|
||||||
{-1.0f,1.0f,1.0f,1.0f,-1.0f,},
|
{-1.0f,0.3f,0.6f,0.3f,-1.0f,},
|
||||||
//row 3
|
//row 3
|
||||||
{-1.0f,1.0f,1.0f,1.0f,-1.0f,},
|
{-1.0f,0.6f,1.0f,0.6f,-1.0f,},
|
||||||
//row 4
|
//row 4
|
||||||
{-1.0f,1.0f,1.0f,1.0f,-1.0f,},
|
{-1.0f,0.3f,0.6f,0.3f,-1.0f,},
|
||||||
//row 5
|
//row 5
|
||||||
{-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,},
|
{-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,},
|
||||||
},
|
},
|
||||||
@ -83,7 +83,7 @@ public class TerrainChunk {
|
|||||||
|
|
||||||
Entity rVal = EntityUtils.spawnDrawableEntityWithPreexistingModel(modelPath);
|
Entity rVal = EntityUtils.spawnDrawableEntityWithPreexistingModel(modelPath);
|
||||||
|
|
||||||
EntityUtils.getPosition(rVal).set(1,-2,1);
|
EntityUtils.getPosition(rVal).set(1,-1,1);
|
||||||
|
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,8 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.vecmath.Vector2f;
|
||||||
|
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
@ -321,6 +323,21 @@ public class TerrainChunkModelGeneration {
|
|||||||
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
|
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final byte[] BLOCK_PICK_BITS_BY_VERT_INDEX = new byte[]{
|
||||||
|
(byte)0x67,
|
||||||
|
(byte)0x26,
|
||||||
|
(byte)0x23,
|
||||||
|
(byte)0x37,
|
||||||
|
(byte)0x45,
|
||||||
|
(byte)0x04,
|
||||||
|
(byte)0x01,
|
||||||
|
(byte)0x15,
|
||||||
|
(byte)0x57,
|
||||||
|
(byte)0x46,
|
||||||
|
(byte)0x02,
|
||||||
|
(byte)0x13
|
||||||
|
};
|
||||||
|
|
||||||
static class Triangle {
|
static class Triangle {
|
||||||
int[] indices = new int[3]; //array of size 3
|
int[] indices = new int[3]; //array of size 3
|
||||||
|
|
||||||
@ -455,7 +472,7 @@ public class TerrainChunkModelGeneration {
|
|||||||
Vector3f n = new Vector3f(u.y * v.z - u.z * v.y, u.z * v.x - u.x * v.z, u.x * v.y - u.y * v.x).normalize();
|
Vector3f n = new Vector3f(u.y * v.z - u.z * v.y, u.z * v.x - u.x * v.z, u.x * v.y - u.y * v.x).normalize();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//for each vertex, average the new normal with the normals that are already there
|
//for each vertex, average the new normal with the normals that are already there
|
||||||
int trianglesSharingIndex0 = trianglesSharingVert.get(index0);
|
int trianglesSharingIndex0 = trianglesSharingVert.get(index0);
|
||||||
//calculate proportion of each normal
|
//calculate proportion of each normal
|
||||||
@ -641,27 +658,6 @@ public class TerrainChunkModelGeneration {
|
|||||||
temp[2] = normal.z;
|
temp[2] = normal.z;
|
||||||
NormalArrayBufferData.put(temp);
|
NormalArrayBufferData.put(temp);
|
||||||
}
|
}
|
||||||
// for(Triangle triangle : triangles){
|
|
||||||
// //emit 3 normal vectors
|
|
||||||
// //normal 0
|
|
||||||
// Vector3f normal = normals.get(triangle.indices[0]);
|
|
||||||
// temp[0] = normal.x;
|
|
||||||
// temp[1] = normal.y;
|
|
||||||
// temp[2] = normal.z;
|
|
||||||
// NormalArrayBufferData.put(temp);
|
|
||||||
// //normal 1
|
|
||||||
// normal = normals.get(triangle.indices[1]);
|
|
||||||
// temp[0] = normal.x;
|
|
||||||
// temp[1] = normal.y;
|
|
||||||
// temp[2] = normal.z;
|
|
||||||
// NormalArrayBufferData.put(temp);
|
|
||||||
// //normal 2
|
|
||||||
// normal = normals.get(triangle.indices[2]);
|
|
||||||
// temp[0] = normal.x;
|
|
||||||
// temp[1] = normal.y;
|
|
||||||
// temp[2] = normal.z;
|
|
||||||
// NormalArrayBufferData.put(temp);
|
|
||||||
// }
|
|
||||||
NormalArrayBufferData.flip();
|
NormalArrayBufferData.flip();
|
||||||
mesh.buffer_normals(NormalArrayBufferData, 3);
|
mesh.buffer_normals(NormalArrayBufferData, 3);
|
||||||
}
|
}
|
||||||
@ -672,31 +668,34 @@ public class TerrainChunkModelGeneration {
|
|||||||
//
|
//
|
||||||
// TEXTURE COORDINATES
|
// TEXTURE COORDINATES
|
||||||
//
|
//
|
||||||
/*try {
|
try {
|
||||||
skyboxmesh.textureCoordCount = mesh.mTextureCoords(0).capacity();
|
mesh.textureCoordCount = normals.size();
|
||||||
FloatBuffer TextureArrayBufferData;
|
FloatBuffer TextureArrayBufferData;
|
||||||
if(skyboxmesh.textureCoordCount > 0){
|
if(mesh.textureCoordCount > 0){
|
||||||
TextureArrayBufferData = BufferUtils.createFloatBuffer(skyboxmesh.textureCoordCount * 2);
|
TextureArrayBufferData = BufferUtils.createFloatBuffer(mesh.textureCoordCount * 2);
|
||||||
float[] temp = new float[2];
|
float[] temp = new float[2];
|
||||||
for (int i = 0; i < skyboxmesh.textureCoordCount; i++) {
|
for(Vector3f normal : normals){
|
||||||
AIVector3D normal = texturecoords.get(i);
|
float absX = Math.abs(normal.x);
|
||||||
temp[0] = normal.x();
|
float absY = Math.abs(normal.y);
|
||||||
temp[1] = normal.y();
|
float absZ = Math.abs(normal.z);
|
||||||
// temp[2] = normal.z();
|
if(absX >= absZ && absX >= absY){
|
||||||
|
temp[0] = normal.z / 2.0f + 0.5f;
|
||||||
|
temp[1] = normal.y / 2.0f + 0.5f;
|
||||||
|
} else if(absZ >= absX && absZ >= absY){
|
||||||
|
temp[0] = normal.x / 2.0f + 0.5f;
|
||||||
|
temp[1] = normal.y / 2.0f + 0.5f;
|
||||||
|
} else if(absY >= absX && absY >= absZ){
|
||||||
|
temp[0] = normal.x / 2.0f + 0.5f;
|
||||||
|
temp[1] = normal.z / 2.0f + 0.5f;
|
||||||
|
}
|
||||||
TextureArrayBufferData.put(temp);
|
TextureArrayBufferData.put(temp);
|
||||||
}
|
}
|
||||||
TextureArrayBufferData.flip();
|
TextureArrayBufferData.flip();
|
||||||
skyboxmesh.buffer_texture_coords(TextureArrayBufferData);
|
mesh.buffer_texture_coords(TextureArrayBufferData, 2);
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
skyboxmesh.shader = ShaderProgram.smart_assemble_shader(has_bones, apply_lighting);
|
|
||||||
|
|
||||||
skybox_model.materials.add(optionalMaterial);
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -751,4 +750,16 @@ public class TerrainChunkModelGeneration {
|
|||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final int pickBlockIdForVertex(long blockIds, int vertIndex){
|
||||||
|
int bits = BLOCK_PICK_BITS_BY_VERT_INDEX[vertIndex];
|
||||||
|
int blockIndexA = bits >> 4;
|
||||||
|
int blockIndexB = bits & 0xf;
|
||||||
|
int blockIdA = (int)(blockIds >> 8 * blockIndexA) & 0xff;
|
||||||
|
int blockIdB = (int)(blockIds >> 8 * blockIndexB) & 0xff;
|
||||||
|
|
||||||
|
//assert (blockIdA == airBlockId) != (blockIdB == airBlockId);
|
||||||
|
//return blockIdA - nonZeroAirBlockId + blockIdB;
|
||||||
|
return blockIdA + blockIdB;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user