mirror of
https://github.com/Floriansylvain/ThatsMyWorld.git
synced 2026-08-19 19:53:17 +02:00
feat: chunks WIP
This commit is contained in:
+13
-6
@@ -16,25 +16,30 @@ interface BlockData {
|
||||
}
|
||||
|
||||
export default class Chunk {
|
||||
position: Vector3
|
||||
chunk: BlockData[]
|
||||
chunkSet: Set<string>
|
||||
radius: number
|
||||
textures: { [name: string]: Texture[] }
|
||||
faces: { [key: string]: Face[] }
|
||||
|
||||
constructor(radius: number, textures: { [name: string]: Texture[] }) {
|
||||
constructor(
|
||||
radius: number,
|
||||
textures: { [name: string]: Texture[] },
|
||||
position: Vector3
|
||||
) {
|
||||
this.position = position
|
||||
this.chunk = []
|
||||
this.chunkSet = new Set<string>()
|
||||
this.radius = radius
|
||||
this.textures = textures
|
||||
this.faces = {}
|
||||
this.generateChunk()
|
||||
this.initializeFaces()
|
||||
}
|
||||
|
||||
generateChunk() {
|
||||
for (let i = 0; i < this.radius; i++) {
|
||||
for (let j = 0; j < this.radius; j++) {
|
||||
async generateChunk() {
|
||||
return new Promise((resolve) => {
|
||||
for (let i = this.position.x; i < this.radius + this.position.x; i++) {
|
||||
for (let j = this.position.z; j < this.radius + this.position.z; j++) {
|
||||
const max = Math.ceil(Math.sin(i / 30) * 10 + Math.cos(j / 30) * 10)
|
||||
for (let k = -16; k <= max; k++) {
|
||||
const position = new Vector3(i, k, j)
|
||||
@@ -46,6 +51,8 @@ export default class Chunk {
|
||||
}
|
||||
}
|
||||
}
|
||||
resolve("")
|
||||
})
|
||||
}
|
||||
|
||||
initializeFaces() {
|
||||
|
||||
+17
-2
@@ -31,9 +31,21 @@ async function loadTextures() {
|
||||
}
|
||||
|
||||
function onTexturesLoaded() {
|
||||
const radius = 128
|
||||
const chunk = new Chunk(radius, textures)
|
||||
const radius = 16
|
||||
|
||||
const positions = [] as THREE.Vector3[]
|
||||
for (let i = -8; i < 8; i++) {
|
||||
for (let j = -8; j < 8; j++) {
|
||||
positions.push(new THREE.Vector3(i * radius, 0, j * radius))
|
||||
}
|
||||
}
|
||||
|
||||
const chunks = positions.map(
|
||||
(position) => new Chunk(radius, textures, position)
|
||||
)
|
||||
chunks.map((chunk) =>
|
||||
chunk.generateChunk().then(() => {
|
||||
chunk.initializeFaces()
|
||||
chunk.countVisibleFaces()
|
||||
|
||||
const cubes = [] as Block[]
|
||||
@@ -47,6 +59,8 @@ function onTexturesLoaded() {
|
||||
if (face.instancedMesh) scene.add(face.instancedMesh)
|
||||
})
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
camera.position.x = 15
|
||||
@@ -55,6 +69,7 @@ camera.position.z = 15
|
||||
|
||||
function animate(elapsedTimeMs: number) {
|
||||
renderer.render(scene, camera)
|
||||
console.log(renderer.info.render.calls)
|
||||
controls.update()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user