If we add PointLight to a Group(or anything other than scene) along with the PointLightHelper. Then PointLightHelper does not move along with the PointLight.
I checked the documentation of PointLightHelper, it says following-
.matrix : Object
Reference to the pointLight’s matrixWorld
I think, this is causing the problem. Because, if the we translate the PointLight parent Group by 10 unit along with the X axis. So PointLight matrixWorld would have 10 unit value in the first row of the last column but PointLightHelper would have the same also but in it’s matrix, and that means it has 10 unit displacement along with X axis relative to it’s parent Group. So the parent group is already has 10 unit displacement along with X axis relative to scene center. But PointLightHelper now has 10+10=20 unit displacement along with X axis relative to scene center which is not correct.
Please suggest a workaround.
Just curious: Would it work if the PointLight
is in a Group
, but the PointLightHelper
is outside?
If PointLightHelper is directly in scene but PointLight is inside a group it works. Because matrix and matrixWorld is same at that point for the PointLightHelper.
So, is this a workaround or not?
No sorry mate, I am already doing this. But I want to keep PointLight and PointLightHelper inside same parent. So, a solution that enables me to do that would be the workaround.
Does this work:
var light = new THREE.PointLight( 'royalblue', 1 ),
helper = new THREE.PointLightHelper( light.clone() ); // ← the magic is here
var lightGroup = new THREE.Group( );
lightGroup.add( light, helper );
It only works when both are in a same Group, but it doesn’t work when both are directly inside the scene. Actually, what I want is to keep them inside same parent it could be a Group (or even in a Group that is situated deep inside multiple level of Groups) or the Scene.
You have a solution when the light and the helper are inside the same group. You have a solution when they are inside a scene. You can just combine both solutions. If the light is a child of the scene, add a helper for the light; otherwise, add a helper for the clone of the light.
Hi mate, sorry for late reply. Actually, I am creating an 3D scene editor, it does not have anything fixed. We cannot have different solution for different cases. We need a unique solution, because just imagine in a scene element tree, if user drags PointLight to a Group from the Scene or to the Scene to from a Group. We cannot change between different solutions, for both PointLight and PointLightHelper. It will be very hard to manage, because it’s not only PointLight rather it could have huge list of things to manage. There is nothing to be hardcoded everything is dynamic. So, we need a solution which works regardless of which structure we are putting the PointLight in.
I don’t know what the vision is behind to develop PointLightHelper in such a way, so that it only works correctly when it’s directly under the Scene. If does not have any specific vision or reason behind doing this, then it’s better to fix the code inside PointLightHelper rather than beating around the bush.
Then, just make your own class MyPointLightHelper
that installs a helper as a child of the light and without the automatic update of position. In this way when a helper is created, it does not need to be added to the scene or to the hosting group.
Click on the image to try it (red light/helper are in the scene, blue light/helper is in a group):

Edit: replaced the link with a link to CodePen.
1 Like
I really appreciate your dedication to solve the problem. Also, I think the idea you are proposing would work for my case. Thanks a lot buddy.
1 Like