Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add optional envmap intensity #269

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/XRControllerModelFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import { fetchProfile, GLTFLoader, MotionController, MotionControllerConstants }
const DEFAULT_PROFILES_PATH = 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles'
const DEFAULT_PROFILE = 'generic-trigger'

const applyEnvironmentMap = (envMap: Texture, obj: Object3D): void => {
const applyEnvironmentMap = (envMap: Texture, envMapIntensity: number, obj: Object3D): void => {
obj.traverse((child) => {
if (child instanceof Mesh && 'envMap' in child.material) {
child.material.envMap = envMap
child.material.envMapIntensity = envMapIntensity
child.material.needsUpdate = true
}
})
}

export class XRControllerModel extends Object3D {
envMap: Texture | null
envMapIntensity: number
motionController: MotionController | null
scene: Object3D | null

Expand All @@ -24,16 +26,18 @@ export class XRControllerModel extends Object3D {

this.motionController = null
this.envMap = null
this.envMapIntensity = 1
this.scene = null
}

setEnvironmentMap(envMap: Texture): XRControllerModel {
if (this.envMap == envMap) {
setEnvironmentMap(envMap: Texture, envMapIntensity = 1): XRControllerModel {
if (this.envMap === envMap && this.envMapIntensity === envMapIntensity) {
return this
}

this.envMap = envMap
applyEnvironmentMap(this.envMap, this)
this.envMapIntensity = envMapIntensity
applyEnvironmentMap(this.envMap, envMapIntensity, this)

return this
}
Expand Down Expand Up @@ -179,7 +183,7 @@ function addAssetSceneToControllerModel(controllerModel: XRControllerModel, scen

// Apply any environment map that the mesh already has set.
if (controllerModel.envMap) {
applyEnvironmentMap(controllerModel.envMap, scene)
applyEnvironmentMap(controllerModel.envMap, controllerModel.envMapIntensity, scene)
}

// Add the glTF scene to the controllerModel.
Expand Down