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.
# 1 28-12-2007 , 10:48 PM
Registered User
Join Date: Dec 2007
Posts: 12

samplerInfo output to a text file?

I realize the samplerInfo node is generally used to drive an objects property such as incandescence or transparency, but is there a way I can get it to record in a text file the pointWorld property as it runs? Like in hypershade, is there a node that will just spit out whatever goes through it to a text file?

I am looking for a file like this

X1 Y1 Z1
X2 Y2 Z2
X3 Y3 Z3
etc.

of all the points that the pointWorld property would pass along to the rest of the shader network.

Please let me know.

Thanks,

David

# 2 29-12-2007 , 03:40 AM
t1ck135's Avatar
Registered User
Join Date: May 2004
Location: UK
Posts: 1,991
Hi David,

I'm not too versed on the samplerInfo node but what you want spurred me on to have a look user added image
I dont know of a node that spits things out to a text file (I've not been learning Mel and Python too long) but the following below might help.

This is not the finalised requirement but will get you the pointWorld values from a generic samplerInfo node and dump them into a text file as you need.

1) Open up the Script Editor (Window -> General Editors -> Script Editor), copy this line of code in and execute it to set up a sample samplerInfo node. If you already know the name of the existing samplerInfo node you are using then you can skip this step.

Code:
shadingNode -asUtility samplerInfo -n "myNode";
2) Now we need to set up an expression that will run every frame, grab the samplerInfo pointWorld data and save it to a text file.
Open up the expression editor (Window -> Animation -> Expression Editor) and with the default settings copy the following code into the expression box:

Code:
$pWorldValues = `getAttr "myNode.pointWorld"`;
$exampleFileName = ( `internalVar -userTmpDir` + "example2.txt" );
$fileId=`fopen $exampleFileName "a"`;
fprint $fileId ($pWorldValues[0] + " " + $pWorldValues[1] + " " + $pWorldValues[2] + "\n");
fclose $fileId;
You can see that the first line is using the 'myNode' name I set up as the sample samplerInfo node. It can be changed as required.
The second line creates a temporary text file in your temp folder (mine showed as C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/) and yours *may* be in a similar place. Again the name of the file specified here can be changed.
The third line opens the specified file for appending information to.
The fourth line prints the contents to a line in the file and the fifth line closes the file.

3) Now run the movie and as it passes through each frame it will write the samplerInfo pointWorld x,y and z data to a line in the specified text file.

I dont know whether it fulfills all your needs but I hope it shows that getting information from maya into a text file can *sometimes* be quite straightforward with a bit of coding user added image

Simon

p.s, the code is just a mod of what is already in the maya help section so I cant take credit for it, even though I tested it and it works fine user added image


Examples of bTraffic - a traffic animation tool for Maya
bFlocking - a tool for Maya 8.5+ to generate flocking and swarming behaviours
Jan/Feb Challenge 2007 Entry and W.I.P
May/Jun Challenge 2006 Entry and W.I.P
Mar/Apr Challenge 2006 Entry and W.I.P
Jan/Feb Challenge 2006 Entry and W.I.P
Nov/Dec Challenge 2005 Entry and W.I.P
Sep/Oct Challenge 2005 Entry and W.I.P
Jul/Aug Challenge 2005 Entry
www.flash-fx.net

Last edited by t1ck135; 29-12-2007 at 03:47 AM.
# 3 29-12-2007 , 08:28 AM
mirek03's Avatar
Subscriber
Join Date: Feb 2006
Location: Australia
Posts: 2,752
our man Tick user added image

very cool mate user added image


take it easy and life will be easy
# 4 29-12-2007 , 04:30 PM
Registered User
Join Date: Dec 2007
Posts: 12
I appreciate the very thorough reply!

However, still a couple of issues.

1) when i create the samplerInfo node, when I click on it in the expression editor, there are no Attributes (when i click on a cube i created i have the whole list of attributes). However, when i run 'listAttr davidSampler' all of the attributes I expect are returned.

2) As I understand it, the 'pointWorld' property actual takes on thousands of values (one for each pixel in the frame) every frame... hence I'm not sure it makes sense to grab the values once per frame... and since that is the case I have NO idea how to proceed lol.

Any more pointers would be great!

Thanks,

David

# 5 29-12-2007 , 06:16 PM
t1ck135's Avatar
Registered User
Join Date: May 2004
Location: UK
Posts: 1,991
Hi daviddoria

1) You dont need to select any attributes in the expression editor for this, just simply create a new expression with the code. It isnt attached to the samplerInfo node, it merely runs each frame and calls the pointWorld attribute on the node.
It doesnt seem that you can visually list the attributes in the expression editor so to see them all open the hypershade and select the samplerInfo node. Now in the right hand menu in Maya it should show the samplerInfo node and all its attributes listed below. From here you could edit them as needed.

2) If you want to grab all the data at once then simply get rid of the expression and put it in the script editor, highlight it and run it. For some reason I mistakenly thought you were after a frame by frame grab of the values (probably because I've never used the samplerInfo node and dont really know what it can do) user added image
It does appear however to be a value containing just an x,y and z value so I'm not sure how it stores all the values for all the points - maybe that happens when it is attached to another node?

mirek03 - I try user added image

Simon


Examples of bTraffic - a traffic animation tool for Maya
bFlocking - a tool for Maya 8.5+ to generate flocking and swarming behaviours
Jan/Feb Challenge 2007 Entry and W.I.P
May/Jun Challenge 2006 Entry and W.I.P
Mar/Apr Challenge 2006 Entry and W.I.P
Jan/Feb Challenge 2006 Entry and W.I.P
Nov/Dec Challenge 2005 Entry and W.I.P
Sep/Oct Challenge 2005 Entry and W.I.P
Jul/Aug Challenge 2005 Entry
www.flash-fx.net

Last edited by t1ck135; 29-12-2007 at 06:19 PM.
# 6 29-12-2007 , 06:21 PM
Registered User
Join Date: Dec 2007
Posts: 12
1) got it

2) the thing is, although there are 3 fields (x, y, and z), each of those should contain thousands of values (like an array? - one for each pixel). With the code you recommended, it just gives me [0,0,0]. When I connect samplerInfo.pointWorld to a shaders color property, I get the desired distance to color mapping for each pixel, as it should. But it seems at any one time, there is only 1 value for x,y,z stored in samplerInfo.pointWorld. I need ALL of them.

Does that make any sense?

Thanks,
Dave

# 7 29-12-2007 , 06:57 PM
t1ck135's Avatar
Registered User
Join Date: May 2004
Location: UK
Posts: 1,991
Ah, I get you. So I'm guessing that it will be doing some conversion style calculation between the pointWorld attribute and the shader colour property. Again because I have no real knowledge of using it I would only guess that you have to grab the output of this process and put that in the text file instead.
Is the pointWorld attribute an input connected to the shader property? If so then there might be a way to connect the output of that somewhere - but that brings you back to the same problem of where. All I can think of is to somehow code it so the output is stored in a matrix (array) and then the matrix is dumped to the text file.
Hmm, this is a bit more advanced than I thought but interesting nonetheless. I dont think I've got the time to delve into it deeply but if I get the chance I'll let you know.

Simon

p.s, if you have a real basic version of your connection set up then post the file here and I'll try and take a quick look to see if it is more straightforward


Examples of bTraffic - a traffic animation tool for Maya
bFlocking - a tool for Maya 8.5+ to generate flocking and swarming behaviours
Jan/Feb Challenge 2007 Entry and W.I.P
May/Jun Challenge 2006 Entry and W.I.P
Mar/Apr Challenge 2006 Entry and W.I.P
Jan/Feb Challenge 2006 Entry and W.I.P
Nov/Dec Challenge 2005 Entry and W.I.P
Sep/Oct Challenge 2005 Entry and W.I.P
Jul/Aug Challenge 2005 Entry
www.flash-fx.net
# 8 29-12-2007 , 09:19 PM
Registered User
Join Date: Dec 2007
Posts: 12
Attached is a basic file. The color of the cube is clearly driven by the location in space, but i need the numbers!!! (ie. i would like to tap between the samplerInfo node and the setRange node and pipe the data to a text file.

Hope you have more luck than I have!

Attached Files
File Type: mb testcube.mb (61.2 KB, 221 views)
# 9 30-12-2007 , 01:39 AM
t1ck135's Avatar
Registered User
Join Date: May 2004
Location: UK
Posts: 1,991
cheers for the file Dave, it helps understand things better.
After having a quick look (its getting late) I think I understand a little more about what is going on. I might be wrong but the pointWorld value determines the xyz position in space that is being sampled. This means that when the image is rendered what is happening is that the samplerInfo node is grabbing all the pointWorld xyz values (effectively going from 0,0,0 to 0,0,1 to 0,0,2 all the way to for example 20,20,20 as points in space) and pumping them into the setRange node which is restricting the R, G or B value that is passed to the blinn shader (in this case to a value between 0.2 and 0.8). The values passed to the blinn material are mixed and the point color is produced. Phew......

So a test (if my theory is right):
Go to the samplerInfo node where you will see the pointWorld x,y and z attributes as 0,0,0.
In the script editor run the following command
Code:
$rTest = `getAttr "blinn1.colorR"`;
$rTest2 = `getAttr "blinn1.colorG"`;
$rTest3 = `getAttr "blinn1.colorB"`;
print ($rTest + " " + $rTest2 + " " + $rTest3);
It will come back with 0.5 0.5 0.5 (middle of the road)

Now alter the first pointWorld attribute value to 1 and run the code again. This time it comes back with 0.62 0.5 0.5, a higher red value. changing it to 2.5 or over results in the setRange node restricting it back to 0.8 as in its settings. Altering the second pointValue changes the Green value and the third pointWorld the Blue value. A combination of these values therefore determines what color each point (and therefore rendered pixel) on the box should be based on its position in the xyz planes.

I've not yet figured out how to get the physically intersected points where the points of the box are in 3D space but if the samplerInfo node allows you to get that then it should just be a case of iterating through all those points and dumping the position out along with the rgb values.

All this might not be useful to you yet but its real interesting to me user added image
If I get the chance tomorrow I'l look into it further

Simon


Examples of bTraffic - a traffic animation tool for Maya
bFlocking - a tool for Maya 8.5+ to generate flocking and swarming behaviours
Jan/Feb Challenge 2007 Entry and W.I.P
May/Jun Challenge 2006 Entry and W.I.P
Mar/Apr Challenge 2006 Entry and W.I.P
Jan/Feb Challenge 2006 Entry and W.I.P
Nov/Dec Challenge 2005 Entry and W.I.P
Sep/Oct Challenge 2005 Entry and W.I.P
Jul/Aug Challenge 2005 Entry
www.flash-fx.net

Last edited by t1ck135; 30-12-2007 at 01:43 AM.
# 10 30-12-2007 , 04:28 AM
Registered User
Join Date: Dec 2007
Posts: 12
ahhh you might be really on to something here!

I forgot that I can SET the worldPoint property!! That is definitely how I'm gona have to iterate through the points, but the problem, as you say is how to figure out which points it would have used in during the rendering, but I think samplerInfo may have more useful properties for determining that.

I'll play with it in the morning and let you know.

Thanks for the help - i'll let you know what i find.

David

# 11 30-12-2007 , 06:25 PM
Registered User
Join Date: Dec 2007
Posts: 12
hmmm I dont think that works... although I could just be doing it wrong.

I think I am very close to having a plugin that I wrote to just dump everything that goes through it into a file working - so we might not have to do this anyway, but I'd be nice to understand the samplerInfo node a little better.

Let me know if you have better luck than I did and I'll post the .mll file when its working properly - they'll be a few more questions I'm sure even once that is working, like what happens if I have more than one object in the scene, does the sampler info node care about that? Also, when the scene is rendered, maya knows what to do even if you dont have a samplerInfo node at all - is the samplerInfo node just a tap into what maya already knows, or is it not the same data Maya uses to render?

# 12 30-12-2007 , 07:27 PM
Registered User
Join Date: Dec 2007
Posts: 12
Getting close!

The attached file is really an .mll, but i had to chagne it to upload it user added image

It makes a file called c:\data.txt with exactly what I need - the problem is if I hook up all 3 inputs, maya crashes, saying

fatal error. attempting to save in c:/blah/blah/..../Dave.20080109.1500.ma

any thoughts about that? maybe i can turn off auto save or something? not sure why it wouldn't be able to save though, and WHAT is it trying to save?

Attached Files
File Type: mel exporttofile.mel (45.5 KB, 210 views)
# 13 30-12-2007 , 11:14 PM
t1ck135's Avatar
Registered User
Join Date: May 2004
Location: UK
Posts: 1,991
Hi David,

Is the mll file one you wrote or found online? I'm not going to have a chance to look for a bit but I'm guessing connecting all 3 outputs to it might overload it with data. I would try just connecting one thing at a time, for example the pointWorld attribute just to see if it works and then maybe move onto a single channel. These are just ideas mind user added image

Simon


Examples of bTraffic - a traffic animation tool for Maya
bFlocking - a tool for Maya 8.5+ to generate flocking and swarming behaviours
Jan/Feb Challenge 2007 Entry and W.I.P
May/Jun Challenge 2006 Entry and W.I.P
Mar/Apr Challenge 2006 Entry and W.I.P
Jan/Feb Challenge 2006 Entry and W.I.P
Nov/Dec Challenge 2005 Entry and W.I.P
Sep/Oct Challenge 2005 Entry and W.I.P
Jul/Aug Challenge 2005 Entry
www.flash-fx.net
# 14 31-12-2007 , 12:21 AM
Registered User
Join Date: Dec 2007
Posts: 12
it is the one I wrote. It does seem like it's "overloading" it, as you say I suppose I can just output one channel at a time - I'll try that tomorrow and see if it is infact the correct points.
Thanks,

David

# 15 31-12-2007 , 12:42 AM
mirek03's Avatar
Subscriber
Join Date: Feb 2006
Location: Australia
Posts: 2,752
its getting gimble lock user added image

this is an interesting thread

the things one could do with a script like this is unreal

anything from advanced science simulations to advanced games.. (Im guessing anyway)

Muser added image


take it easy and life will be easy
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