FORMULA for converting Lighting Data to Sun Direction [PYTHON]

Dose anyone know the formula Roblox Used to convert Lighting Data (eg. TimeOfDay and GeographicLatitude) to the direction of the sun? I know there is a inbuilt Roblox Method but I want to know as I am trying to use this formula for a Blender add-on to replicate Roblox Lighting so i need the actual formula.

Ive tried to rip and read the code from a Sun Position Plugin… but… fr, just look at this Unreadable mess :sob:

function ToTimeOfDay(n)
	local i,f = math.modf(n)
	local m = f*60
	local mi,mf = math.modf(m)
	m = tostring(math.abs(math.floor(m)))
	local s = tostring(math.abs(math.floor(mf*60)))
	return i..":"..string.rep("0",2-#m)..m..":"..string.rep("0",2-#s)..s
end

function rad_sc(n)
	return n/(math.pi*2)
end

function sc_rad(n)
	return n*(math.pi*2)
end

function ToLatLon(d)
	d = Vector3.new(-d.x,-d.y,d.z) -- derp derp derp derp derp
	local lat = math.atan2(d.z,math.sqrt(d.x^2 + d.y^2))
	local lon = math.atan2(d.y,d.x)
	lat = rad_sc(lat)*360 + 23.5
	lon = ToTimeOfDay(rad_sc(lon)*24 - 6)
	return lat,lon
end
1 Like

Just to be sure, you want to be able to get the same Vector3 results as you would get from :GetSunDirection()?

And also, does that snippet of code also give you the desired results? If it does, do you just want it to be redone in a more readable sense?

1 Like

Yes it dose!

No, this one dose the inverse. It takes a direction and converts it to Lighting Data. Its just for reference.

1 Like

And just to be sure, there isn’t one on that plugin that does what you want?

???. I’m a little confused on what you mean… but I think you mean “Are there any existing Blender plugins that do this”. Now I don’t think so as I’ve tried to look before, but even if this dose exist, I think it would be a good exercise for myself to get the hang of BlenderPy.

Is bro fr trying to help me? :wilted_flower: :sob:

Oh no I was referring to the plugin by Clonetrooper1019, does he have a function that does this already or no?

Could you send a url to the plugin?

It’s the plugin that you referred to in your original post.

Uh thats not CloneTrooper’s… I don’t think…

And also no, this plugin doesn’t have what I want… As I said earlier:

Just use the inverse of GetSunDirection() then

Dose bro even know what the inverse of a math function is? :skull:

Basically an inverse is NOT just 1 / function (that’s a reciprocal ), its a version of the same function, that when you Input in to the Inverse its Original Function’s Outputs It returns the the what the Original function’s inputs would be to get that output

Example:

local y_from_normal = foo(x)
local x_from_inverse = foo_inverse(y_from_normal)

print(x_from_inverse == x) -- Should be true in almost all cases, although the sign may change (eg, `x = -1`, but `x_from_inverse = 1`)

Examples of inverse functions are: x^2 and sqrt(x), 10^x and log(x), tan(x) and arctan(x) (yes, arctan2(), the fuction used for converting x,yangle is just a slightly modified version of the arctan() the inverse of tan()), Etc.

To create an inverse function is not easy, as you have to create an entirely new function by swaping, X and Y and then solving for X. (Eg: y = 10x + 3x = 10y + 3x - 3 = 10y1/10(x - 3) = y1/10x - 3/10 = yy = 1/10x - 3/10)

sorry for the math lesson folks :sob:


Short Explination of Inverse Functions

Also GetSunDirection() is the exact function I want, its just that since I’m not currently inside Roblox, I need a function that esentially dose the same with just the ClockTime and GeographicLatitude values passed in.

why can’t you use GetSunDirection()?

i meant this

local d = game.Lighting:GetSunDirection()
local Direction = -d

WHY DOSE NO ONE READ THE ORIGNAL POST :sob:

CHAT REEAAD :skull: :wilted_flower:

I fr feel like I have to edit the title :skull: I’m actually going to cry :folded_hands: :sob:

I already read the title. You can use game.Lighting:GetSunDirection() to get the sun direction. No need to reinvent the wheel.

No, he can’t, he is referring to that method because that is what is in the actual ROBLOX studio, he wants to do that but in Blender rather than in our studio engine.

1 Like

I dont think game.Lighting:GetSunDirection() exists in Python dawg :man_facepalming: :sob: :wilted_flower:

I think these comments are making me go insane :woozy_face: :laughing:

Then use Lua‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

OM*G :sob: :sob: :sob: :sob:
I fr wish I could ban people off threads :sob:

Oh wait… I think @Imperiector Is ragebaiting :sob: NOOOOOOOOOOOOOOOOOOOOO

No. Seriously why do you need this, what are you trying to do? Why can’t you just use the built-in function under Lighting?