colorAtPoint sequence not updating


#1

Hello,

I’ve mapped an animated .iff sequence onto an object, its in the proper name.#.iff format, and I cached it. It plays back fine in the viewport and in playblasts. The problem is that I’m using a colorAtPoint expression in my particle goals, but it only reads the first frame, and doesn’t update when I run the simulation.

Any thoughts?

Thanks!

Update: I know the expression is fine because it works with an animated ramp, so I guess I just need a way to force it to let the image sequence update before doing the colorAtPoint command.


#2

Try the expression I posted in this thread.
http://forums.cgsociety.org/showthread.php?f=86&t=1061982
I found this worked where the standard image sequence expression did not.


#3

Thanks! I was just looking at that, but don’t really know how to use it. Where do I put that in?

Here’s what I have right now for my particle expressions:

Creation:

particleShape1.goalU = rand(1);
particleShape1.goalV = rand(1);
particleShape1.goalPP = 0;
particleShape1.goalWeight0PP = .1;

Runtime Before Dynamics:

$gU = particleShape1.goalU;
$gV = particleShape1.goalV;
$pRamp = `colorAtPoint -o RGB -u $gU -v $gV file2`;

if ($pRamp[0] >= 0.1)
{
particleShape1.goalPP = 1;
}

That works with a ramp (but not a ramp with the animated sequence plugged in). I assume your code goes on the image sequence some how, but I don’t know any Python, and can’t figure out exactly how to use it.


#4

Ha, no worries.
Create a new expression using the expression editor or edit the expression that gets created when you click “Image Sequence” on the file node.
Paste that expression in there and replace where noted:

string $fileNode="fileIn"; //<Change fileIn with the name of you file node 
     string $imagePrefix="images/animMap"; //< Change to the path dir of image sequence
     string $imageSuffix="iff"; //< change file type
     int $offset=0; // <change if you want an offset
    // NO NEED TO TOUCH ANYTHING ELSE
     string $pythonCmd="import maya.cmds as cmds
offset="+$offset+"
frame=int(cmds.currentTime(q=1))+offset
cmds.setAttr('"+$fileNode+".fileTextureName',('"+$imagePrefix+".'+str(frame).zfill(4)+'."+$imageSuffix+"'),type='string')";    
     python $pythonCmd;

Your particle expression should be able to stay the same this expression is just hard coding the change of images instead of just the image number.
Hope that makes sense and helps.


#5

Oh ok thanks, I almost had it, was missing the fileIn part.

Anyway, I just got it working by adding an attribute to my particles called dummy.

Then in runtime before dynamics I appended it to look like:

$gU = particleShape1.goalU;
$gV = particleShape1.goalV;
$pRamp = `colorAtPoint -o RGB -u $gU -v $gV file2`;
particleShape1.dummy = frame;

if ($pRamp[0] >= 0.1)
{
particleShape1.goalPP = 1;
}

After that, I changed the expression in my image sequence to:

file2.frameExtension=particleShape1.dummy;

I haven’t tested if it still works with offset, but I imagine that it would, otherwise I’ll just write that part in on my particles. I’m off to lunch right now, but when I get back I’m going to test with your method too, thanks for the help!

EDIT: NOT ACTUALLY WORKING


#6

Ok, after coming back from lunch, turns out my solution doesn’t actually work.

I tried your solution again, and I’m getting:

Error: line 6: invalid syntax

So I’m still doing something wrong apparently, back to work!


#7

Hmm for some reason the long line is getting some weird space from posting it.
Around here I see a big space I can’t get rid of in the post:
+offset
cmds.se tAttr

it should be ncmds.setAttr

Annoying web-tax


#8

Thanks a lot, works great!

I added a variable for frame padding, and your script works very well.

string $fileNode="fileIn"; //<Change fileIn with the name of you file node 
     string $imagePrefix="images/animMap"; //< Change to the path dir of image sequence
     string $imageSuffix="iff"; //< change file type
     int $offset=0; // <change if you want an offset
     int $padding = 5; // frame padding
    // NO NEED TO TOUCH ANYTHING ELSE
     string $pythonCmd="import maya.cmds as cmds
offset="+$offset+"
frame=int(cmds.currentTime(q=1))+offset
cmds.setAttr('"+$fileNode+".fileTextureName',('"+$imagePrefix+".'+str(frame).zfill("+$padding+")+'."+$imageSuffix+"'),type='string')";    
     python $pythonCmd;

I just got it working before you posted by turning off “use image sequence” and then creating an expression that was simply:

$frame = frame;
setAttr -type "string" file1.fileTextureName ("sourceimages/particle_ramp/turtle_ramp." + $frame + ".iff");

I’m definitely saving/using your script though because if I’m not mistaken it is doing the same thing just much easier and cleaner to change, so thanks a lot for the help.


#9

Really the only thing my expression does is pad 4…which is totally unneeded if your images are numbered in a different way.
I guess I should have mentioned that.
Your solution works well if that gets your correct image numbers.
But the concept is the same…force a reload of the images to force an update.
Woo hooo!


#10

I have taken the time to write this into a handy python script. Just select your file in node and run the script.

It uses the attributes already on the node like the file texture name and offset (because I am lazy) so if you need to change anything, change the attributes and run it again. I have pretty much just used what you guys have. Hope this makes someones life easier

import maya.cmds as mc
from os.path import splitext

pad=4 #change frame padding

fileNode = mc.ls(sl=True, et='file')[0]

exprName = mc.listConnections(fileNode, d=True, t='expression')[0]
mc.delete(exprName)

texturePath = mc.getAttr(('%s.fileTextureName' % fileNode))

ext = (splitext(texturePath)[1])[1:] #we strip the . at the start

texture = splitext(splitext(texturePath)[0])[0] # remove the padding

offset=mc.getAttr(('%s.frameOffset' % fileNode))

mc.setAttr(('%s.useFrameExtension' % fileNode), 0) #set use image sequence to off

expr = """
string $pythonCmd="import maya.cmds as cmds\
offset=%d\
frame=int(cmds.currentTime(q=1))+offset\
cmds.setAttr('%s.fileTextureName',('%s.'+str(frame).zfill(%d)+'.%s'),type='string')"; 
python $pythonCmd;
""" %(offset, fileNode, texture, pad, ext)

mc.expression(o=fileNode, s=expr, n=exprName)

#11

I tried to reply but don’t think it worked.

Anyway second time lucky.

I write a python script that will make doing this easier. It uses the attributes like filename and offset already on the file node so no need to type out everything. Just change the frame padding if not set to 4 already

import maya.cmds as mc
from os.path import splitext

pad=4 #change this if you want

fileNode = mc.ls(sl=True, et='file')[0]

exprName = mc.listConnections(fileNode, d=True, t='expression')[0]
mc.delete(exprName)

texturePath = mc.getAttr(('%s.fileTextureName' % fileNode))

ext = (splitext(texturePath)[1])[1:] #we strip the . at the start

texture = splitext(splitext(texturePath)[0])[0] # remove the padding

offset=mc.getAttr(('%s.frameOffset' % fileNode))

mc.setAttr(('%s.useFrameExtension' % fileNode), 0) #set use image sequence to off

expr = """
string $pythonCmd="import maya.cmds as cmds\
offset=%d\
frame=int(cmds.currentTime(q=1))+offset\
cmds.setAttr('%s.fileTextureName',('%s.'+str(frame).zfill(%d)+'.%s'),type='string')"; 
python $pythonCmd;
""" %(offset, fileNode, texture, pad, ext)

mc.expression(o=fileNode, s=expr, n=exprName)

hope this helps someone


#12

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.