texture on all faces

This commit is contained in:
Adrien MALINGREY 2024-10-01 01:57:38 +02:00
parent f7b7b74e01
commit 3c8fc95e23
2 changed files with 27 additions and 10 deletions

View File

@ -12,7 +12,7 @@ export class TetraGUI extends GUI {
this.pauseButton = this.add(game, "pause").name("Pause").hide() this.pauseButton = this.add(game, "pause").name("Pause").hide()
this.resumeButton = this.add(game, "resume").name("Reprendre").hide() this.resumeButton = this.add(game, "resume").name("Reprendre").hide()
this.stats = this.addFolder("Stats").hide() this.stats = this.addFolder("Statistiques").hide()
this.stats.add(stats, "time").name("Temps").disable().listen() this.stats.add(stats, "time").name("Temps").disable().listen()
this.stats.add(stats, "score").name("Score").disable().listen() this.stats.add(stats, "score").name("Score").disable().listen()
this.stats.add(stats, "highScore").name("Meilleur score").disable().listen() this.stats.add(stats, "highScore").name("Meilleur score").disable().listen()
@ -30,17 +30,14 @@ export class TetraGUI extends GUI {
this.settings.add(settings, "theme", ["Plasma", "Espace", "Rétro"]).name("Thème").onChange(theme => { this.settings.add(settings, "theme", ["Plasma", "Espace", "Rétro"]).name("Thème").onChange(theme => {
scene.theme = theme scene.theme = theme
Mino.meshes.material = Mino.materials[theme] Mino.meshes.theme = theme
if (theme == "Rétro") { if (theme == "Rétro") {
playfield.edge.visible = false playfield.edge.visible = false
playfield.retroEdge.visible = true playfield.retroEdge.visible = true
Mino.meshes.resetColor()
Mino.meshes.update = Mino.meshes.updateOffset
music.src = "audio/Tetris_MkVaffQuasi_Ultimix_OC_ReMix.mp3" music.src = "audio/Tetris_MkVaffQuasi_Ultimix_OC_ReMix.mp3"
} else { } else {
playfield.edge.visible = true playfield.edge.visible = true
playfield.retroEdge.visible = false playfield.retroEdge.visible = false
Mino.meshes.update = Mino.meshes.updateColor
music.src = "audio/benevolence.m4a" music.src = "audio/benevolence.m4a"
} }
}) })

View File

@ -90,6 +90,25 @@ class InstancedMino extends THREE.InstancedMesh {
this.instances.clear() this.instances.clear()
} }
set theme(theme) {
this._theme = theme
if(Mino.materials[theme]) Mino.meshes.material = Mino.materials[theme]
if (theme == "Rétro") {
this.geometry = Mino.retroGeometry
this.position.set(.5, .5, .5)
this.resetColor()
this.update = Mino.meshes.updateOffset
} else {
this.geometry = Mino.geometry
this.position.set(0, 0, 0)
this.update = Mino.meshes.updateColor
}
}
get theme() {
return this._theme
}
setOffsetAt(index, offset) { setOffsetAt(index, offset) {
this.offsets[2*index] = offset.x this.offsets[2*index] = offset.x
this.offsets[2*index + 1] = offset.y this.offsets[2*index + 1] = offset.y
@ -148,12 +167,11 @@ class Mino extends THREE.Object3D {
opacity: 0.8, opacity: 0.8,
roughness: 0.1, roughness: 0.1,
metalness: 0.99, metalness: 0.99,
}), })
Rétro: [sideMaterial, sideMaterial, sideMaterial, sideMaterial, sideMaterial, sideMaterial]
} }
static { static {
new THREE.TextureLoader().load("images/sprites.png", (texture) => { new THREE.TextureLoader().load("images/sprites.png", (texture) => {
this.materials.Rétro[0] = this.materials.Rétro[2] = new TileMaterial({ this.materials.Rétro = new TileMaterial({
color: 0xd0d4c1, color: 0xd0d4c1,
map: texture, map: texture,
bumpMap: texture, bumpMap: texture,
@ -162,6 +180,7 @@ class Mino extends THREE.Object3D {
metalness: 0.8, metalness: 0.8,
transparent: true, transparent: true,
}, 8, 8) }, 8, 8)
if (this.meshes.theme == "Rétro") this.meshes.material = this.materials.Rétro
}) })
} }
static meshes static meshes
@ -181,8 +200,9 @@ class Mino extends THREE.Object3D {
bevelOffset: 0, bevelOffset: 0,
bevelSegments: 1 bevelSegments: 1
} }
let minoGeometry = new THREE.ExtrudeGeometry(minoFaceShape, minoExtrudeSettings) this.geometry = new THREE.ExtrudeGeometry(minoFaceShape, minoExtrudeSettings)
this.meshes = new InstancedMino(minoGeometry, this.materials.Plasma, 2*ROWS*COLUMNS) this.retroGeometry = new THREE.BoxGeometry()
this.meshes = new InstancedMino(this.geometry, this.materials.Plasma, 2*ROWS*COLUMNS)
} }
constructor(color, offset) { constructor(color, offset) {