Skip to main content
Richard Rosenman
Inspiring
March 26, 2022
Question

Transform_world working differently for image vs shape

  • March 26, 2022
  • 2 replies
  • 377 views

Hi gang;

 

I am trying to understand what I'm doing wrong to get transform_world working correctly.

 

To explain, I have a circle image (circle.png) on a layer that I've imported into AE.

I also have a circle shape I created within After Effects on another layer.

 

My code below allows me to checkout either one through a dropdown. You can see I first checkout the selected layer. If a layer has data, I then draw over it (for testing purposes), and then transform it using transform_world. The issue is that it won't work with the circle image layer, but it will work with circle shape layer. I don't understand why?

 

if (!err) {
	if (checkoutLayer.u.ld.data) {

		ERR(suites.WorldSuite1()->new_world(in_data->effect_ref, max(checkoutLayer.u.ld.width * psize,1), max(checkoutLayer.u.ld.height * psize,1),
											flags, &particle_world));

		ERR(PF_ABORT(in_data));
		
		if (PF_Quality_HI == in_data->quality) 
                   {
			ERR(suites.WorldTransformSuite1()->copy_hq(in_data->effect_ref, &checkoutLayer.u.ld, &particle_world, NULL, NULL));
		   } else {
			ERR(suites.WorldTransformSuite1()->copy(in_data->effect_ref, &checkoutLayer.u.ld, &particle_world, NULL, NULL));
		   }

		ERR(PF_ABORT(in_data));
		

// Let's draw some pixels in the effect world												drawPixel32B(px2, py2, color, &particle_world);

										PF_CompositeMode mode;
mode.opacity = alpha * 255 + 0.5;
mode.opacitySu = alpha * 32768 + 0.5;
mode.rgb_only = false;
mode.xfer = PF_Xfer_IN_FRONT;
PF_FloatMatrix mat1;
double ratio = (double)in_data->downsample_x.num / (double)in_data->downsample_x.den;
double scale = 1.0 * ratio;
mat1.mat[0][0] = scale;
mat1.mat[0][1] = 0.0;
mat1.mat[0][2] = 0.0;
mat1.mat[1][0] = 0.0;
mat1.mat[1][1] = scale;
mat1.mat[1][2] = 0.0;
mat1.mat[2][0] = px2 - checkoutLayer.u.ld.width * psize / 2;
mat1.mat[2][1] = py2 - checkoutLayer.u.ld.height * psize / 2;										mat1.mat[2][2] = scale;

PF_FloatMatrix my_matrices[1];
my_matrices[0] = mat1;
PF_Rect dest;
dest.bottom = in_data->height;
dest.left = 0;
dest.right = in_data->width;
dest.top = 0;
int quality = PF_Quality_HI;

err = suites.WorldTransformSuite1()->transform_world(in_data->effect_ref, quality, PF_MF_Alpha_STRAIGHT, PF_Field_FRAME, &particle_world, &mode, NULL, my_matrices, 1L, true, &dest, output);
									ERR(suites.WorldSuite1()->dispose_world(in_data->effect_ref, &particle_world));

} // checkout data
} // err

 

 

Sorry for the formatting - I had a lot of trouble posting it here in a readable way.

 

Could someone help explain what I'm doing wrong? Why can I draw on me effect world when the shape layer is selected but not when the circle.png image layer is selected?

 

Thanks,

-Richard  

 

This topic has been closed for replies.

2 replies

James Whiffin
Legend
March 27, 2022

My guess is that the buffer sizes are different between the two layers because one is continuously rasterised (the shape layer) and one is not (the image).

 

To confirm this, create a 500x500 composition and fill it with a solid layer. In a new composition, apply your plugin to two instances of this test composition. On one of these layers enable continuous rasterisation and see if both behave the same. If they don't, then the issue is your setup is expecting behaviour that changes if cont raster is on or off. 

Joost van der Hoeven
Community Expert
Community Expert
March 26, 2022

I'm no sripte but I do expressions, but I know generated items like shapes and texts refere to themselfs first then to the comp position, size, etc. We often nest a text first before using scaling expressions to get consistent results. @Roland Kahlenberg can you assist?

Roland Kahlenberg
Legend
March 26, 2022

Hi Joost, this uses scripting and looks Greek to me.  🙂
Someone like Mathias Mohl will be able to solve this easily. 

Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV