From 9721b311ebb457703c893acc90f0e6d4ba22268b Mon Sep 17 00:00:00 2001
From: adrien <adrien@malingrey.fr>
Date: Thu, 3 Oct 2024 00:31:12 +0200
Subject: [PATCH] move mino materials to InstancedMino.prototype

---
 jsm/Tetrominoes.js | 51 +++++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/jsm/Tetrominoes.js b/jsm/Tetrominoes.js
index 8902a40..504306d 100644
--- a/jsm/Tetrominoes.js
+++ b/jsm/Tetrominoes.js
@@ -70,25 +70,6 @@ const sideMaterial = new THREE.MeshStandardMaterial({
 
 
 export class InstancedMino extends THREE.InstancedMesh {
-    static materials = {
-        Plasma: new THREE.MeshStandardMaterial({
-            envMap: environment,
-            side: THREE.DoubleSide,
-            transparent: true,
-            opacity: 0.7,
-            roughness: 0.6,
-            metalness: 1,
-        }),
-        Espace: new THREE.MeshStandardMaterial({
-            envMap: environment,
-            side: THREE.DoubleSide,
-            transparent: true,
-            opacity:   0.8,
-            roughness: 0.1,
-            metalness: 0.99,
-        })
-    }
-
     constructor() {
         let minoFaceShape = new THREE.Shape()
         minoFaceShape.moveTo(.1, .1)
@@ -115,13 +96,13 @@ export class InstancedMino extends THREE.InstancedMesh {
         if (theme == "Rétro") {
             this.resetColor()
             this.update = this.updateOffset
-            if (this.constructor.materials["Rétro"]) {
-                this.material = this.constructor.materials["Rétro"]
+            if (this.materials["Rétro"]) {
+                this.material = this.materials["Rétro"]
             } else {
-                this.constructor.materials["Rétro"] = []
-                const loadingManager = new THREE.LoadingManager(() => this.material = this.constructor.materials["Rétro"])
+                this.materials["Rétro"] = []
+                const loadingManager = new THREE.LoadingManager(() => this.material = this.materials["Rétro"])
                 new THREE.TextureLoader(loadingManager).load("images/sprites.png", (texture) => {
-                    this.constructor.materials.Rétro[0] = this.constructor.materials.Rétro[2] = new TileMaterial({
+                    this.materials.Rétro[0] = this.materials.Rétro[2] = new TileMaterial({
                         color: COLORS.RETRO,
                         map: texture,
                         bumpMap: texture,
@@ -132,7 +113,7 @@ export class InstancedMino extends THREE.InstancedMesh {
                     }, 8, 8)
                 })
                 new THREE.TextureLoader(loadingManager).load("images/edges.png", (texture) => {
-                    this.constructor.materials.Rétro[1] = this.constructor.materials.Rétro[3] = this.constructor.materials.Rétro[4] = this.constructor.materials.Rétro[5] = new TileMaterial({
+                    this.materials.Rétro[1] = this.materials.Rétro[3] = this.materials.Rétro[4] = this.materials.Rétro[5] = new TileMaterial({
                         color: COLORS.RETRO,
                         map: texture,
                         bumpMap: texture,
@@ -145,7 +126,7 @@ export class InstancedMino extends THREE.InstancedMesh {
             }
         } else {
             this.update = this.updateColor
-            this.material = this.constructor.materials[theme]
+            this.material = this.materials[theme]
         }
     }
 
@@ -188,6 +169,24 @@ export class InstancedMino extends THREE.InstancedMesh {
         }
     }
 }
+InstancedMino.prototype.materials = {
+    Plasma: new THREE.MeshStandardMaterial({
+        envMap: environment,
+        side: THREE.DoubleSide,
+        transparent: true,
+        opacity: 0.7,
+        roughness: 0.6,
+        metalness: 1,
+    }),
+    Espace: new THREE.MeshStandardMaterial({
+        envMap: environment,
+        side: THREE.DoubleSide,
+        transparent: true,
+        opacity:   0.8,
+        roughness: 0.1,
+        metalness: 0.99,
+    })
+}
 
 
 class Mino extends THREE.Object3D {