Learning MEL – Step #8 – Arrays (Part 2)

We already have covered arrays basic points. In this part I go over working with arrays.

When a new thing is introduced, in any place and field, from math to technology, in religion or politics, in CGI or in traditional painting, it comes with associated issues/advantages/components/tools etc. Therefore array also has it own functions and methods. Do not forgot that array is a hero in Computer Programming.

Related Functions:

Functions to be solely used with arrays are:

sort(), size() and clear();

Above three functions are general functions related to arrays. There are many functions used with array that are both complex and far from our point of study, thus I leave them uncovered. Let’s begin explaining our triple functions.

sort(): Use this function simply by placing the array inside the () of the function.

sort($array);

This function would sort the element in an array in “ascending order” and returns a sorted array. However, be aware that the array does not get sorted internally, only returned values from sort() function would sort the output. I return to this point later. Just for now, focus on this example:

string $examples[] = {“hello”, “laugh”, “that man”, “somewhere”, “awful”};
print $examples;

Regularly it outputs based on the order of declaration:

print $examples;
hello
laugh
that man
somewhere
awful

But if you use sort() function, the result is this:

sort($examples);

// Result: awful hello laugh somewhere that man //

However you if you like to keep the result of examples, you have two choices:

1 – Put the result in a new array, like this:

$examples = sort($examples);

Look at the above example. There is not need to use array curly brackets after $example, because MEL already knows it is an array, and you are not going to reintroduce it to MEL, but just what you indeed do is assigning a new set of data.

2- Declare a new array. look at below:

string $sorted_array[] = sort($example);

Look, do not mess up the above $example array with method number 1. The above $example variable is the array unsorted array.

Both of above methods work. Sometime you need only  and only direct printing without keeping the result necessarily in an array. In that specific case, use sort() directly.

size(): Use this function simply by placing the array inside the () of the function.

size($array);

size() is a very very very important function which returns the number of elements in an array. why is it important? Because it dynamically allows you to know about the size of an array whenever you want to. For instance, if you want to print the list of selected nodes, how you would do that? of course you don’t know, since I have not yet covered it, but I will cover it perfectly in next tutorial. title Loops.

Look, this function would return an int number.

clear(): Use this function simply by placing the array inside the () of the function.

This function as its name is explanatory, would clear the array. It does not, however, undeclare it, it just remove every elements in the array , and let you have an empty array without any element.

Therefore, if I do clear our $example array, it will output:

clear ($example);

print ($example);

// Result: //

I wish you learn whatever we do cover here, as these are free tutorials.

Autodesk Mudbox 2014 8K Texture Support

آپلود عکس

Work done by Mostafa Talebi

 

 

Autodesk Mudbox 2014 Now Support 8k Textures

When I work with Mudbox, I mourn why it does not support 8k ( (8 * 1024)2) texture map. For large models, or for close-up shot elements, less than 8k would be a blow. Now I received an email telling that Mudbox 2014 now all generously support 8k size, which further means a great set of improvement. However it ends the report by warning me that only capable Graphic Card are able to handle the computation required for real time 8k texture painting. I have thought about it, and have reached to a certain conclusion regarding such update in an all lovely application as Mudbox.

8k Support – Now Procedural, Now Native

Autodesk Mudbox now supports 8k texture painting. Up to version 2013, it only supported up to 4k textures, which sucks when dealing with production-quality creation. A solution was common among Mudbox modelers,  that they saved a 8k texture in PS, and then imported it as a texture in Mudbox, and eventually got it painted as a MB created texture. This further meant that MB supported 8k, and by its core, it had not put a [commercial] restriction against 8k texture, but yet  it just had not had translated forth onto interface. However I do not fully agree with this statement: Now that MB has announced the coverage of 8k texture, it has grown into all MB parts. When you create a texture, when you export, when you deal with displacement map, when working to export normal maps and further, 8k is counted as a legitimate option. This is of high importance.

Mudbox Understood its Real Deficiency

As a modeling package, MB is a super friendly application for users native of Maya, Max and XSI. Since it has a direct connection for those application, as well as an interface all familiar, unlike nasty [great] ZBrush interface which craves your strength. As a user, I voted for an Update Request at somewhere around Autodesk Site. Now the votes persuaded the officials at Autodesk to inject 8k support into Mudbox.

