Hi everyone, I am creating a simple day/night cycle system for a small game project I am working on. For now, I have got the sun lamp to simulate sun rise and sun set by simply creating a small Python script using the applyRotation code which rotates the sun lamp continuously. I have some sky-dome textures for different times of the day, what I would like to do is create different sky-domes for each time (morning, mid morning, mid day etc…) and use the replace mesh code to change the sky-dome mesh depending on the angle of the sun lamp. I imagine that this could be done with an if statement but i am a complete novice to python, does anybody know of a way to do this? I am using blender 2.66 by the way.
Do you know what angles you want to map to which meshes?
Yes, since the first post I have played around a bit with the code. I have managed to get the rotation of the sun lamp using the code "sun.worldOrientation.to_euler() and printed it to the console. From here I have written some if statements that print some text (either “Morning, Mid day, Dawn, Mid night”) to the console so I know it is detecting the angles correctly and so far this works. At the moment, I am struggling to replace this test with the actual mesh replacement, I have used the code “scene = logic.getCurrentScene()” and “scene.objects[“Morning”]” to get one of the skydomes available in the python script. To replace the mesh I have replaced the if statement console message with "morning.replaceMesh(“Night”, True, True) which throws an error in the console when the angle is detected. Sorry if this is confusing, it’s the furthest I’ve got with python.
What does the System Console say?
The consol errors are:
Python script error - object ‘sun’, controller ‘Python’:
Traceback <most recent call lat>:
File “timecycle.py”, line 25 in <module>
File “timecycle.py”, line 14, in main
ValueError: gameOB.replaceMesh<value>: KX_GameObject, requested name “Night” did not match any KX_MeshProxy in this scene
Do you have a Mesh called “Night” in your scene? Be sure to check that there is a Mesh called “Night” and not just an Object called “Night”. Click on your Object that should represent the “Night” then double check that the “Mesh” tab in the Properties window has a name of “Night”. If you didn’t change this then it probably defaulted to something like “Sphere.001” or “Cube.003”.
thanks for the reply, it didnt cross my mind to check the mesh name. I’ll have a look and see if this fixes it!
sorry to double post, that fixed the problem it works perfectly! thanks for your help
Check out martins sky implementation in game engine resource