使用 Outline Effect 2D 效果

使用 Outline Effect 2D 效果为 2D 节点的内容应用轮廓。

例如,使用 Outline Effect 2D 效果为来自数据源的文本应用轮廓。

../../_images/outline-effect-2d-large.png

创建轮廓颜色效果

要创建轮廓颜色效果:

  1. 在 Library 中,按 Alt 并右键单击 Effects 并选择 Outline Effect 2D。

    ../../_images/create-outline-effect-2d.png
  2. 在 Node Tree 或 Prefabs 中,创建一个要应用轮廓效果的 2D 节点。

    ../../_images/text-block-2d-in-node-tree.png ../../_images/text-block-2d-in-preview.png
  3. 从 Library > Effects > 2D Effects 中,将 Outline Effect 2D 效果拖到您想要应用轮廓效果的 2D 节点。

    通过这种方式,您可以在该 2D 节点中将 Effect Prefab 属性设置为 Outline Effect 2D 效果。

    Kanzi 将应用于 2D 节点中内容的视觉形状,轮廓为黑色且宽度为四个像素。

    ../../_images/drag-outline-effect-to-node.png ../../_images/outline-effect-prefab-set.png ../../_images/outline-effect-default-preview.png
  4. 在 Library 中,选择 Outline Effect 2D 效果。在 Properties 中,使用这些属性设置轮廓的外观:

    • Outline Blend Mode 设置 Kanzi 用于渲染轮廓的混合模式。

    • Outline Width 设置轮廓的像素厚度。

    • Outline Color 设置轮廓的颜色。

    • Outline Softness 设置相对于轮廓宽度的渐变长度,以柔化轮廓。

    ../../_images/outline-color-properties.png ../../_images/outline-color-in-preview.png

创建纹理轮廓

您可以将一维纹理应用于使用 Outline Effect 2D 效果创建的轮廓。 例如,您可以使用纹理为文本添加多个描边。

要创建纹理轮廓:

  1. 为2D节点创建轮廓效果。请参阅 创建轮廓颜色效果。

    ../../_images/outline-effect-prefab-set.png ../../_images/outline-effect-default-preview.png
  2. 在 Library 中,选择 Outline Effect 2D 效果。在 Properties 中,添加并设置:

    • 将 Outline Width 设置为您想要的轮廓像素厚度。

    • Outline Color 到您想要在轮廓纹理中调制颜色值的颜色。

      要按原样应用轮廓纹理中的颜色,请将 Outline Color 设置为白色。

    • 将您要应用到轮廓的纹理 Outline Texture。

      Kanzi 仅将此纹理的最上面一行像素应用于轮廓。纹理中最左边的像素映射到轮廓的最内侧部分,最右边的像素映射到轮廓的最外侧部分。Kanzi 将纹理的宽度缩放到轮廓的宽度。

      例如:在 Outline Texture 下拉菜单中选择 + Import Image 并导入此图像:

      ../../_images/outline-texture-grays.png
    ../../_images/outline-textured-properties.png ../../_images/outline-textured-in-preview.png
  3. (可选) 要沿轮廓定位和缩放纹理,请在 Properties 中添加并设置这些 Outline Effect 2D 属性:

    • Outline Texture Offset 设置 Kanzi 开始采样纹理的相对起始位置。

      例如,要使用示例纹理中的中灰色阴影开始轮廓,请将 Outline Texture Offset 设置为 0.33。

    • Outline Texture Tiling 设置 Kanzi 缩放轮廓纹理的值。

      例如,要创建一个显示两次纹理的轮廓,请将 Outline Texture Tiling 设置为 2。

    ../../_images/outline-repeated-texture-properties.png

    小技巧

    当您希望纹理重复以覆盖轮廓时,在 Library > Materials and Textures > Textures 中,选择该纹理,并在 Properties 中,将 Wrap Mode 设置为 Repeat。

    ../../_images/gray-levels-outline-texture-in-library.png ../../_images/wrap-mode-repeat1.png
    ../../_images/outline-texture-tiled-in-preview.png

自定义轮廓效果的实例

