Created
February 16, 2021 08:53
-
-
Save guidoschmidt/e43a85faf73dbbcce84fd2b0123622dc to your computer and use it in GitHub Desktop.
three.js fake env map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as THREE from "three"; | |
// Local imports | |
import levelLogic from "@common.js/logic/logic.level.js"; | |
import webGLLogic from "@common.js/logic/logic.webgl.js"; | |
import assetLogic from "@common.js/logic/logic.assets.js"; | |
class EnvironmentSphere { | |
constructor(filepath, radius = 60) { | |
console.assert( | |
filepath !== undefined, | |
"missing filepath for EnvironmentSphere" | |
); | |
var pmremGenerator = new THREE.PMREMGenerator(webGLLogic.values.renderer); | |
assetLogic.values.textureLoader.load(filepath, (texture) => { | |
texture.encoding = THREE.sRGBEncoding; | |
this.envSphere = new THREE.Mesh( | |
new THREE.SphereGeometry(radius, 32, 32), | |
new THREE.MeshBasicMaterial() | |
); | |
this.envSphere.material.side = THREE.DoubleSide; | |
this.envSphere.material.map = texture; | |
this.envSphere.material.needsUpdate = true; | |
levelLogic.values.scene.add(this.envSphere); | |
// const envMap = pmremGenerator.fromEquirectangular(texture).texture; | |
// levelLogic.values.scene.envMap = envMap; | |
// levelLogic.values.scene.background = envMap; | |
// pmremGenerator.dispose(); | |
// texture.dispose(); | |
}); | |
} | |
} | |
export default EnvironmentSphere; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment