Monday, 25 April 2016

Finalization & Conclusion

As I wanted to make sure I met most of what I set out to do from the learning contract I wanted to create a UI.
The original idea was to make it so that the user could use this to change what season and climate the weather system was located, however, because of lack of time I had chosen to make the season one, this way I still had a UI the user could use.


For the UI I had some simple text to explain what the UI does and then 4 buttons for each season.
Each button season will use a function on which will set the values of the rain and snow so that they either have more or less of a chance of happening.
Like every time I write a UI, I make sure that if the UI already exists that it will delete it self it the script is executed again to save from having several duplicates on the screen at once.
The UI also has Spring as the default season.


As you can see with this part of the code, when it comes to summer the chance of it snowing is 0, the random range can hit 0 but with this being a 1 out of a 1000 chance it is rare that it will snow.
I could have the snow not happen all together but because it can snow in some places during the summer though it mostly is rare in certain places I left it as it was.
When we look at the numbers for the winter you can see it has more change of snowing than anything else.

The UI that gets created is this the image below.


One thing I also wanted to try was make the sun change due to the weather, so for when it is raining it looks more overcast and then with the summer it was sunny, this was you could see the different season a lot more. However, when I implemented it into the code I had the issue of the light was snapping rather than wanting to use the lerp that was set up. It was also going all over the place. During one of the snowing states it got really bright that the texture was just white.
I decided to not try adding this at such a last moment because of the errors.

========================================================================

CONCLUSION

I was originally hoping to have a scene on which more different types of materials and objects change due to the weather however, because of the shader taking longer than anticipated it was obvious that if I did try that I may have not had my code working.

The shader was one of the things which took a bit of the work because of the way ShaderFX works, the lighting wasn't great till I had but lighting into the environment to keep the errors from showing up.

I learnt some valuable lessons during this module, as I want to specialize as a texture artist this was a cool project to take on. I feel like that keeping some Python knowledge will be helpful in my career.
This project was good experience and I learnt a lot, even some new Python knowledge to use.
The Expression Editor took me a little while to figure out how to get working correctly but when I did I started to question why I got so stuck in the first place.

In the end of this project, though I wish I had done more I felt I learnt more from what adds to what I learnt from last semester too. I had to do a little remember of some things I did last semester but it helped.
Additionally I was a little annoying how long it took me to get the ShaderFX working correctly as I was really hoping to have a small scene and more to my UI.
However, with what I got I am reasonably please with it.

Saturday, 23 April 2016

Scripting part 2

After looking back at last week work I wasn't sure I liked the idea of having 2 types of code the end user would have to copy and paste to get the script working.
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.

Tuesday, 12 April 2016

Scripting

Now that I had the weather effect working it was now time to get to the script part of it so that I could have it transition between each weather state and also run semi-procedurally as intended from the start.

To start the scripting off I used Notepad++ to create it on which I then started to create a simple UI to begin with so that I could get the weather states playing from a click of a button.


This script would bring up a small UI with the 4 buttons of Rain, Snow, Dry and a debug button on which the plan was to have that as the linear interpolation test.

To get this script running I had to make sure the script file was in the maya script directory and then in Maya with Python make a script for a button.
import DynamicWeatherSystem as dws
reload(dws)
UI = dws.WeatherSystem() 

When creating this script I did some research first into how to get global variables to work because originally when I put them in the original place it wouldn't run the script and came up with errors.
After spending time fixing these and working out how to get the global variables working better I was able to get the script running.

The script as this point was so that when the button was pressed, it would created the UI with the buttons and then during play mode if you click on of the weather button it would change to that state and if it was currently another weather state it would stop that so never was it possible to have rain and snow at the same time, it was either one or the other.

Next was the linear interpolation, I was not sure how to get this type of effect to work so I requested help from one of the lecturers who gave me a base of a script to get working on.

With this Grant was able to get it so that with each button press the water amount would add a little each time till it was full (at the number 1 on the lerp).

The next part was a little more tricky for myself because I needed to work out how to get it to change at any point in the timeline due to a random number. I had no idea how I was going to do this right away so I tried to program it so that when I pushed a button it would lerp into that weather state.

To get it working with the timeline first I had to figure out how to get the expression editor to work with it, I tried some different ways of getting this to work. Each time and with each edit I kept running into issues, I tried so many ways originally but when I started of it was having a problem connecting to the notepad++ script that I had created.
One of the ways I tried was having this in the expression editor:
python("WeatherSystem(Frame_Counter("+frame+")");
This was suppose to grab the class of weather system and get the frame counter that I had made.


The counter and expression editor was more of a headache than I originally anticipated, following the past tutorials was slightly helpful but I felt lost most of the time like I didn't know what I was doing and I couldn't understand what was doing what which I didn't not much like as I like to know what does what.

After trying many other different ways I went ahead and emailed the lecturer asking why it was not working.

Even though I wasn't sure the lecturer would email me back I kept trying different ways.
With a help of a friend it we came up with a solution of having a function in the maya python editor that would link both the Notepad++ script and expression editor together, we managed to get it working from that.