Rotating texture based on object position

Rotating texture based on object position

I have created a model of planet Earth with quite complex material node that includes city lights and different color tones on day-side and night-side and various speculars based on the viewing angle. I created it based on examples in the amazing "Learn 3D with Cheetah3D 6" book by Tonio Loewald. I can post tutorial once I solve the last problem described below.

earth.jpg

What I am trying to achieve now is to create a user-friendly way of rotating the day and night in an animation. So far I found two ways of doing it:
1)
Screen Shot 2016-11-02 at 08.57.04.png
Simply rotating the material in the material properties of an object works fine, but it has its limitations. E.g. it doesn't work when my Earth is saved in Cheetah's Smart Folder - the original material properties are always loaded. Also when my planet is composed of multiple object (e.g. each continent is a separate object), I need to tweak material properties of every one of them.

2)Screen Shot 2016-11-02 at 09.00.49.png
Changing the material node itself by tweaking a "vector" connected to "state" by "dotprod" eliminates the previous problem but instead of an angle, I have to calculate exact vectors related to the given angle. For example 30 degrees rotation is represented by the numbers on the screenshot. Not user-friendly at all.

THE QUESTION IS:
Is there any way, any script, that could rotate the material node based on the position of another object - in this case the Sun?
Simply put, I want to rotate the Sun around the planet with my material node (day and night) being adjusted automatically as the Sun is moving.

I am thinking that if the Sun's coordinates could somehow be transferred into the "vector" in the material node, it would be done. But my scripting skills are non-existing, so I have no clue how or if it can be done.

Thank you for any suggestions
 
Last edited:
Back
Top