MEL Freezing Transforms has unexpected results

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  07 July 2013
MEL Freezing Transforms has unexpected results

I am very new to MEL and have been trying to create a script that creates a curved backdrop by creating a profile curve that is duplicated 3 times and lofted. The issue I have run into is simple to work around, but I am just curious why I am getting this problem anyways. The code looks like this:

curve -p 0 0 0 -p 10 0 0 -p 14 0 0 -p 18 4 0 -p 19 12 0;
 duplicate -rr "curve1";
 move -4 0 10;
 rotate 0 -20 0;
 duplicate -rr "curve1";
 select curve3;
 move -4 0 -10;
 rotate 0 20 0;
 select curve1 curve2 curve3;
 loft -ch 1 -u 1 -c 0 -ar 1 -d 3 -ss 1 -rn 0 -po 0 -rsn true "curve3" "curve1" "curve2";
 DeleteHistory;
 rebuildSurface -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kc 0 -su 8 -du 3 -sv 6 -dv 3 -tol 0.01 -fr 0  -dir 2 "loftedSurface1";
 delete curve1 curve2 curve3;
 select loftedSurface1;
 rotate 0 90 0 ;
 scale 1.5 1.5 1.8;
 
 //--------------
 
 FreezeTransformations;
 makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 -pn 1;
 
 rename "loftedSurface1" "backDrop";


Now if I run the first part (up to the scale 1.5 1.5 1.8), and then run the freeze transforms bit immediately afterwards, everything works as expected, the new surface is rotated by 90 and scaled by 1.5 1.5 and 1.8. However, if I try running it all at once, the rotate 90 and scale commands don't get applied at all. I tried testing it with something even simpler:

sphere;
move 0 5 15;
rotate 0 20 45;
scale 5 4 3;

FreezeTransformations;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 -pn 1;


This code works as expected when run all at once.

I realize it wouldn't be difficult to just tweak some of the other values to have the proper scale and rotation from the beginning, but I am just stumped as to why the two bits of code don't work together for the loftedSurface. Hopefully someone can shed some light

Last edited by pollos : 07 July 2013 at 11:16 PM.
 
  07 July 2013
Magic!

Can you write the code without the hardcoded name "loftedSurface1", i.e. use the returned value?

Try python...
 
  07 July 2013
I'm not actually sure what you mean by re write it without the hardcoded name. Could you give me an example?

I have been working a bit with python actually, but a few tutorials I have been looking at suggest having at least a basic understanding of Mel before getting too into python.
 
  07 July 2013
My friend, jump to python with no second thought:

http://forums.cgsociety.org/showthread.php?t=1044538

In no hard coded names, I meant:

string $loft[] = `loft -ch 1 -u 1 -c 0 -ar 1 -d 3 -ss 1 -rn 0 -po 0 -rsn true "curve3" "curve1" "curve2"`;


and then refer to the surface as

print $loft[0]


It would be much easier for me to play with this in python. So if you are into it, you have your first exercise to translate your code to python. This should be an easy one-to-one. Also an opportunity to try the mel2py script:

http://forums.cgsociety.org/showthr...?f=89&t=1113380
 
  07 July 2013
FreezeTransformations... You do not need that line. That is what makeIdentity is doing.

However -pn 1 is not valid argument in makeIdentity.

But to make it work in one block of code you need to do the last line with evalDeferred...

evalDeferred("makeIdentity -apply true -t 1 -r 1 -s 1 -n 0");

David
__________________
http://www.djx.com.au
 
  07 July 2013
Never knew evalDeferred existed.
Why do we need this magic command for the freezing? (is there a control here, or is it just a way to do sleep? Why do we need it for non-gui related operation?)
Is it needed in python as well?
 
  07 July 2013
To be honest I don't know for sure. Maya does somethings internally which are deferred - maybe to make interactivity feel more responsive? Anyway, evalDeferred lets you add the command to the end of the queue to make sure it happens after the other commands finished. I dont know why it was needed in this case though. My guess is that its because of a series of commands, based on selections rather than by passing names. I'm pretty sure that code could be written differently to avoid having to resort to evalDeferred.

David
__________________
http://www.djx.com.au
 
  07 July 2013
Originally Posted by zoharl: Never knew evalDeferred existed.
Why do we need this magic command for the freezing? (is there a control here, or is it just a way to do sleep? Why do we need it for non-gui related operation?)
Is it needed in python as well?

Bit late on this, but:
It's not a MEL specific thing.
A lot in Maya relies on things being evaluated at the most convenient time. Inside maya there's an idle state that constantly pops up in the cycle.
evalDeferred "ques" something to be run when the main thread enters an idle state.

Python doesn't quite work with that even if you grab it from the commands, but you have alternatives:
executeInMainThreadWithResult(); processIdleEvents() and executeDeferred().

There are many cases when threading is necessary even if you're not working towards parallelism (which Python's GIL prevents it from doing much with), mostly any monitoring, the former specifically, and the latter for many batching tricks, are useful when you want Maya to do something only when it's idling, or to force things that would otherwise execute when idle only (and potentially late).
Idle is mostly something to preserve interactivity or to avoid apparent freezes.

