question

强 avatar image
0 Likes"
asked Phil BoBo commented

How to use the code to set the position of the light source

How to use the code to set the position of the light source, I want to change the position of the light source over time.

Thanks a lot.

FlexSim 19.1.0
how to use the code to set the position of the light source
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Brandon Peterson avatar image
0 Likes"
Brandon Peterson answered Phil BoBo commented

You can set the location and rotation the same way as any other object in the model.

Here is one solution for you:

Object tempLight = Model.find("DirectionalLight1");
Vec3 tempVec;
tempVec.x = tempLight.location.x+1;
tempVec.y = tempLight.location.y+1;
tempVec.z = tempLight.location.z;
tempLight.location = tvec;

Here is another that does not use the Vec3 variable type:

Object tempLight = Model.find("DirectionalLight1");
tempLight.location.x += 1;
tempLight.location.y += 1;

I hope one of these works for you, Brandon

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Phil BoBo avatar image Phil BoBo ♦♦ commented ·

Brandon's solution works if you have Light objects in your model in FlexSim 2020 or later.

If you are using an earlier version of FlexSim or you aren't using Light objects, then you can modify the values of the view's light sources.

For example:

Object current = ownerobject(c);
treenode view = param(1);

treenode light = first(viewlights(view));
double x = fmod(time(), 10.0) - 5.0;
double y = -1.10;
double z = 1.5;
set(rank(light, 1), x);
set(rank(light, 2), y);
set(rank(light, 3), z);
1 Like 1 ·