Brave Texturing

8k Texturing makes you brave. When you become brave that you be able to paint qualified textures. 8k shows every parts in  your texture as it is able to tease you in case of weak-painting.

At the end I thank everyone who in some way incorporated in this update which has made me (and many others) happy. It had been long time ago when I got happy for some updates (I think it was Maya 2008). It really boost the process of texturing since it allows a wider size and more complex details.

Here is a movie related to Autodesk Creation Suit

Learning MEL – Step #7 – Arrays (Part 1)

In this part we are going to cover arrays in MEL. Here I do explain what is array. I also would tell you three functions used exclusively with arrays.

Arrays are only and only a set of variables combined in one variable. Let’s give an example:

You have in a regular variable declaration:

string $text = “example”;

string $text_2 = “example_25″;

If you want to print them you simple would refer to them directly; such as:

print ($text);

or:

print($text_2);

The above example is not new to you, since we have already covered them. But what if you wish to put both variables in one variable? The solution is simple, array. But then how you can access them? Simply by using index of the element in the array. Now, I go into a comprehensive discussion of arrays in MEL.

How to declare?

The process is the same but with some extra steps to take:

after the name of variable, without any space, “[]” sign must be used.

If you want to assign it some sorts of data, then you must open a “{” and then write your element, separate them only and only with “,” and then close it with “}”. In the following parts it would be more explored. Look at this example:

string $array[] = {“element1″, “element2″, “element3″};

Why must array be used?

Never think that arrays are only an extra option to ease your path. They are as essential as simple variables are, and as inevitable as the use of simple variables are. Even sometimes arrays are the only option to use due to the language process at a certain scope. For instance, there are functions in MEL language that return the data  in an array, therefore to store their result one has to use an array, and nothing else. I will cover this part more in the future lessons, because  now it would be confusing.

When to use arrays?

Arrays are used largely in two ways:

Declaration:

First, when you are going to collect a bunch of data within separate sheets. Then one might ask what’s wrong with simple variables? You can not manage them properly, and also accessing them is nothing but a headache. Furthermore, if you want to use only regular variables, the look of your scripts would be ugly enough to prevent other programmers to apply modifications to your script. Any way, MEL is awkward in arrays. I do web programming with PHP, and it supports the use of more complex variables and thus easier workflow.

Stored Result:

This section makes the use of variables necessary. MEL has a function such as “ls” which only returns array. The below statement returns the list of selection.

ls -sl;

Most of the time, almost 99.99999 percent of situations there is a need to store the selection list. Because you are going to use the retrieved data;  Maya reports an error telling you that can not store data of array type into a regular variable. Even if there only be one object selected, which means an element that could be stored in a simple variable, still Maya does not accept it and errs; we now draw this conclusion that in some situations arrays are obligatory. The above statement could be written as so:

string $selection[] = ls -sl;

Now if I do print the $selection, it returns the full list of selected objects; however if there is only one object, you can refer to it like this:

$selection[0];

Index of arrays begin from 0, and not 1.

Have you ever seen (surely you have) a tool in Maya works with two selected object; you must select an object and shift+select the second object? These are the examples:

Constrainting the objects: $selection[0] works as the parent (constraintor).

Curve to Surface: $selection[0] works as the profile or whatever curve.

and many other examples.

However you can directly declare an array with several elements:

string $array_variable = {“Hello” , “Goodbye”, “Function”, “Table”, “home”};

Now we have a variable with 5 subvariables. However, this is wrong to say subvariables, items in array are called elements. We have an array with five elements, it means the last index in array is 4 (remember we have already told index of array begins from zero). Well, to talk more about it: this is an array with string data, however you can use mutiple-data array. Look at the following example:

string $array_variable = {“Hello” , “Goodbye”, “Function”, “Table”, “home”, 2, -0.53574818747, true};

Now this is an array with all sorts of data in; string, int, float and Boolean.

Conclusion:

Arrays are variables with capability of storing several variables with various data-type. Accessing them is possible only by using the relative key(index). Never forgot to use “[]” after the variable declaration so that MEL understand what to declare. In the next tutorial we would apply array-specific functions.

Learning MEL – Step #6 – Using Conditionals in MEL

In this tutorial I am going to make some output using conditionals. It is very easy and indeed essential to learn. However, for further advanced uses, it turns to be somehow complex. After all,  make sure that you have understood the previous section if you are an absolute beginner. At the bottom of this tutorial, there are several important notes about conditionals which must be read.

In this project I would tell you if X=1 then do this and if not do other thing. Very easy. But have in mind the syntax based on which the conditional is provided. Now I move to explain our little project.

  • What is/are the function of the script?
  • What is/are the design, order and/or segment of execution?
  • Command and Functions

What is/are the function of the script?

The script sees what the conditional include, and get the variable or place to which conditional is attached, then checks the value of variable etc., if it meets the condition then the given statement(s) is/are execute respectfully, if not it skips over the other following statement(s) or steps over to next part of conditional (optional). It is too vague now, I know. Let’s see it in practice in a few moments.

What is/are the design, order and/or segment of execution?

It includes basically three parts:

The conditioning, the checking, and then executing or skipping. (don’t pay attention to the // Mel Script , it is simple a comment, when there are two // may wont execute that line since it is considered (and is) to be a comment and nothing more. I will go over it later.

// MEL script

if($x==”Childhood”)

{

print (“This is a true word.”);

}

Look at the above script. It says that if $x is equal to the word “Childhood” then please print the phrase “This is a true word.”

But something is missing. Where the script goes to check $x, or let’s ask where is the $x? It must be before the conditional so that conditional checks something already read by execute (Maya). If it be after conditional then it means there is no $x and so you would get an error reporting undeclared variable. Look at the following part, now it is complete:

// MEL script

$x = “Manhood”;

if($x==”Childhood”)

{

print (“This is a true word.”);

}

With the above script what you get is NOTHING. For two big reasons:

1- You have not stated in the script that in case of FALSE condition, what to do.

2- You script ends by the conditional, for instance if you had lines after it, Maya would just like always execute them, after checking the conditional, regardless of its FALSE or TRUE.

But if $x = “Childhood” the phrase would have been outputted. Now it is the time of dissection:

if($x==”Childhood”)

The above line is the conditional statement. I haven not read anywhere but I call it the header of conditional. It is here that the trueness or falseness of the result is achieved. In IF-Statement you MUST only and only use “==” to check equality, and not “=” which is “assignment” in programming language.

{

print (“This is a true word.”);

}

In order for the conditional to work you must use opening curly bracket “{” and write you statements and the close it with closing curly bracket “}”. If you miss to put them you encounter syntactical error.

You could have done millions of jobs if the conditionals is true.

Note that with true I mean “meeting the standard of your conditional”. It means what you have stated is checked and is confirmed. For instance you could have told if $x is not equal to 5 then do something. Then if $x be 2, it means that it is not 5, and your conditional is true however.

Now what to do if the condition is false. You may decide to do something in case of FALSE condition.

It is easy, just next after the opening parenthesis put a “!” (exclamation sign) and then write the rest of your conditional.  For instance if you want to tell MEL if $x is not equal to zero then do something, you just state it as so:

if(!$x==0)

{

print(“The variable X is not equal to zero.”);

}

Now Maya checks if $x is equal or not, and if it is not, then it execute the statement within the body of conditional, and if not goes with the rest of script.Now it is the time of real application. Let’s say if $x is equal to 2 print something, and if equals to 3 print something else. But I don’t go with one-time print execution, I want to do something so line by line our phrases get printed. Look here:

int $x = 2;
if($x == 2)
{
print (“Number 2 is printed.”);
$x = 3;
}
if($x == 3)
{
print (“Number 3 is printed.”);
}

In the above code you see two conditionals coming after each other. One following the other one. You can do this with unlimited number of conditionals. No two If-Conditionals in anyway could be related, and they are fully performing independently. Now, since each conditional is part of a script, it can modify, change or use variables and other accessible elements. In the first conditional we see,as regular  in case of true, it goes into the body of conditional where statements are stored. I have put the print function and then have changed the variable’s value to 3, so the executor moves forward and reaches the next conditional, here it checks for it and due to the fact that I have changed the variable’s value to 3,  it accounts for true and execute the insiders. You see nice it is. Much use in you future acts. Below you see a nice list of important points about conditionals:

  • Conditionals must be composed within two sections: One the parenthesis and another curly brackets.
  • Parenthesis are for condition to be checked while curly brackets are for the statements to be executed if the conditions is met as true.
  • Every statement within the body of conditionals must be followed by a semi-column.
  • If you want to check for true/false of your condition and if not met, run another condition, you must use “else”, as already described.
  • Else does not need (and must not) be compiled with condition-definition (parenthesis containing the condition just like if-statement), since it is simple the opposite of if-statement.
  • There are other types of conditionals which would be covered later, but fundamentally we have ended one important conditionals.
  • A variable declared within a conditional, could not be accessed/used from outside of it. Therefore the following code would report “undeclared variable” error. Because you have not declared the variable from outside of it, and it is a rule in MEL that variable declared within a conditional are only usable during the same conditionals. Thus, it is strongly recommended to declared variable before conditionals to avoid such problems.

Incorrect Code:

int $x = 2;
string $z = “This is regular variable”;
if($x == 2)
{
print (“Number 2 is printed.”);
$x = 3;
string $y = “This is condition-restricted variable”;
}
if($x == 3)
{
print (“Number 3 is printed.”);
}
print $y;

Correct Code:

int $x = 2;
string $z = “This is regular variable”;
if($x == 2)
{
print (“Number 2 is printed.”);
$x = 3;
string $y = “This is condition-restricted variable”;
}
if($x == 3)
{
print (“Number 3 is printed.”);
}
print $z;

Learning MEL – Step #5 – Conditionals, A Theoretical Overview

In this part we want to talk about conditions and their usage in computer programming. But without any actual work in MEL. If you are not familiar you can use our previous tutorials on MEL. Conditionals are a ways completing a super complex action in a computer programming language. It can does simple jobs from printing a text to most complex jobs such as simulation of particles and other dynamic systems. Conditions are exactly driven out of real life. The only big difference between real life and programming in terms of conditional is that many tasks in real life are done habitually, unconsciously while in computer there is no task to be done out of order and design of a super conscious computer, however in a limited scope.

Let me give you an example of a real world action which include step by step of conditionals. You want to eat a piece of bread with a bunch of fried potatoes. Now? Let’s begin the scenario:

You go to refrigerator to pick a slice of bread. You open the door and find that you have already run out of bread. So what to do? there are a plateful of french fried. Then this happens:If I do have bread, I would eat french fried with bread

But If I don’t have bread, I do go to super market to buy.

(now that I go)

if I have money I would but a bottle of soda

(now that I wanna but)

If there is black soda I would buy

but if it does not have I would b the orange one!

but If I don’t have I would not buy

This is the very usage of it in programming, too. But instead of “but” we use “else”.

For instance if you want to check if the user has entered the value or not, and if not, then report him an error, you must use conditionals.

If the sphere’s radius is less than 1 color it red, if it is greater than one, leave the color as it is.

If the character is in a distance longer than 100 units from camera, then move it 50 frames in second, if it is in less than 100 units from the camera move it in 25 frames in second.

This was a very brief overview of what conditionals in computer programming would indeed do. In later tutorials we would go through it practically.

Learning MEL – Step #4 – Variables in Practice[String]

In this part we are going to utilize variable and to see it all in practice. Now it is very important to ask our questions so that we get the points.

  • What is/are the function of the script?
  • What is/are the design, order and/or segment of execution?
  • Command and Functions

What is/are the function of the script?

It prints a text. But the text is a compilation of several pieces of texts. It adds them together, make a sentence, and prints them. Before the execution of print, in the end of the chapter, we also add a sphere creation script, and use some pieces of text to name a part of the script.

What is/are the design, order and/or segment of execution?

At first we declare line by line our required strings, and then bring our function “print” and “polySphere”.

            Command and Functions

We learn how to use “polySphere” function and some parameter related. We also reuse the function “print”.

We learn how to use operators to add text and make a final phrase, sentence or whatsoever.

In this project we want to print a text using a variable(s), but also use some other functions to expand our base knowledge. We already know how to print something in Maya, but here I go through print a string of characters using variables. First name and last name are going to be outputted via Maya print function. Therefore:

Declare a variable for the first name. Since you are going to output text, the data type of the declared variable must be “string”. Then  we set the name of variable also to “firstname” and assign it “Mostafa” (my own first name).

string $firstname = “Mostafa”;

Now we have successfully declared a variable. Whenever we do declare, such steps relatively are done. Now do repeat the same steps but this time set the name of variable to “space” and assign it a simple ” “, so that in our sentence and phrase we could give space between words.

string $space = ” “;

And now for last name:

string $lastname = “Talebi”;

Here let’s make a core phrase also. Set the name for this variable to “corePhrase”:

string $corePhrase = “The MEL Tutorial is written by:”;

You see that now we have put a sentence in a variable. We could even put longer text. Now this is what we have so far:

string $firstname = “Mostafa”;

string $space = ” “;

string $lastname = “Talebi”;

string $corePhrase = “The MEL Tutorial is written by:”;

It is the time of outputting. Use the “print” function as always for printing a text. But here things are a little new. You need “+” sign to put all strings in a sentence. “+” is a little strange for string summing, since “+” is for mathematical calculations and not textual representations. In other languages such as PHP you would use “.” for adding strings to each other. Now let’s do them. Note that to have a clean and errorless script, use parenthesis to add strings to each other. Doing do, let Maya understands to calculate parenthesis a s a whole for the print function. Now let’s write:

print ($corePhrase + $space + $firstname + $space + $lastname);

Note that we have used variable $space two times. We could have used it one million times. Now our whole scripts would be like this:

string $firstname = “Mostafa”;

string $space = ” “;

string $lastname = “Talebi”;

string $corePhrase = “The MEL Tutorial is written by:”;

print ($corePhrase + $space + $firstname + $space + $lastname);

Let’s do other things. Let’s make a sphere and name the sphere according to our $firstname and $lastname and then add a prefix to it by another variable.

Do write:

string $sphere_passifix = “has_created_this”;

bow we have declared a variable as a passifix for the sphere which is created. Now the function to create sphere. Note that we need a parameter in the sphere itself to name it properly. Use Maya MEL Documentation to see whether it has it or not (it has).

polySphere –name ($firstname + “_”  + $lastname + “_” + $sphere_passifix);

Note that we have put a string inline “_” for our name. We can use direct strings in place of variables to avoid a chaotic environment. A crucial point that you already must be familiar is that ” ” empty spaces are not allowed for name in Computers. They are weird.

-name is a parameter for the function polySphere, and is true as long as is used in the place after polySphere and the final “;”. It is called “flag” in Maya. So flag is the same as function’s parameter. Pay attention to the spelling, all lower case and without space between hyphen and the parameter name. Now let’s make the radius a little higher, for instance 2:

polySphere –radius 2 –name ($firstname + “_”  + $lastname + “_” + $sphere_passifix);

The order of flag is not important. For example, you could have written it like this:

polySphere–name ($firstname + “_”  + $lastname + “_” + $sphere_passifix) –radius 2;

Now our whole script would be like this:

string $firstname = “Mostafa”;

string $space = ” “;

string $lastname = “Talebi”;

string $corePhrase = “The MEL Tutorial is written by:”;

string $sphere_passifix = “has_created_this”;

polySphere -name ($firstname + “_”  + $lastname + “_” + $sphere_passifix) -radius 2 ;

print ($corePhrase + $space + $firstname + $space + $lastname);

I have put polySphere just before the print so that the print function output as the last function. Regularly Maya reports on every individual function, and if I place print before the polySphere, its output would be lost by output of polySphere function. You can test it yourself to see what I mean. The interesting point is the dynamism of variables. Now change the variables to whatever you like and you see it shifts accordingly and affects on all related parts.

Hope this tutorial be useful for you friends.