| Thinking Particles Expression Helper |
|
|
|
| Written by Panait Mihai | |
| Sunday, 28 February 2010 01:39 | |
|
Thinking Particles Expression Helper.
In this tutorial we'll take a look at the Expression Helper. This is a highly customizable and very powerfull node. In this setup we'll use it to calculate the distance between two objects. This demonstrates how easy it is to use math formulas in your Thinking Particles systems. Click read more and go to the bottom of this page to download the package containing the video and the scene files. You need 3DSMax 2010 to open the scene files. Tutorial Length 18:33 min. Thinking Particles Operators Used in this tutorial: (O) Param Block, (H) Node, (H) Integer, (H) Point3, (H) Expression, (H) Add&Multiply, (C) Distance.
Thinking Particles 11 - Expression Helper from Mihai Panait on Vimeo.
Preview
Dynamic Sets
Transcript: Hello! In this tutorial we will take a look at the expression helper. This is a highly customizable node. In this tutorial we will use it to calculate the distance between two objects. Create two sphere objects in the scene and change the radius to 10. Name the first sphere blue, and the second one green. Go to particles systems, and create a Thinking Particles system in the scene. Select the modify panel and open the TP user interface. We won’t need any particles group in this system. Go to master dynamic and create a new dynamic set. Name it distance condition. In this set we will use a distance condition to calculate the distance between the two spheres. From helpers, drag two node helpers to the set. Select the first one and click the pick node button. Select the blue sphere in the scene. For the second node select the green sphere. From conditions, add a distance test. Link the two positions to the position one and position two inputs. Close the TP UI for now. Go to create, helpers. From the dropdown list choose manipulators. Add a slider to the scene. Rename it distance condition. Go to modify panel. In the label input type the same name. We will use this slider to display the distance. Disable snap. Open the TP UI. From standard operators, add a Param block to the set. Click pick object, and select the slider from the scene. Expand the nodes and select the value parameter. Click add input. Link the distance to this value input. Select the master dynamic and disable edit on the fly. If you want enable show, but it makes no difference in this setup. Drag the time slider to update the slider’s value. If you move the spheres you will see the new distance in the slider. To see if the distance is correct let’s input a position by hand. Set the x value for the green sphere to 30 and the x value for the blue sphere to -30. Set the other values to 0. The distance is calculated from the pivot of the object. In this case the distance should be 60. Drag the time slider to test it. As you can see the distance is being correctly calculated. Open the TP UI. So far so good. Now we are going to calculate the distance in a different way. If you search distance on Wikipedia you will find this page. Here you will find a formula for calculating the distance between two 3D points. We will use this formula to calculate the distance between the two spheres. Create a new dynamic set, and name it distance expressions. From helpers, add again two node helpers and select a sphere for each. We have to extract the x, y, and z values from the position output. To do this we need two point 3 helpers. Add them to the set and link the position output to the vector input of each point 3 helper. Now if we look to the formula, first we have to calculate the difference between the x, y, and z values of the spheres. For this we need three add and multiply helpers. Set them to difference, A minus B. Link them as in the formula. X two minus x one, Y two minus Y one, and respectively Z two minus Z one. The next step is to rise the results to the power of two. If you will look around, you will see that there is no such helper or node to help us do this operation. This means that we will have to create one ourselves. For this we will need an expression helper. From helpers add one to the set. Click in out button. Select add inputs, scalar input. Name this input p. Add another scalar input and name it q. Click again in out button. Select add outputs, scalar output. Name it power. You can see the newly created inputs and outputs on the node. Now we have to enter the mathematical expression to handle this inputs. If we open the TP Help for this node you will see they direct us to the max reference guide. There we have to do a search for expression controller. I did this and I came up to this page named expression techniques. Here you can see the mathematical functions and operators you can use in this node. So we need p to the power of q. if you scroll down you will find in the topic named standard calculations, a function named pow. This is what we need. Select it and click copy. Paste it in the expression textbox. Click enter from your keyboard. This will test the expression. If an error appears it means that something is wrong with the expression. Link the value to p. Select the node and right click somewhere outside. Select copy. This will copy the node. Right click again and select paste. We will need three expression nodes. We have to rise the result to the power of two. Add an integer node and set the value to two. Link it to the q input of each expression. Now we have to add the results. To do this we can use an add and multiply helper. Unfortunately this helper has only two inputs and we have to use two helpers to add three value. This is not a very elegant solution. The best solution in this case is to use another expression helper. Add three scalar inputs and name them a, b, and c. In the expression textbox write a plus b plus c. Add also a scalar output and name it sum. Link the three output values to the a, b, and c inputs. Of course you can rename the helpers so they have a meaningful name. The next step now is to take the square root of the sum. Add another expression helper. Add a scalar input and name it p. If we open the max help we see the function we need to extract the square root. Select and copy it. Paste it in the expression textbox and press enter. Add a scalar output and name it sqrt. Link the sum output to the p input. Rename the helper to square root. Add a param block operator. We have to add another slider to the scene. Add a new slider and name it distance expression. Open the TP UI. Select the param block operator and click the pick object button. Select the new slider from the scene. Select the value parameter, and click add input. Link it to the square root output. Drag the time slider to test the scene. All works as expected. The problem is that this solution is not too elegant. In the next part we will simplify the setup to only one expression helper. Create a new dynamic set and name it distance simplified. Add two node helpers and set them to the two spheres. Add an expression helper to the set. Click the in out button. Select add input, but this time choose vector input. Unfortunately the selection of this option it’s off screen and you can’t see it on this video. Rename the vector input to Position p. Add another vector input and name it position q. Add a scalar output this time and name it distance. This time we will do all the math in the same expression helper. But first let’s see how can we handle a vector input. In the max help look for the vector operators topic. Here you can see that we can decompose a vector into its component parts. Let’s type in the expression. Pos Q, dot, x, minus, Pos P, dot, x. Close this into parenthesis. Rise it to the power of two, using shift six. Enclose it again in parenthesis. Copy this and add it three times. Replace x with y and with z respectively. Enclose all in parenthesis. Type sqrt in front of the expression. Here is the final expression that you should have. Link the position outputs to the pos p and pos q inputs. Add another slider to the scene and name it distance simplified. Open thinking particles user interface. From standard operators, add a param block operator. Click pick object and select the slider from the scene. Select the value Parameter and click add input. Link it to the distance output. Drag the time slider to see if it works. All works as expected. So this demonstrates the power of the expression operator. We used only one helper to do the work of eleven helpers. I recommend you to open max help and search for expression techniques. Until next time, familiarize yourself with this content. We will explore this node in greater detail. I hope this was useful.
To DOWNLOAD Video Tutorial and Project Files CLICK HERE. *if you can't download the file, or the archive is corrupt you may need to use a download manager.
MediaFire
|









