I wanted it all in one place and because the Notepad++ script with the button didn't seem to connect with the expression editor that well I thought of just doing the script fully in the Maya Python editor so that way it was a easy copy and paste into that and click enter saving time and effort for the end user.
The pictures below are in Notepad++ because I copied the code over to it just so I was able to save it and take it to my home PC.
As it was going into Maya Python editor instead a lot of the code I wanted to end up changing, one of the main things I wanted to change was getting rid of the UI, as the idea was to have a random generator of numbers change the weather states instead.
On my learning contract I said I was planning on having a UI system on which you could control the season or/and climate of the weather, however, I wasn't sure I would get that done in time.
Once the UI was deleted from the script it was time to change a few other things around too. I also had a look at the agency script a while back because I wanted to see how to get the expression editor running each frame like that script.
After looking at it and trying to understand what I was looking at, I began to get back to my edits. One of the first things to edit to start of with was the running function, this needed all of the global variables I wanted to start of with and to edit.
I began now with making the function to have a random number set when it snows or rains.
At the top of the script I'm able to get the random number by using:
import random;This allows to get the function to have this work.
In the state change I have a grace frame so that there is some time before it goes right into another weather state because sometimes the transition would be to quick.
With this part of the script, it is at the start of the script so we can have our variables.
From the random number script you can see here the variables for the rain and snow limit, if I have time I'll make it so that you can control what season that it is in, so say for summer it has no change of snowing but some change of raining and for something like winter it has more change of snowing than being dry.
We also have some frame constraints and the transition of the frames.
You can also see the grace period on which I just mentioned, this is just to make sure it doesn't change weather states to fast so there is a pause between each one.
This run function was so that the expression editor would run this each frame, on which I got able to work with less issues than when trying to get it to grab information from a Notepad++ version of the script.
I created an if statement for the very start of the timeline, this was so that if the simulation had been running and it was a snow/rain state that when you click play from the start it would force set it to dry instead of continuing from the last one.
This part of the code is the same for both the snow and the dry state as well.
It is an if else statement area on which controls the lerp change and then when at it's peak will then go through another random number so that it can know when to change back to its reversed version. To get it working on the reserved lerp it has to go to a dry state first, I made it so that it could not lerp from snow to rain, only rain to dry then to snow and vice versa. The reasoning behind this choice was that when the materials lerped together from snow and rain it wouldn't transition well as the shader had issues. If I had time and went into developing this further I would have more states so that it would transition to a icy state and what not.
This part is the only section that didn't really change from the Notepad++ version I did.
The only changes in this part is the variable on which is used on the if else statement and adding the lerp to change the transition.
as you can see I'm using something called a sigmoid to lerp it in via a sigmoid curve.
Here is the part with the lerp, I have placed in two versions too, that for the lerp with goes to 0-1 and the other one which is the inverted version of that.
This is so that when we go into the dry state it will use the inverted version of the lerp.
This part took me a little while to work out as I wasn't fully sure how to get the frame parts working, a friend of mine who is a programmer helped me get it working to the point where the code looked like this.
This part I also had my programming friend help me with, I wasn't even sure what it was at the beginning but this was because I wanted to have the snow material to change slower because it changed just as the snow particles would drop. It still isn't perfect and I'm going to try next week figure out a better way to get it going, however, it could mean either another lerp will be needed or another grace sort of period for it.
To work out the math for this sigmoid curve we used this website - https://rechneronline.de/function-graphs/
To get this all working I would run it through the Maya Python editor and it would run once I got the expression editor loaded which the code for that was this.
With all this together now when I push play it will then run the random range and then choose one of the weather states at random and then when it changes it will keep on going.
Next week I want to try and finish it up by making a UI system for the user to be able to choose the season.
No comments:
Post a Comment