当您在 Library > Effects 中编辑效果的属性时,您会更改使用该效果的所有节点的外观。您可以通过覆盖效果属性值来自定义每个效果实例。例如:

  • 当您创建 Shadow Effect 2D 效果时,您可以在该效果的不同实例中改变阴影的柔和度。

  • 当您创建 Mask Effect 2D 效果时,您可以在该效果的不同实例中改变遮罩的大小。

  • 当您创建 Blur Effect 2D 效果时,您可以在该效果的不同实例中改变模糊的程度。

  • 当您创建 Outline Effect 2D 效果时,可以在该效果的不同实例中改变轮廓的颜色。

要自定义效果的实例:

  1. 创建一个效果并设置一个节点来使用它。

    例如,创建一个 Shadow Effect 2D 效果,并设置一个 Image 节点来使用它。请参阅 为二维节点创建阴影效果。

    ../../_images/effect-prefab-property-set.png ../../_images/image-in-preview-w-shadow.png
  2. 在效果中自定义属性:

    1. 在 Library 中,选择您创建的效果。在 Properties 中,在您要自定义的属性旁边,单击 image-publish-property。

      Kanzi Studio 从该属性创建一个自定义属性,将其添加到效果预设的根,并在2D效果中创建一个到该属性的 ##Template 绑定。

      例如,单击 image-publish-property,旁边是 Shadow Blur Radius 属性。Kanzi Studio 创建一个自定义 Shadow Blur Radius 属性,将其添加到根效果预设,并在 Shadow Effect 2D 效果预设中创建一个 ##Template 绑定到自定义 Shadow Blur Radius 属性。

      ../../_images/properties-publish-shadow-blur-radius.png ../../_images/properties-shadow-blur-radius-template-binding.png
    2. 在 Node Tree 或 Prefabs 中,选择使用您创建的效果的 2D 节点。在 Properties 中,点击您自定义的属性旁边的 image-add-property,并设置该属性的值。

      Kanzi Studio 向 2D 节点添加了一个 To Source 绑定,该绑定将该属性的值推送到通过节点的 Node2D.Effect 属性提供的效果实例。

      您可以设置多个 2D 节点以使用相同的效果,并且在每个 2D 节点中,您可以添加和设置属性以具有不同的值。

      例如:在 Properties 中,添加 Shadow Effect 2D Properties > ShadowEffect2D.BlurRadius 属性,并使用它仅在 Image 节点中调整阴影的柔和度。

      ../../_images/properties-shadow-effect-2d-blur-radius.png ../../_images/preview-shadow-effect-2d-blur-radius.png
  3. (可选) 对您要自定义的每个效果属性重复上一步。

    小技巧

    当您想从节点中移除属性及其 To Source 绑定时,右键单击该属性并选择 Remove Property And Binding。

使用 API 中的 Outline Effect 2D 效果

要创建轮廓效果:

// Create an outline effect template.
NodeEffectTemplate2DSharedPtr outlineEffectTemplate =
    NodeEffectTemplate2D::create(OutlineEffect2D::getStaticMetaclass()->getName(), "OutlineEffect");

// Set the value of the WidthProperty in the outline effect template.
// The WidthProperty defines the maximum width of the outline outside the content area.
outlineEffectTemplate->addPropertyValue(OutlineEffect2D::WidthProperty, Variant(8));

// Create an outline effect prefab.
NodeEffectPrefab2DSharedPtr outlineEffectPrefab =
    NodeEffectPrefab2D::create(getDomain(), "OutlineEffect prefab", outlineEffectTemplate);

// Assign the outline effect to a 2D node.
node2d->setEffectPrefab(outlineEffectPrefab);

// Get the node-specific effect instance created from the assigned prefab.
OutlineEffect2DSharedPtr outlineEffect = dynamic_pointer_cast<OutlineEffect2D>(node2d->getEffect());

// Set the SoftnessProperty to 0.7 for this node only. This overrides
// the property default value defined by the OutlineEffect2D metaclass.
outlineEffect->setSoftness(0.7f);

有关详细信息,请参阅 OutlineEffect2D 类。

另请参阅

2D 节点的效果

使用 Blur Effect 2D 效果

使用 Mask Effect 2D 效果

使用 Shadow Effect 2D 效果

使用多个效果

调整 2D 节点的外观

使用刷子

渲染 (Rendering)