Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

ImageTextureLayered

继承: TextureLayered < Texture < Resource < RefCounted < Object

派生: Cubemap, CubemapArray, Texture2DArray

纹理类型的基类,包含多个 ImageTexture 的数据。各个图像具有相同的大小和格式。

描述

Texture2DArrayCubemapCubemapArray 的基类。不能直接使用,但包含了访问派生资源类型所需的所有函数。另见 Texture3D

方法

Error

create_from_images(images: Array[Image])

void

update_layer(image: Image, layer: int)


方法说明

Error create_from_images(images: Array[Image]) 🔗

根据 Image 数组创建 ImageTextureLayered,所需的数据格式见 Image.create()。宽度、高度、图像格式、Mipmap 等设置由第一个图像决定,其他图像必须保持一致。

每个 Image 都代表一层 layer

# 为数组中的图像填充不同的颜色。
var images = []
const LAYERS = 6
for i in LAYERS:
    var image = Image.create_empty(128, 128, false, Image.FORMAT_RGB8)
    if i % 3 == 0:
        image.fill(Color.RED)
    elif i % 3 == 1:
        image.fill(Color.GREEN)
    else:
        image.fill(Color.BLUE)
    images.push_back(image)

# 创建并保存 2D 纹理数组。图像数组中必须至少有 1 个图像。
var texture_2d_array = Texture2DArray.new()
texture_2d_array.create_from_images(images)
ResourceSaver.save(texture_2d_array, "res://texture_2d_array.res", ResourceSaver.FLAG_COMPRESS)

# 创建并保存立方体贴图。图像数组中图像的数量必须为 6。
# 立方体贴图图像的顺序为:X+、X-、Y+、Y-、Z+、Z-
# (使用 Godot 的坐标系,因此 Y+ 是“上”、Z- 是“前”)。
var cubemap = Cubemap.new()
cubemap.create_from_images(images)
ResourceSaver.save(cubemap, "res://cubemap.res", ResourceSaver.FLAG_COMPRESS)

# 创建并保存立方体贴图数组。图像数组中图像的数量必须为 6 的倍数。
# 每个立方体贴图图像的顺序为:X+、X-、Y+、Y-、Z+、Z-
# (使用 Godot 的坐标系,因此 Y+ 是“上”、Z- 是“前”)。
var cubemap_array = CubemapArray.new()
cubemap_array.create_from_images(images)
ResourceSaver.save(cubemap_array, "res://cubemap_array.res", ResourceSaver.FLAG_COMPRESS)

void update_layer(image: Image, layer: int) 🔗

用这个新图像替换给定 layer 的现有 Image 数据。

给定的 Image 必须与其余引用的图像具有相同的宽度、高度、图像格式和多级渐远纹理标志。

如果图像格式不受支持,它将被解压缩并转换为一个相似且受支持的 Format

更新是即时的:它与绘制同步。