Digital humans the art of the digital double
Ever wanted to know how digital doubles are created in the movie industry? This course will give you an insight into how it's done.
# 16 29-02-2012 , 09:56 PM
ctbram's Avatar
Moderator
Join Date: Jan 2004
Location: Michigan, USA
Posts: 2,998
Np As Dave suggested I just used the echo commands and the script editor to figure out each of the individual commands then did a little googling to find out how to write the foreach loop.


"If I have seen further it is by standing on the shoulders of giants." Sir Isaac Newton, 1675
# 17 01-03-2012 , 02:30 AM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988
Hope you guys don't mind, but I've beefed up the code a bit.

Code:
global proc prepareMeshForEngine()
{
    string $sel[] = `ls -sl -tr -dag`;    
    
    if (`size($sel)` <= 0)
        error("You must select at least one object.");    
    
    for ($obj in $sel)
    {
        string $relatives[] = `listRelatives -s $obj`;
        int $isMesh = false;    
        
        // go through the transform's relatives, and see if any of them are 
        // of type "mesh"
        for ($relative in $relatives)
        {
            if (`nodeType $relative` == "mesh")
            {
                $isMesh = true;
                
                break;     // we don't care about the others
            }
        }
        
        // if we found a mesh relative, continue processing. Otherwise ignore
        // this object.
        if ($isMesh)
        {
            // use the real freeze transform command, as it avoids warnings
            makeIdentity -apply true $obj;
            
            polyNormalPerVertex -ufn true $obj;    // unlock the normals
            polySoftEdge -angle 90 $obj;           // set the normal angle to 90

            select -cl;
        }
        else
            warning($obj + " is not a mesh.");
    }
}
I've put it into it's own function, so you can run it just by typing "prepareMeshForEngine();", or binding it to a shelf button. It's also easier to pass this along to others if you put it into a file in the scripts directory. I think the comments are pretty clear, so I'll just point out some things I did.

1) I made $sel more strict on what it accepts. We only want transform nodes, so it filters out anything that isn't. Eg utility nodes, etc.
2) I've put in some error checking, warnings, and errors to make the script more user friendly.
3) I've put a check in to look through the transform's relatives, and see if it contains a mesh node. If we don't do this, the script will run on NURBS surfaces, curves, etc; and will error out.
4) I've changed the FreezeTransformations command over to it's real command. FreezeTransformations is an undocumented helper function, and can cause problems in certain cases.

Other than that, everything else is the same. Good job Rick!


Imagination is more important than knowledge.

Last edited by NextDesign; 01-03-2012 at 06:49 AM.
# 18 01-03-2012 , 06:18 AM
ctbram's Avatar
Moderator
Join Date: Jan 2004
Location: Michigan, USA
Posts: 2,998
Not at all ND. I am no mel programmer and knew my version had no error checking. so kudos for taking the time to write a proper version.

Plus I get to pick these little examples apart to learn more about proper mel script writing. I like that you made it a procedure too.

Oh and to use this as a learning tool if you don't mind. I am assuming going through an objects "relatives" would be for an object that is combined? If so, I notice that you break out once you find the first mesh object. What if there are multiple combined mesh objects? I am clearly not understanding the "relatives" concept. I am also kind of fuzzy about Directed Acyclic Graphs (DAG).

You know! This gets me thinking about the possibility of having a Mel scripting thread or forum section. I wonder if there would be interest in that? I volunteer NextDesign as the moderator user added image

-Rick


"If I have seen further it is by standing on the shoulders of giants." Sir Isaac Newton, 1675

Last edited by ctbram; 01-03-2012 at 11:15 AM.
# 19 01-03-2012 , 07:03 AM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988
Hey Rick, glad to help.

I am assuming going through an objects "relatives" would be for an object that is combined?

Nope. The relatives are any nodes that are the children of the given node. In this case, the child of the transform node, is a shape node. We then go through each shape node, and make sure it's a mesh, not a nurbsSurface, or anything like that. (See that I added a "-s" to the listRelatives command above. This states we're only interested in shape relatives, so the list is smaller and therefore faster to execute)

I break out of the loop when I find a mesh node, because all I'm doing is setting a flag, if there is a mesh node. Therefore, due to short-circuit evaluation, once we find one, we don't need to keep looking for another, as we know that if we have a mesh node, the proceeding commands will work.

I am also kind of fuzzy about Directed Acyclic Graphs (DAG).

A DAG is a graph that is exactly what you said. Directed, and acyclic. Directed, meaning that the connections have a single source, and destination. And acyclic, meaning that you cannot create a loop between connections.

From Wikipedia:

... it is formed by a collection of vertices and directed edges, where each edge connects one vertex to another, such that there is no way to start at some vertex v and follow a sequence of edges that eventually loops back to v again.

It's a bit confusing, as there's a difference between parents, children, and connections. My suggestion would be for you to grab an object, display it's input and output connections, chose a node to start at, and try to traverse the tree to get to another. Try using the following:

pickWalk
listConnections
listRelatives
nodeType

You'll need to play with the flags as well. This will also get you comfortable with the documentation system. (Which is a god-send by the way)

You know! This gets me thinking about the possibility of having a Mel scripting thread or forum section. I wonder if there would be interest in that?

We actually have one already. https://simplymaya.com/forum/forumdisplay.php?f=32

I volunteer NextDesign as the moderator user added image

Thanks for the recommendation!


Imagination is more important than knowledge.

Last edited by NextDesign; 01-03-2012 at 07:10 AM.
# 20 01-03-2012 , 07:32 AM
ctbram's Avatar
Moderator
Join Date: Jan 2004
Location: Michigan, USA
Posts: 2,998
Thanks ND. I am still hazy about the relatives thing but you have given me a good jumping off point to dig into it more.

okay so each node in a selection[] is a transform node and is at the top of a hierarchy that points to a shape node which defines the class of the object as mesh, curve, or surface?

You cannot just query an individual node say $sel[0] and determine if it's a mesh, curve, or surface?

I really need spend a month or so to find some structured mel training that goes into the object types and the API. Right now I understand just about enough to get my winky caught in the cogs.


"If I have seen further it is by standing on the shoulders of giants." Sir Isaac Newton, 1675

Last edited by ctbram; 01-03-2012 at 07:40 AM.
# 21 01-03-2012 , 09:26 AM
daverave's Avatar
The thin red line
Join Date: Aug 2009
Location: England
Posts: 4,472
I like the way you have put in notes in the script NextDesign I can understand most of it............dave




Avatar Challenge Winner 2010
# 22 01-03-2012 , 12:10 PM
ctbram's Avatar
Moderator
Join Date: Jan 2004
Location: Michigan, USA
Posts: 2,998
Ah I get it now. Disregard the question above about querying the obj directly. I played with hypergraph a bit and see what is going on. you have to get to the shape node to determine the type. Got it.


"If I have seen further it is by standing on the shoulders of giants." Sir Isaac Newton, 1675
# 23 01-03-2012 , 08:58 PM
Acid44
Guest
Posts: n/a
Love it ND, the comments make it so understandable, as Dave said.

EDIT: Maybe I'm doing something wrong, but it isn't working for me? Copied in to the Script Editor window, then selected all, and dragged to shelf with middle mouse button

How would I go about sending it around to people? Would I just have to tell them to do the middle mouse drag from script editor thing, or is there a way I can put it in to a file so they can just drop it in to a folder?


Last edited by Acid44; 01-03-2012 at 09:14 PM.
# 24 01-03-2012 , 09:43 PM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988

EDIT: Maybe I'm doing something wrong, but it isn't working for me? Copied in to the Script Editor window, then selected all, and dragged to shelf with middle mouse button

How would I go about sending it around to people? Would I just have to tell them to do the middle mouse drag from script editor thing, or is there a way I can put it in to a file so they can just drop it in to a folder?

What you need to do is place it in a file called prepareMeshForEngine.mel, and place it into the scripts directory. This will make Maya load the code when it starts up. However, this is just the definition, and nothing is calling it. What you need to add to your shelf is "prepareMeshForEngine();" (without quotes) as this will call the code.


Imagination is more important than knowledge.
# 25 01-03-2012 , 10:17 PM
Acid44
Guest
Posts: n/a
Figured it was something like that.

The script itself doesn't seem to be working for me now, though. It seems to be only working on a couple of objects, and just leaving the rest, everything in the scene is polygonal, nothing is grouped, and I just cleaned everything in the outliner before trying

Selected objects are what it worked on in first image, second image shows locked/unlocked normals, where yellow is locked, green is unlocked.

EDIT: Err, nevermind, it's working now. Don't know what's different, but it works now ;D

Attached Thumbnails

Last edited by Acid44; 01-03-2012 at 11:42 PM.
# 26 01-03-2012 , 11:51 PM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988
Don't you just love those types of errors? user added image

If it happens again, email me a test file so I can take a look at it.

On a side note, where do you work in Toronto? I'm guessing a games company?


Imagination is more important than knowledge.
# 27 02-03-2012 , 12:23 AM
Acid44
Guest
Posts: n/a
I think it has something to do with me using duplicate special with -1 scale in the X axis, whenever I do that, then select both sides of the car, it messes up, but if I freeze transforms first it works fine

My work is overseas, boss lives in Aus, everyone else is spread out all over the place. I think the lead road car guy lives in New Brunswick, or some other redneck place up here :p

https://www.facebook.com/groups/216134590902/

# 28 02-03-2012 , 12:57 AM
EduSciVis-er
Join Date: Dec 2005
Location: Toronto
Posts: 3,374
Where do you work, ND? It's all Torontonians here...

# 29 02-03-2012 , 05:25 AM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988

Where do you work, ND? It's all Torontonians here...

The last studio I worked for was Arc Productions (formerly Starz Animation). I'm currently looking for work starting in May.

My work is overseas, boss lives in Aus, everyone else is spread out all over the place. I think the lead road car guy lives in New Brunswick, or some other redneck place up here :p

https://www.facebook.com/groups/216134590902/

Cool. I wish I could take a look at the link, but I don't have a Facebook account. I've done my fair share of racing stuff. My first position was working on the intro to Need for Speed: Pro Street. My uncle also does a lot of car and bike camera work for movies. (And races on the side user added image)


Imagination is more important than knowledge.

Last edited by NextDesign; 02-03-2012 at 05:29 AM.
# 30 02-03-2012 , 05:33 AM
Acid44
Guest
Posts: n/a
Don't know what the hell he's done, but it took me ages to get from the forums to the home page :p, also doesn't show much, but we mainly do rFactor mods (As far as people know)

https://mak-corp.net/


Last edited by Acid44; 02-03-2012 at 05:35 AM.
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads