Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Per frame ptex map Xgen

Per frame ptex map Xgen

Anonymous
Not applicable
1,759 Views
7 Replies
Message 1 of 8

Per frame ptex map Xgen

Anonymous
Not applicable

Hello all,

 

We're rendering a mesh with footage (a sequence) in the material and are trying to figure out how we could drive xgen's primitives' color with the mesh's changing surface color.

 

We somehow found the ptexBake command which I've used to successfully bake a new ptex file every frame, but using these new ptex files doesn't seem to be possible for two main reasons:

 

1)  Xgen has its own rudimentary scripting language that doesn't support string manipulation, so I can't, by script, change which ptex file it should look at each frame.  I'm referring to the "color tip" and "color root" settings under "Preview/Output", for clarification.

-->In short: I can't, by script, change the .ptex file being loaded.

 

2)  Renaming the mesh object and running fixPatchNames('collectionName') (from xgen's python API) almost works but not when rendering a sequence, and invariably the link is lost to said mesh and the whole system falls apart.  I can't for the live of me successfully rename the mesh and keep everything in order.

-->In short: I can't rename the mesh, despite fixPatchName().

 

Has anyone figured this out already or notice something I might be overlooking?  And if not may I double this question as a feature request for any potential devs lurking about 🙂

 

Thanks so much!

0 Likes
Accepted solutions (1)
1,760 Views
7 Replies
Replies (7)
Message 2 of 8

cheng_xi_li
Autodesk Support
Autodesk Support

Hi Jim,

 

I think you can try expression like this.

 

$a=map('C:/Users/lizh/Documents/maya/projects/default/xgen/collections/collection67/description65/paintmaps/color/1');#3dpaint,5.0
$b=map('C:/Users/lizh/Documents/maya/projects/default/xgen/collections/collection67/description65/paintmaps/color/2');#3dpaint,5.0
$select=frame;#1,2
#Sets selection range. 
$fit=expand($select,1,2);

#choose() functon chooses a selection choice based on the range.
choose($fit,$a,$b)

You can find more samples here.

 

Yours,

Li

Message 3 of 8

Anonymous
Not applicable

 

Ah.  Thank you so much!

0 Likes
Message 4 of 8

Anonymous
Not applicable
Accepted solution

 

For anyone trying to do this, too, it gets fun...

 

First thing's first: you'll have to bake out a ptex map to a different folder per frame.  I had a Frame Begin mel script to the tune of:

 

 

python("execfile('G:/pathToScript/ptexBake.py')");

 

 

All that did was bake out the maps, automatically making our awesome new folder structure (ptexBake will create the directory if it doesn't already exist) and a map in each one:

 

 

import maya.cmds as cmds

frame = int(cmds.currentTime(query = True)) #I int it in case it wants to return decimals, which I'd rather not have
cmds.ptexBake( inMesh='pSphere1', o='G:/pathToProject/collections/collectionName/descriptionName/colormap1/' + str(frame), bt='file1', tpu=29) #'file1' will depend, of course, on the material

 

For some reason that messes up the baking--I really don't know, but it doesn't work via a Frame Begin script (this is half question).  Maybe some little thing would fix it, but getting those baked out isn't the hard thing.  I just put the bake command in a loop and iterated through the timeline, baking, before sending it to render:

 

import maya.cmds as cmds
import xgenm as xg #I think I just forgot to delete this, you don't need xgenm for ptexBake

for i in range(150): #Number of frames, of course
    cmds.currentTime(i+1)
    cmds.ptexBake( inMesh='pSphere1', o='G:/pathToProject/xgen/collections/c2/d2/colormap1/' + str(i+1), bt='file1', tpu=29) #Don't forget to replace c2 and d2 with your collection and description name

 

Anyway, for the color tip and color root options you need to have it exactly like Li's post, except instead of $select = frame; you need to have $select = 1;, or any number, so that xgen realizes (thinks) you want some kind of slider that switches between maps.  Lord knows everyone wants a slider before a different ptex map per frame (just kidding, xgen, you're doin a great job ^^).

 

Now hit Accept, and write "frame" (without the quotes) instead of the "1" that'll be displayed.  It actually raises a warning, claiming it wants an integer, but it'll work.  All you have to do from here on out is, well, add a line like the first one for every frame you need to render 🙂  Your scene's a few hundred frames?  Mine was, too.  You either need an intern to type it all out, or you can use this:

 

 

 

count = 150 #Number of frames
for i in range(count):
    print "$a" + str(i) + "=map('${DESC}/colormap1/" + str(i) + "');"
    
chooseLine = "choose($fit,"
for i in range(count):
    chooseLine = chooseLine + "$a" + str(i) + "," #Replace last comma with closing parenthesis
    
print chooseLine

That'll print out such that you can just copy the result from the script editor and paste it accordingly (should be obvious).  Don't forget to replace the $fit line so the 2 equals the number of frames (150 in my case) and don't forget to make sure your path after ${DESC} is right.  The way I'm doing it, here, is every folder is just named after the frame it was created on.

 

Okee dokee, good luck!  I think that's everything.

Thanks again, Li.

 

 

Message 5 of 8

Anonymous
Not applicable

looks like you can specify the exact name of the ptx file you want to use for your maps as long as its generated for the underlying geometry. Just add the file's name (or sequence in format %d) to the path. There's no need for it to be named after the geometry , you can name it as you like.

I.e:

 

map( 'PATH/TO/DESCRIPTION/map-%d.tx', cycle($frame, 1, 100))   cycles through maps 1 through 100 based on frame #

 

"the filename for the map and projmap functions can specify an optional format-arg which will be inserted into the filename as indicated in the examples below:

  • map( 'noise.%d.map.tx', 10 )   references a file named 'noise.10.map.tx'
  • map( 'fenceColor-%04d.tx', 12 )    references a file named 'fenceColor-0012.tx'
  • map( 'map-%d.tx', $objectId)   builds the filename based on the object Id
  • map( 'map-%d.tx', cycle($objectId, 10, 20))   cycles through maps 10 through 20 based on object Id
  • map( 'map-%d.tx', pick($objectId, 10, 20))   picks maps 10 through 20 randomly based on object Id"

font:http://wdas.github.io/SeExpr/doxygen/userdoc.html

 

tested and working, no need of pre render scripts.

0 Likes
Message 6 of 8

Anonymous
Not applicable
i answer myself. The above method doesn't work, i asked in another topic for help.
0 Likes
Message 7 of 8

Anonymous
Not applicable

Following the help text inside the expression window i came up with this expression:


$a = map( "C:/path/to/folder/test.${PAL,myCycle}.ptx");
$a



where myCycle is a simple

 

 

$a = $frame;
$a

 

to enumerate my frame range. This seems to work with errors if i play the range, but renders fine.

 

Thanks Michael.

0 Likes
Message 8 of 8

Anonymous
Not applicable

the above example only works for colors, not for driving attributes. For that you could use this other expression:

 

 

if($frame == 1) { $a= map( 'C:/path/to/folder/test_0001.ptx'); }
else if($frame == 2) {$a=map( 'C:/path/to/folder/test_0002.ptx'); }
.
.
.
else if($frame == 40) {$a=map( 'C:/path/to/folder/test_0040.ptx'); }

$a

Quite a PITA if you have a lot of frames, but this works for any attribute.

 

 

Cheers

0 Likes