threejs


WebGL and Three JS dedicated forum. Here we can discuss about Three JS 3D library.
 
HomeCalendarGalleryFAQSearchRegisterLog in

Share | 
 

 Updating Directional Light

View previous topic View next topic Go down 
AuthorMessage
Khappa MJ

avatar

Posts : 8
Points : 14
Reputation : 0
Join date : 2017-02-10

PostSubject: Updating Directional Light   Tue Feb 21, 2017 12:18 pm

I have also posted this in Reddit:

I need to dinamycally update DiretionalLight parameters. So, some of them like position, intenstity and color are working properly. Problem is in helper and shadow.camera helper. Here I have these code in a function:


light.shadow.camera.right = newVal;
light.shadow.camera.left = -newVal;
light.shadow.camera.updateProjectionMatrix();


but it doesnt update light and helper.
Any help? Please?
Back to top Go down
Atrahasis



Posts : 5
Points : 10
Reputation : 1
Join date : 2017-02-17

PostSubject: Re: Updating Directional Light   Tue Feb 21, 2017 4:07 pm

Your question is about the DirectionnalLightHelper. However the helper is a geometry, with vertices and lines, so if you change the light's camera parameters, you would need to dynamically change the position array of the lines geometry according to your new parameters. Check the DirectionnalLightHelper class for more details.
Back to top Go down
Khappa MJ

avatar

Posts : 8
Points : 14
Reputation : 0
Join date : 2017-02-10

PostSubject: Re: Updating Directional Light   Tue Feb 21, 2017 4:31 pm

Hi Atrahasis and thanks for your reply.
I thought about DirectionnalLightHelper but now my question is: once I've created the helper and light and add both to the scene, how can i juts modify light parameters using helper?

In the threejs examples i hadnt find a good example/tut which explains crearly this, do you know if there is some other resource?

Thanks a lot
Back to top Go down
Atrahasis



Posts : 5
Points : 10
Reputation : 1
Join date : 2017-02-17

PostSubject: Re: Updating Directional Light   Tue Feb 21, 2017 4:47 pm

I havent found a question about that on stackoverflow either so feel free to ask there.

Quote :
how can i juts modify light parameters using helper?

The helper is independant, you cannot do that, I think the only way is my previous answer.
Back to top Go down
Khappa MJ

avatar

Posts : 8
Points : 14
Reputation : 0
Join date : 2017-02-10

PostSubject: Re: Updating Directional Light   Tue Feb 21, 2017 4:51 pm

oh... I found this example in threejs documentation:

Code:

//Create a WebGLRenderer and turn on shadows in the renderer
var renderer = new THREE.WebGLRenderer();
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap

//Create a DirectionalLight and turn on shadows for the light
var light = new THREE.DirectionalLight( 0xffffff, 1, 100 );
light.position.set( 0, 1, 0 ); //default; light shining from top
light.castShadow = true;            // default false
scene.add( light );

//Set up shadow properties for the light
light.shadow.mapSize.width = 512;  // default
light.shadow.mapSize.height = 512; // default
light.shadow.camera.near = 0.5;       // default
light.shadow.camera.far = 500      // default

//Create a sphere that cast shadows (but does not receive them)
var sphereGeometry = new THREE.SphereBufferGeometry( 5, 32, 32 );
var sphereMaterial = new THREE.MeshStandardMaterial( { color: 0xff0000 } );
var sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
sphere.castShadow = true; //default is false
sphere.receiveShadow = false; //default
scene.add( sphere );

//Create a plane that receives shadows (but does not cast them)
var planeGeometry = new THREE.PlaneBufferGeometry( 20, 20, 32, 32 );
var planeMaterial = new THREE.MeshStandardMaterial( { color: 0x00ff00 } )
var plane = new THREE.Mesh( planeGeometry, planeMaterial );
plane.receiveShadow = true;
scene.add( plane );

//Create a helper for the shadow camera (optional)
var helper = new THREE.CameraHelper( light.shadow.camera );
scene.add( helper );

What i basically need now is to modify dinamically these parameters in the example above (its the same):
light.shadow.camera.near = 0.5;
light.shadow.camera.far = 500


How is it possible?
Back to top Go down
Sponsored content




PostSubject: Re: Updating Directional Light   

Back to top Go down
 
Updating Directional Light
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Day/Night Controller
» Kenny Bobien-The Light (Bang The Drum Mixes)
» The Great Crossbow light bowgun - what is it useful for?
» Order Of The Light: The Deathly Artisan
» SYM VTS200 signal light relay

Permissions in this forum:You cannot reply to topics in this forum
threejs :: WEBGL and Three JS Library :: Discussions about WebGL coding via Three.js-
Jump to: