## Calculate the position of the sun by selecting points that p

Discuss about expressions in Clarisse

### Calculate the position of the sun by selecting points that p

Great Clarisse team,I really like a feature of vray. The position and angle of the sun can be automatically calculated by selecting the exposure point on the object. I tried it for many days and wanted to implement it with expressions, but all failed. I asked a mathematician friend, but I couldn't make it an expression in clarisse. I found that none of the parent objects can obtain their location information. This refers to the information of the constrained object, not the parent information. I think this principle is very simple and will greatly improve efficiency. Is there any simpler way to achieve this?
thank you very much
flansrjf

Posts: 48
Joined: Sat Dec 22, 2018 1:56 am

### Re: Calculate the position of the sun by selecting points th

Hi,

Here is a snippet to get the global matrix of an object. With the global matrix, you'll able to calculate the position and the angle of the object whenever it's parented or constrained.

Code: Select all
loc = ix.get_item("project://scene/locator")
matrix = loc.get_module().get_global_matrix()

Cheers
Démian
Isotropix
Technical Artist - Clarisse Specialist

dboude

Posts: 1603
Joined: Mon Jul 03, 2017 10:51 am

### Re: Calculate the position of the sun by selecting points th

Thanks for the reply, I have not learned the matrix. If you want to get the location information, how do you add it after this code?
flansrjf

Posts: 48
Joined: Sat Dec 22, 2018 1:56 am

### Re: Calculate the position of the sun by selecting points th

Hi,

Like this

Code: Select all
loc = ix.get_item("project://scene/locator")
matrix = loc.get_module().get_global_matrix()

pos = ix.api.GMathVec3d()
ix.api.GMathMatrix4x4d.extract_translation(matrix, pos)
Démian
Isotropix
Technical Artist - Clarisse Specialist

dboude

Posts: 1603
Joined: Mon Jul 03, 2017 10:51 am

### Re: Calculate the position of the sun by selecting points th

Hello, thank you very much for your answer. Is this py scripting? But I want to implement it in EXPRESSIONS so that I can see the position of the sun changing in real time
flansrjf

Posts: 48
Joined: Sat Dec 22, 2018 1:56 am

### Re: Calculate the position of the sun by selecting points th

Yes, this is python. I miss understood you. What do you want to achieve? Write an angle to place the hotspot of an environment light ?

If yes you can simply place the hot spot of the env' light at the horizon, then parent the light to a fresh new locator and then use the rotation of the locator to place the hotspot with precision.

Cheers
Démian
Isotropix
Technical Artist - Clarisse Specialist

dboude

Posts: 1603
Joined: Mon Jul 03, 2017 10:51 am

### Re: Calculate the position of the sun by selecting points th

flansrjf

Posts: 48
Joined: Sat Dec 22, 2018 1:56 am

### Re: Calculate the position of the sun by selecting points th

Ok, I understand now. As expressions cannot receive the normal of the object you clicked on it's not possible to do that with expressions.

However, it's simple to create a mini light rig to achieve that. And you can create a script that creates automatically the setup for you and further that controls the settings.

Create a locator and a light. Parent the light to the locator and then you can use the snapping shortcut (S) to snap the locator on the object you clicked on. In the translate tool options make sure that "Align to Normal" is checked.

You can also use a surface constrain if you have moving objects so the locators will follow the moving parts.

Hotspot_Picking.project
(66.4 KiB) Downloaded 250 times

Cheers
Démian
Isotropix
Technical Artist - Clarisse Specialist

dboude

Posts: 1603
Joined: Mon Jul 03, 2017 10:51 am

### Re: Calculate the position of the sun by selecting points th

Thank you very much for your patience and I am very sorry, I feel a better way like this. It does not directly illuminate the vertical point of the surface, but enters the camera through reflection, just like the schematic diagram I drew below.
The locator2 in the picture can also be obtained like the project file you provided, but its coordinate value does not change, and the position where I picked it by get_double is its original position.
At present, I feel that I only need to know the position or normal vector of locator2 to find the position of the light source through the expression.
thank you very much
Attachments
flansrjf

Posts: 48
Joined: Sat Dec 22, 2018 1:56 am

### Re: Calculate the position of the sun by selecting points th

Got it.

Maybe this expression snipper can help you. It calculates the distance between two objects. But it is not taking the global matrix.

Seeprx :

Code: Select all
objectA = get_name("locator");
objectB = get_name("locator1");

xa = get_double(objectA + ".translate[0]");
ya = get_double(objectA + ".translate[1]");
za = get_double(objectA + ".translate[2]");

xb = get_double(objectB + ".translate[0]");
yb = get_double(objectB + ".translate[1]");
zb = get_double(objectB + ".translate[2]");

dist = sqrt(pow((xb - xa),2) + pow((yb - ya),2) + pow((zb - za),2));
dist

Cheers
Démian
Isotropix
Technical Artist - Clarisse Specialist

dboude

Posts: 1603
Joined: Mon Jul 03, 2017 10:51 am

Next

Return to Expressions