Compare commits
1 Commits
27e9e30cbc
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
fa2bd33b98
|
@@ -1,74 +0,0 @@
|
||||
import * as THREE from 'three';
|
||||
|
||||
export default class MazeMesh extends THREE.InstancedMesh {
|
||||
constructor( width, length, height, material ) {
|
||||
super(
|
||||
new THREE.BoxGeometry( 1, height, 1 ),
|
||||
material,
|
||||
width*length - 2
|
||||
);
|
||||
this.length = length
|
||||
this.width = width
|
||||
this.map = new Array(length).fill().map(() => new Array(width).fill(1))
|
||||
this.start = new THREE.Vector3(width/2, .1, length/2)
|
||||
this.exit = new THREE.Vector3(Math.floor(width/2), 0, 1)
|
||||
|
||||
this.dig(this.exit)
|
||||
this.dig(new THREE.Vector3(Math.floor(width/2), 0, 0))
|
||||
this.build ( this.exit )
|
||||
let matrix = new THREE.Matrix4()
|
||||
this.count = 0
|
||||
this.map.forEach((row, z) => {
|
||||
row.forEach((isWall, x) => {
|
||||
if (isWall) {
|
||||
matrix.setPosition( x + .5 - width/2, 0.5, z + .5 - length/2)
|
||||
this.setMatrixAt( this.count, matrix );
|
||||
this.count++
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
dig(position) {
|
||||
this.map[position.z][position.x] = 0
|
||||
}
|
||||
|
||||
static DIRECTIONS = [
|
||||
new THREE.Vector3( 0, 0, -1),
|
||||
new THREE.Vector3( 0, 0, 1),
|
||||
new THREE.Vector3(-1, 0, 0),
|
||||
new THREE.Vector3( 1, 0, 0),
|
||||
]
|
||||
build(position) {
|
||||
for (var direction of Array.from(this.constructor.DIRECTIONS).sort(x => .5 - Math.random())) {
|
||||
var step1 = position.clone().add(direction)
|
||||
var step2 = step1.clone().add(direction)
|
||||
if (this.isWall(step2) == 1) {
|
||||
this.dig(step1)
|
||||
this.dig(step2)
|
||||
this.count -= 2
|
||||
this.build(step2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isWall(position) {
|
||||
if (0 <= position.x && position.x < this.width &&
|
||||
0 <= position.y &&
|
||||
0 <= position.z && position.z < this.length) {
|
||||
return this.map[Math.floor(position.z)][Math.floor(position.x)]
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
collision(position) {
|
||||
return this.isWall(this.worldToLocal(position))
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.map.map(row =>
|
||||
row.map(isWall => isWall? "██":" ").join("")
|
||||
).join("\n")
|
||||
}
|
||||
}
|
||||
64
main.js
@@ -5,7 +5,6 @@ import { Water } from 'three/addons/objects/Water.js'
|
||||
import { PointerLockControls } from 'three/addons/controls/PointerLockControls.js'
|
||||
import { GUI } from 'three/addons/libs/lil-gui.module.min.js'
|
||||
import { OctreeHelper } from 'three/addons/helpers/OctreeHelper.js'
|
||||
import { CSM } from 'three/addons/csm/CSM.js';
|
||||
import Stats from 'three/addons/libs/stats.module.js'
|
||||
|
||||
import MazeMesh from './MazeMesh.js'
|
||||
@@ -184,26 +183,27 @@ const sideGroundMaterial = new THREE.MeshStandardMaterial({
|
||||
roughness : wallMaterial.roughness,
|
||||
metalness : wallMaterial.metalness,
|
||||
})
|
||||
loader.load('Poly-cobblestone-wall/ao_map.jpg', (texture) => {
|
||||
wallMaterial.aoMap = texture
|
||||
wallMaterial.metalnessMap = texture
|
||||
wallMaterial.needsUpdate = true
|
||||
sideGroundMaterial.map.wrapS = sideGroundMaterial.map.wrapT = THREE.RepeatWrapping
|
||||
sideGroundMaterial.map.repeat.set(mazeWidth, 20)
|
||||
sideGroundMaterial.map.rotation = Math.PI
|
||||
sideGroundMaterial.normalMap.wrapS = sideGroundMaterial.normalMap.wrapT = THREE.RepeatWrapping
|
||||
sideGroundMaterial.normalMap.repeat.set(mazeWidth, 20)
|
||||
sideGroundMaterial.normalMap.rotation = Math.PI
|
||||
sideGroundMaterial.roughnessMap.wrapS = sideGroundMaterial.roughnessMap.wrapT = THREE.RepeatWrapping
|
||||
sideGroundMaterial.roughnessMap.repeat.set(mazeWidth, 20)
|
||||
sideGroundMaterial.roughnessMap.rotation = Math.PI
|
||||
|
||||
const sidegroundTexture = texture.clone()
|
||||
loader.load('Poly-cobblestone-wall/ao_map.jpg', (texture) => {
|
||||
wallMaterial.aoMap = texture
|
||||
wallMaterial.metalnessMap = texture
|
||||
wallMaterial.needsUpdate = true
|
||||
|
||||
const sidegroundTexture = texture.clone()
|
||||
sidegroundTexture.wrapS = sidegroundTexture.wrapT = THREE.RepeatWrapping
|
||||
sidegroundTexture.repeat.set(mazeWidth, 20)
|
||||
sidegroundTexture.rotation = Math.PI
|
||||
|
||||
sideGroundMaterial.map.wrapS = sideGroundMaterial.map.wrapT = THREE.RepeatWrapping
|
||||
sideGroundMaterial.map.repeat.set(mazeWidth, 20)
|
||||
sideGroundMaterial.map.rotation = Math.PI
|
||||
sideGroundMaterial.normalMap.wrapS = sideGroundMaterial.normalMap.wrapT = THREE.RepeatWrapping
|
||||
sideGroundMaterial.normalMap.repeat.set(mazeWidth, 20)
|
||||
sideGroundMaterial.normalMap.rotation = Math.PI
|
||||
sideGroundMaterial.aoMap = sidegroundTexture
|
||||
sideGroundMaterial.roughnessMap.wrapS = sideGroundMaterial.roughnessMap.wrapT = THREE.RepeatWrapping
|
||||
sideGroundMaterial.roughnessMap.repeat.set(mazeWidth, 20)
|
||||
sideGroundMaterial.roughnessMap.rotation = Math.PI
|
||||
sideGroundMaterial.aoMap = sidegroundTexture
|
||||
sideGroundMaterial.metalnessMap = sidegroundTexture
|
||||
|
||||
sideGroundMaterial.needsUpdate = true
|
||||
@@ -246,13 +246,7 @@ const groundMaterial = new THREE.MeshStandardMaterial({
|
||||
aoMap : loader.load('angled-blocks-vegetation/ao.webp', repeatGroundMaterial),
|
||||
metalnessMap: loader.load('angled-blocks-vegetation/ao-roughness-metalness.webp', repeatGroundMaterial),
|
||||
normalMap : loader.load('angled-blocks-vegetation/normal-dx.webp', repeatGroundMaterial),
|
||||
roughnessMap: loader.load('angled-blocks-vegetation/ao-roughness-metalness.webp', repeatGroundMaterial),
|
||||
/*hexTiling : {
|
||||
patchScale: 1,
|
||||
useContrastCorrectedBlending: true,
|
||||
lookupSkipThreshold: 0.01,
|
||||
textureSampleCoefficientExponent: 32,
|
||||
}*/
|
||||
roughnessMap: loader.load('angled-blocks-vegetation/ao-roughness-metalness.webp', repeatGroundMaterial)
|
||||
})
|
||||
|
||||
const ground = new THREE.Mesh(
|
||||
@@ -296,7 +290,7 @@ const ocean = new Water(waterGeometry, {
|
||||
waterColor : 0x001e0f,
|
||||
distortionScale: 3.7,
|
||||
fog : scene.fog !== undefined,
|
||||
alpha : 0.7
|
||||
alpha : 0.9
|
||||
})
|
||||
ocean.rotation.x = - Math.PI / 2
|
||||
ocean.position.y = -0.2
|
||||
@@ -526,27 +520,9 @@ if (dev) {
|
||||
wallMaterialFolder.add(wallMaterial, "roughness").min(0).max(1)
|
||||
wallMaterialFolder.add(wallMaterial, "metalness").min(0).max(1)
|
||||
wallMaterialFolder.add(wallMaterial, "aoMapIntensity").min(-10).max(10)
|
||||
wallMaterialFolder.add(wallMaterial, "bumpScale").min(-10).max(10).onChange(() => wallMaterial.needsUpdate = true)
|
||||
wallMaterialFolder.add(wallMaterial.normalScale, "x")
|
||||
wallMaterialFolder.add(wallMaterial.normalScale, "y")
|
||||
wallMaterialFolder.close()
|
||||
|
||||
if (wallMaterial?.hexTiling) {
|
||||
const hexTilingFolder = gui.addFolder('Hex Tiling')
|
||||
if (wallMaterial?.hexTiling?.patchScale) {
|
||||
const wallMaterialFolder = hexTilingFolder.addFolder("wall")
|
||||
wallMaterialFolder.add(wallMaterial.hexTiling, "patchScale", 0, 10)
|
||||
wallMaterialFolder.add(wallMaterial.hexTiling, "useContrastCorrectedBlending")
|
||||
wallMaterialFolder.add(wallMaterial.hexTiling, "lookupSkipThreshold", 0, 1)
|
||||
wallMaterialFolder.add(wallMaterial.hexTiling, "textureSampleCoefficientExponent", 0, 64).name("SampleCoefExp")
|
||||
}
|
||||
if (groundMaterial?.hexTiling?.patchScale) {
|
||||
const groundMaterialFolder = hexTilingFolder.addFolder("ground")
|
||||
groundMaterialFolder.add(groundMaterial.hexTiling, "patchScale", 0, 10)
|
||||
groundMaterialFolder.add(groundMaterial.hexTiling, "useContrastCorrectedBlending")
|
||||
groundMaterialFolder.add(groundMaterial.hexTiling, "lookupSkipThreshold", 0, 1)
|
||||
groundMaterialFolder.add(groundMaterial.hexTiling, "textureSampleCoefficientExponent", 0, 64).name("SampleCoefExp")
|
||||
}
|
||||
hexTilingFolder.close()
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
|
Before Width: | Height: | Size: 1.0 MiB |
|
Before Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 542 KiB |
|
Before Width: | Height: | Size: 1.6 MiB |
|
Before Width: | Height: | Size: 2.0 MiB |
|
Before Width: | Height: | Size: 475 KiB |
|
Before Width: | Height: | Size: 7.2 MiB |
|
Before Width: | Height: | Size: 2.3 MiB |
|
Before Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 55 KiB |
|
Before Width: | Height: | Size: 9.1 MiB |
|
Before Width: | Height: | Size: 1.8 MiB |
|
Before Width: | Height: | Size: 396 KiB |
|
Before Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 210 KiB |
|
Before Width: | Height: | Size: 252 KiB |
|
Before Width: | Height: | Size: 301 KiB |
|
Before Width: | Height: | Size: 135 KiB |
|
Before Width: | Height: | Size: 243 KiB |