gamedesignteam

MOBILE GAMES, IPHONE APPLICATIONS, COMPUTER GAMES, GAME DEVELOPMENT TRAINING , http://www.gamedesignteam.com

  • game design team

    We have emerged as the leading online community for game development of all levels. Our expertise encases all facets for writing PC , Mobile and Online of 2D and 3D Gaming programming and applications development, for instance by using the latest 3D engines, scripting languages and animation techniques, our experienced and qualified team deals with all kind of requirements, whether it be a beginner's choice or an expert gaming action. Most importantly, we endeavor to offer compelling solution and eminent support to our growing community of prospective players and customers.

3D Max Variables Tutorial

Posted by virtualinfocom On 12:32 AM 0 comments

We're going to step it up a level in this tutorialThis one should take about 10 mins to complete.


Intro



We will be covering four main areas.



1: Variables and data types

2: Loops

3: Comparison Operators

4: If statements



Variables



You can think of variables in MXS (maxscript) as a temporary named storage place for an "object" of some sort. think of them like lockers at the swimming pool. there are a huge number of them available (unlimited) and they all have nothing in them and are unnamed.

Once you put something in a locker (variable) - it might be a number, a piece of text or even a modifier - and give it a name it will always be in there until you replace it with something else.

To set a variable in maxscript you simply type the following:



variableName = variableValue



The variable name can be anything you like and the value can be almost anything as well.


For now we will use a float which is a number with a decimal place ourVariable = 34.5

if you enter that into the listener and execute it, it will return 34.5 now if you type an expression such as:



2 * ourVariable



Maxscript will return 69.0



The main data types in maxscript are the following:



Float - these are numbers will a decimal component to them ie 234.643

Integer - These numbers are whole numbers only ie 5 or 200

Boolean - true or false

String - this is a piece of text. To set a string you need to enclose it in quote marks


ie:



myStringVariable = "Maxscript sure is handy"One last thing. You can convert different data


types from one to another like this:



"35" as integer



the 35 is a string (because it has quote marks around it) but the "as integer" after it,


turns it into an integer. Obviously "as string" and "as float" do as you would expect.



Loops



Loops are where maxscript becomes really powerful and useful. They enable maxscript to do


repetitive tasks rather than you and the mouse.



Imagine you have built a scene with many objects. You have added a turbosmooth modifier to


all the objects with an iteration value of 2. This is now causing you problems because the


scene is too slow to navigate and you wish you had set the iterations to 1 with a


rendertime setting of 2.



Here is the code:



for obj in $ do

(

obj.modifiers[#turbosmooth].iterations = 1

obj.modifiers[#turbosmooth].useRenderIterations = true

obj.modifiers[#turbosmooth].renderIterations = 2

)



We will now look at it line by line.



for obj in $ do - Our for loop is saying in plain English: "For the objects in our current


selection, do the commands inside the following brackets."



( - We open the brackets

obj.modifiers[#turbosmooth].iterations = 1 - we set the iterations to 1



obj.modifiers[#turbosmooth].useRenderIterations = true

obj.modifiers[#turbosmooth].renderIterations = 2 - these lines should be obvious to you by


now.



) - We close the brackets to end the for loop.



Max will keep looping through the code on every object in the selection until it has done


them all.



You can test the code by making a bunch of objects all with turbosmooth on them. THEY MUST


ALL HAVE A TURBOSMOOTH MODIFIER. if one object doesn't have a turbosmooth modifier, when


MXS tries to talk to it, it won't find it and your script will fail with an error. This


obviously isn't very satisfactory.



Comparison operators



We can solve this problem by adding an "If" statement to the code



But first of all we'll look at some comparison operators. if we have two items such as the


numbers 5 and 2, we can compare them in different ways try typing the following into the


listener:



5 == 2

-Is 5 equal to 2? -This returns False



5 != 2

-Is 5 NOT equal to 2? -This returns True



5 < 2

-Is 5 less than 2 -This returns False



5 > 2

-Is 5 greater than 2 -This returns True



There are more as well which you'll find useful in due course.



If Statements



The way if works is like this:



if (expression resulting in true or false) do

(

code goes here

)



Here is a sample which you should be able to read easily by now:



if (obj.modifiers[#turbosmooth] != undefined) do

(

obj.modifiers[#turbosmooth].iterations = 1

obj.modifiers[#turbosmooth].useRenderIterations = true

obj.modifiers[#turbosmooth].renderIterations = 2

)



That will check an object to make sure it has a turbosmooth modifier and then if it does,


run through the code in the following brackets



Conclusion



Now when we put it all together, we get the following script:



for obj in $ do

(

if (obj.modifiers[#turbosmooth] != undefined) do

(

obj.modifiers[#turbosmooth].iterations = 1

obj.modifiers[#turbosmooth].useRenderIterations = true

obj.modifiers[#turbosmooth].renderIterations = 2

)

)



It should happily run through every object in your current selection and if it has a turbosmooth modifier, set it to the values we specified.

Categories:

0 Response for the "3D Max Variables Tutorial"

Post a Comment