AEJoy —— AE 插件开发中的 SmartFX (八)

252 阅读3分钟

「这是我参与11月更文挑战的第 18 天,活动详情查看:2021最后一次更文挑战」。

参加该活动的第 35 篇文章

正文

图层的“大小”

非智能效果一样,每个智能效果可以任意收缩或扩展其请求的输入。它们不能依赖于固定的帧大小,而且输入的大小可能随时间而变化。

例如,用户可以在一个图层上应用动画投影(drop shadow),这将在不同的时间向图层的不同边缘添加像素,这取决于投影的方向。

一些效果(例如,那些需要将一个图层与另一个图层对齐的效果)需要一些 “大小” 概念。这可以用两种方式来定义,各有优缺点。

在应用任何效果和下采样之前,原始图层的大小是in_data>width/height。由于这个值不受后续效果的影响,它可以作为中心点之类的东西的绝对参考

然而,这并不是万无一失的,因为用户可能会应用扭曲或平移效果。此外,这个值仅对应用了效果的层有效,而不是其他层参数。

…… 或者 ……

每一层输入都有一个 max_result_rect,它包含所有像素数据,在某种意义上是一个层的主“大小”。

它适用于所有图层,但会根据之前应用的效果随时间而变化,可能是用户意想不到的方式(如上面的投影示例)。

请注意,输入的 ref_width/heightmax_result_rect 可以通过使用空 request_rect 调用 checkout_layer 来获得,而无需渲染。

这是相当有效的,并且很有用,如果首先需要层的 “大小” 来确定哪些像素需要渲染的话。

这是一个在预渲染中请求一个层,然后从不调用 checkout_layer (在本例中,没有调用)的例子。

The "Size" Of A Layer

As with non-smart effects, each smart effect can arbitrarily shrink or expand its requested input. They cannot depend on a fixed frame size, and the size of the input may change over time.

For example, the user could apply an animated drop shadow to a layer, which would add pixels to different edges of the layer at different times, depending on the direction in which the shadow is cast.

Some effects (for example, those which need to align one layer against another) need some notion of “size.” This could be defined two ways, each with advantages and disadvantages.

The size of the original layer, before any effects and downsampling are applied, is given in_data>width/height. As this value is unaffected by subsequent effects, it can act an absolute reference for things like center points.

However, this is not fool-proof, as the user could have applied a distortion or translation effect. Also, this value is available only for the layer to which the effect is applied, not other layer parameters.

…or…

Every layer input has a max_result_rect which encompasses all pixel data, in some sense the master “size” of a layer.

It is available for all layers, but changes over time according to previously applied effects, possibly in ways the user might not expect (as in the drop shadow example above).

Note that the ref_width/height and max_result_rect for an input may be obtained without rendering, by calling checkout_layer with an empty request_rect.

This is fairly efficient, and can be useful if the layer “size” is needed first to determine exactly which pixels are required for rendering.

This is an example of requesting a layer in pre-render and then never calling checkout_layer (in this case, there are none).