It's possible, although rare, to "race" Maya to its idle, as in accessing something (especially when redrawing comes into play) that Maya will only do at the next idle cycle or thereabout, and therefore getting stale data, or worse errors. When that happens quing up into the idle stack, or forcing its premature eval, can get you out of trouble. Occasionally, it can get you IN trouble, or make the app feel seriously crusty and slow.
__________________
Come, Join the Cult http://www.cultofrig.com - Rigging from First Principles
 
  07 July 2013
(I think the verb you are looking for is 'queue'.)

Not late at all, and I would find it relevant as long as a satisfactory reasoning or solution are found.

I get the concept of postponing execution of some operations to idle. Actually, besides redrawing I cannot think of another example. But this whole thing doesn't make sense in this case, especially for commands such as makeIdentity of freeze transform, which has negligible execution time, and their order of execution is paramount to the code logic. Meaning, postponing the redraw won't change the final result or the data, while makeIdentity would mess it up. Could you please demonstrate your logic on our current situation? I encourage you to run the example in the initial post to see how ridiculous the situation is.
 
  07 July 2013
You said you didn't know it existed, and asked if you needed it in Python, I provided some information on why it exists (which is beyond just redrawing, as I said port listening/socket management is a common application, but there's more, especially in the UI domain), and what you are likely to encounter in Python if you ever need to deal with the idle cycle, intentionally or remedially.

That's about it, I don't care much for MEL or defending it and why it might need a deferral to work with freeze transform
__________________
Come, Join the Cult http://www.cultofrig.com - Rigging from First Principles
 
  07 July 2013
Ho, I guess I'm asking too many questions And yes, I also asked specifically about evalDeferred. Thanks
 
  07 July 2013
I wasn't snapping at you by the way, just explaining why I didn't, nor will, bother justifying why MEL for some obscure reason requires you to defer to the idle cycle to freeze a transform, which boils down to "doesn't have an obvious reason, don't know"

The idle cycle itself though is worth knowing about regardless of language, it's very useful to covertly keep track of things without degrading performance on the user's end.
__________________
Come, Join the Cult http://www.cultofrig.com - Rigging from First Principles
 
  07 July 2013
I didn't misread your post as snapping or any other negative tone, and I usually don't, especially when a smiley is involved. But since this topic was refreshed due to the new topic (showEditor something), and the subject was WTF, I found your clarification in place regarding which of my points/questions you were actually referring to (and a reminder that there was actually more than one...).
(My previous post should have been read: I'm asking too many questions, such that I sometimes lose track...)
 
  08 August 2013
This thing was bugging me until today when I was reading here...
http://kmcnamaracom.ipage.com/?p=411

flushIdleQueue caught my eye because I'm not familar with it. And for some reason it doesn't get a mention in the docs, unless you dig into the pymel stuff. But it seems to be the answer.

This works...
curve -p 0 0 0 -p 10 0 0 -p 14 0 0 -p 18 4 0 -p 19 12 0;
duplicate -rr "curve1";
move -4 0 10;
rotate 0 -20 0;
duplicate -rr "curve1";
select curve3;
move -4 0 -10;
rotate 0 20 0;
select curve1 curve2 curve3;
loft -ch 1 -u 1 -c 0 -ar 1 -d 3 -ss 1 -rn 0 -po 0 -rsn true "curve3" "curve1" "curve2";
DeleteHistory;
rebuildSurface -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kc 0 -su 8 -du 3 -sv 6 -dv 3 -tol 0.01 -fr 0  -dir 2 "loftedSurface1";
delete curve1 curve2 curve3;
select loftedSurface1;
rotate 0 90 0 ;
scale 1.5 1.5 1.8;

flushIdleQueue; //<<<<< Ha!

makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;

rename "loftedSurface1" "backDrop";


David
__________________
http://www.djx.com.au
 
  08 August 2013
Weird.. trying to decide if I've noticed this behavior before but another solution is to delete the construction history and associated inputs until after freezing the transformations.

 string $curve=`curve -p 0 0 0 -p 10 0 0 -p 14 0 0 -p 18 4 0 -p 19 12 0`;
  string $curve2[]=`duplicate -rr $curve`;
  move -4 0 10;
  rotate 0 -20 0;
  string $curve3[]=`duplicate -rr $curve`;
  select curve3;
  move -4 0 -10;
  rotate 0 20 0;
  
  string $loft[]=`loft -ch 1 -u 1 -c 0 -ar 1 -d 3 -ss 1 -rn 0 -po 0 -rsn true $curve3[0] $curve $curve2[0]`;
  
  rebuildSurface -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kc 0 -su 8 -du 3 -sv 6 -dv 3 -tol 0.01 -fr 0  -dir 2 $loft[0];
  select $loft[0];
  rotate 0 90 0 ;
  scale 1.5 1.5 1.8;
  
  select $loft[0];
  makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;
  delete -ch $loft;
  delete $curve3[0] $curve $curve2[0];
  rename $loft[0] "backDrop";
__________________
blah blah blah
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:43 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.