Closed vidartf closed 6 years ago
Note: I added the light to the scene, and not the camera (which I see is common in the examples). This was done as I do not want the light to rotate together with the camera.
Can you see if #82 solves the castShadow not updating problem?
Please note that all 3d objects have a look_at
method which can set the 'target': d=DirectionalLight(); d.look_at(d.position, target.position)
.
@jasongrout Regarding the look_at
function, as far as I can tell it sets the rotation of the object? If so, this won't work for DirectionalLight
. From its docs:
A Note about Position, Target and rotation: A common point of confusion for directional lights is that setting the rotation has no effect. This is because three.js's DirectionalLight is the equivalent to what is often called a 'Target Direct Light' in other applications. This means that its direction is calculated as pointing from the light's position to the target's position (as opposed to a a 'Free Direct Light' that just has a rotation component). The reason for this is to allow the light to cast shadows - the shadow camera needs a position to calculate shadows from.
The target is of course not strictly needed - one could instead to an appropriate modification of the position - but the abstraction is nice to have (especially as you can set the target to another object).
Thanks for quoting the docs. It looks like we need to expose the target then. Perhaps the target should be another object3d, which the light will follow?
The docs says that it will accept anything that has a valid position
attribute, but specifying it as another object3d should work well enough.
This works partially in master: You can set the target after light initialization, but if set in the constructor call as a keyword argument the target object disappears. The mechanisms dealing with such objects (InitializedThreeType
) need an overhaul.
Three's
DirectionalLight
should have atarget
in addition toposition
. I also notice that theposition
andcastShadow
attributes ofDirectionalLight
are not correctly synced to the browser (at least, according to the console log).For the following Python code:
The following is logged in the browser console:
It does however work for
Mesh
es.