ViewportTexture
继承: Texture2D < Texture < Resource < RefCounted < Object
以动态纹理的形式提供 Viewport 的内容。
描述
A ViewportTexture provides the content of a Viewport as a dynamic Texture2D. This can be used to combine the rendering of Control, Node2D and Node3D nodes. For example, you can use this texture to display a 3D scene inside a TextureRect, or a 2D overlay in a Sprite3D.
To get a ViewportTexture in code, use the Viewport.get_texture() method on the target viewport.
Note: A ViewportTexture is always local to its scene (see Resource.resource_local_to_scene). If the scene root is not ready, it may return incorrect data (see Node.ready).
Note: Instantiating scenes containing a high-resolution ViewportTexture may cause noticeable stutter.
Note: When using a Viewport with Viewport.use_hdr_2d set to true, the returned texture will be an HDR image that uses linear encoding. This may look darker than normal when displayed directly on screen. To convert to nonlinear sRGB encoding, you can do the following:
img.convert(Image.FORMAT_RGBA8)
img.linear_to_srgb()
Note: Some nodes such as Decal, Light3D, and PointLight2D do not support using ViewportTexture directly. To use texture data from a ViewportTexture in these nodes, you need to create an ImageTexture by calling Texture2D.get_image() on the ViewportTexture and passing the result to ImageTexture.create_from_image(). This conversion is a slow operation, so it should not be performed every frame.
教程
属性
|
属性说明
NodePath viewport_path = NodePath("") 🔗
要显示的 Viewport 节点的路径。相对于本地场景的根节点(见 Resource.get_local_scene()),并非相对于使用该纹理的节点。
注意:在编辑器中,目标视口或其祖级节点发生重命名或移动时会自动更新这个路径。在运行时,该路径可能无法自动更新,因为无法确定场景的根节点。