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

Change DirectionalLight #173

Open
adamasturia opened this issue Apr 15, 2024 · 1 comment
Open

Change DirectionalLight #173

adamasturia opened this issue Apr 15, 2024 · 1 comment

Comments

@adamasturia
Copy link

i'm trying to modify the default DirectionalLight using useEffect, but the scene it loads doesn't yet have the DirectionalLight as its child:

useEffect(()=>{
    // const globeEl = useRef()
    debugger
    var ArtificialLight = new THREE.DirectionalLight(0xffffff, 0.6)
    ArtificialLight.position.set( -2, -1, 1 );
    oGlobeEl.current.scene().add(ArtificialLight )
    //JSON.stringify(oGlobeEl.current.scene().children.find(obj3d => obj3d.type == 'DirectionalLight'))        
},[oGlobeEl])

oGlobeEl.current.scene().children
[Mesh]
Mesh {isObject3D: true, uuid: '86eda375-6611-413d-8df9-a2ef4f367ff5', name: '', type: 'Mesh', parent: Scene, …}

If I try to use useEffect without passing the globe as reference I also get the same result:
useEffect(()=>{
// const globeEl = useRef()
debugger
var ArtificialLight = new THREE.DirectionalLight(0xffffff, 0.6)
ArtificialLight.position.set( -2, -1, 1 );
oGlobeEl.current.scene().add(ArtificialLight )
//JSON.stringify(oGlobeEl.current.scene().children.find(obj3d => obj3d.type == 'DirectionalLight'))
},[oGlobeEl])

oGlobeEl.current.scene().children
[Mesh]
Mesh {isObject3D: true, uuid: '86eda375-6611-413d-8df9-a2ef4f367ff5', name: '', type: 'Mesh', parent: Scene, …}

image

I've noticed you mention a lights method in the Render control but I found no example of its usage, not I have managed to access said method.

Moreover, the other issue opened regarding this doesn't show a clear way of addressing this issue (#17), since it only mentions the code bit being used outside of useEffect, but doesn't specify where.

@vasturiano
Copy link
Owner

@adamasturia you should use the lights method to manipulate the lights. You access this method via the component ref.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants