FORUMS: list search recent posts

Sprites and Image Sequence: Adjusting scalePPX according to Image size

COW Forums : Autodesk Maya

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Joe Derone
Sprites and Image Sequence: Adjusting scalePPX according to Image size
on Apr 16, 2010 at 1:06:48 pm

Hello,

I have run into a small issue and maybe someeone here can help me, I am basically looking for an attribute which will give me the height and width of an image (out of an image sequence) that is used by an individual sprite.

I have set up an nDynamics emitter, emitting sprites towards the camera along the Z Axis with a little bit of spread (to have a slideshow of pictures flying past the camera, each sprite displays a different picture).

To assign the image sequence to the sprites, I have made a material with a file->image sequence shader and assigned it to the particle object. The file node in this shader has "Use image sequence" on but I deleted the standard expression as it does not cycle and is not needed for the sprite image assignment to work. I set the Image sequence caching to the 1 to 29 images I have. (The "image.frameExtension=frame" bit).


Then I added the spriteNumPP attribute to the particle object and a random expression :

particle1.spriteNumPP=rand(1,29);

(The image sequence contains 29 images - image.001 to image.029).

This actually works pretty well, assigning a random photo to each sprite but the pictures are different photos with different aspect ratios, so they appear stretched on the standard sprite (scalex and y =1).

What I intend to do is to match the scale of each individual sprite (.scalePPX) to the aspect ratio of the picture via this particle creation expression:

particle1.scalePPX = image.outSizeX / image.outSizeY

where image is the file node used in the shader.

It works, however there is a bigger problem: image.outSizeX and Y always return the same value because the image node always stays at the first frame, it does not represent the image on the current sprite. Even if I was to put an expression for the .frameExtension on the image node to cycle images, it would not correspond to the individual sprite's assigned image.

As I am not fully versed in the MEL object model in Maya, my Question is (and google has yielded nothing so far):

How do I access the individual sprite's image properties such as .outSizeX and Y to resize each sprite to its image aspect ratio?

I appreciate any help.

br,
Joe


Return to posts index

Michiel Duvekot
Re: Sprites and Image Sequence: Adjusting scalePPX according to Image size
on Apr 16, 2010 at 4:15:01 pm

I would precompute the x and y scales, store them in a array of x and y scale pairs and run use a creation expression like this:

$sn = particleShape1.spriteNumPP;

float $res[] = {0.3, 1.0, 0.5, 1.0, 1.0, 1.0};

float $x = $res[int(($sn-1)*2)];
float $y = $res[int((($sn)*2)-1)];


particleShape1.spriteScaleXPP = $x;
particleShape1.spriteScaleYPP = $y;


print ("sn: " + $sn + "\t" + $x + "\t" + $y + "\n");



Return to posts index

Joe Derone
Re: Sprites and Image Sequence: Adjusting scalePPX according to Image size
on Apr 16, 2010 at 8:50:07 pm

Thank you for that answer!

I think I will go this route.

But as I understand you I would calculate the scales outside of Maya just by looking at the picture sizes and then hardcode it into that array, right?

Is there any way to cycle through the images in the 2D texture node and calculate the ratios this way in maya to pre-set them?

Thanks!
Joe


Return to posts index


Michiel Duvekot
Re: Sprites and Image Sequence: Adjusting scalePPX according to Image size
on Apr 16, 2010 at 9:22:55 pm

I would script that too.

Using your method for calculating the aspect ratio; I might use this:

global float $res[];
for ($i = 1; $i < 4; $i++) {
setAttr "file1.frameExtension" $i;
float $aspectX = `getAttr file1.outSizeX` / `getAttr file1.outSizeY`;
float $aspectY = 1.0;
$res[`size $res`] = $aspectX;
$res[`size $res`] = $aspectY;
}


Return to posts index

Joe Derone
Re: Sprites and Image Sequence: Adjusting scalePPX according to Image size
on Apr 16, 2010 at 11:54:17 pm

Thank you very much!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]