Documentation
¶
Overview ¶
Camera3D is a special node that displays what is visible from its current location. Cameras register themselves in the nearest Viewport node (when ascending the tree). Only one camera can be active per viewport. If no viewport is available ascending the tree, the camera will register in the global viewport. In other words, a camera just provides 3D display capabilities to a Viewport, and, without one, a scene registered in that Viewport (or higher viewports) can't be displayed.
Index ¶
- type Advanced
- type Any
- type DopplerTracking
- type Expanded
- type Extension
- type ID
- type Instance
- func (self Instance) AsCamera3D() Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsNode3D() Node3D.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) Attributes() CameraAttributes.Instance
- func (self Instance) ClearCurrent()
- func (self Instance) Compositor() Compositor.Instance
- func (self Instance) CullMask() int
- func (self Instance) Current() bool
- func (self Instance) DopplerTracking() DopplerTracking
- func (self Instance) Environment() Environment.Instance
- func (self Instance) Far() Float.X
- func (self Instance) Fov() Float.X
- func (self Instance) FrustumOffset() Vector2.XY
- func (self Instance) GetCameraProjection() Projection.XYZW
- func (self Instance) GetCameraRid() RID.Camera
- func (self Instance) GetCameraTransform() Transform3D.BasisOrigin
- func (self Instance) GetCullMaskValue(layer_number int) bool
- func (self Instance) GetFrustum() []Plane.NormalD
- func (self Instance) GetPyramidShapeRid() RID.Shape3D
- func (self Instance) HOffset() Float.X
- func (self Instance) ID() ID
- func (self Instance) IsPositionBehind(world_point Vector3.XYZ) bool
- func (self Instance) IsPositionInFrustum(world_point Vector3.XYZ) bool
- func (self Instance) KeepAspect() KeepAspect
- func (self Instance) MakeCurrent()
- func (self Instance) MoreArgs() MoreArgs
- func (self Instance) Near() Float.X
- func (self Instance) ProjectLocalRayNormal(screen_point Vector2.XY) Vector3.XYZ
- func (self Instance) ProjectPosition(screen_point Vector2.XY, z_depth Float.X) Vector3.XYZ
- func (self Instance) ProjectRayNormal(screen_point Vector2.XY) Vector3.XYZ
- func (self Instance) ProjectRayOrigin(screen_point Vector2.XY) Vector3.XYZ
- func (self Instance) Projection() ProjectionType
- func (self Instance) SetAttributes(value CameraAttributes.Instance)
- func (self Instance) SetCompositor(value Compositor.Instance)
- func (self Instance) SetCullMask(value int)
- func (self Instance) SetCullMaskValue(layer_number int, value bool)
- func (self Instance) SetCurrent(value bool)
- func (self Instance) SetDopplerTracking(value DopplerTracking)
- func (self Instance) SetEnvironment(value Environment.Instance)
- func (self Instance) SetFar(value Float.X)
- func (self Instance) SetFov(value Float.X)
- func (self Instance) SetFrustum(size Float.X, offset Vector2.XY, z_near Float.X, z_far Float.X)
- func (self Instance) SetFrustumOffset(value Vector2.XY)
- func (self Instance) SetHOffset(value Float.X)
- func (self Instance) SetKeepAspect(value KeepAspect)
- func (self Instance) SetNear(value Float.X)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetOrthogonal(size Float.X, z_near Float.X, z_far Float.X)
- func (self Instance) SetPerspective(fov Float.X, z_near Float.X, z_far Float.X)
- func (self Instance) SetProjection(value ProjectionType)
- func (self Instance) SetSize(value Float.X)
- func (self Instance) SetVOffset(value Float.X)
- func (self Instance) Size() Float.X
- func (self Instance) UnprojectPosition(world_point Vector3.XYZ) Vector2.XY
- func (self Instance) VOffset() Float.X
- func (self Instance) Virtual(name string) reflect.Value
- type KeepAspect
- type MoreArgs
- type ProjectionType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type DopplerTracking ¶
type DopplerTracking int //gd:Camera3D.DopplerTracking
const ( // Disables [Doppler effect] simulation (default). // // [Doppler effect]: https://en.wikipedia.org/wiki/Doppler_effect DopplerTrackingDisabled DopplerTracking = 0 // Simulate [Doppler effect] by tracking positions of objects that are changed in _process. Changes in the relative velocity of this camera compared to those objects affect how audio is perceived (changing the audio's [AudioStreamPlayer3D.PitchScale]). // // [AudioStreamPlayer3D.PitchScale]: https://pkg.go.dev/graphics.gd/classdb/AudioStreamPlayer3D#Instance.PitchScale // [Doppler effect]: https://en.wikipedia.org/wiki/Doppler_effect DopplerTrackingIdleStep DopplerTracking = 1 // Simulate [Doppler effect] by tracking positions of objects that are changed in _physics_process. Changes in the relative velocity of this camera compared to those objects affect how audio is perceived (changing the audio's [AudioStreamPlayer3D.PitchScale]). // // [AudioStreamPlayer3D.PitchScale]: https://pkg.go.dev/graphics.gd/classdb/AudioStreamPlayer3D#Instance.PitchScale // [Doppler effect]: https://en.wikipedia.org/wiki/Doppler_effect DopplerTrackingPhysicsStep DopplerTracking = 2 )
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsCamera3D ¶
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsCamera3D ¶
func (Instance) Attributes ¶
func (self Instance) Attributes() CameraAttributes.Instance
The CameraAttributes to use for this camera.
func (Instance) ClearCurrent ¶
func (self Instance) ClearCurrent()
If this is the current camera, remove it from being current. If 'enable_next' is true, request to make the next camera current, if any.
func (Instance) Compositor ¶
func (self Instance) Compositor() Compositor.Instance
The Compositor to use for this camera.
func (Instance) CullMask ¶
The culling mask that describes which VisualInstance3D.Layers are rendered by this camera. By default, all 20 user-visible layers are rendered.
Note: Since the CullMask allows for 32 layers to be stored in total, there are an additional 12 layers that are only used internally by the engine and aren't exposed in the editor. Setting CullMask using a script allows you to toggle those reserved layers, which can be useful for editor plugins.
To adjust CullMask more easily using a script, use GetCullMaskValue and SetCullMaskValue.
Note: VoxelGI, SDFGI and LightmapGI will always take all layers into account to determine what contributes to global illumination. If this is an issue, set GeometryInstance3D.GiMode to [Geometryinstance3d.GiModeDisabled] for meshes and Light3D.LightBakeMode to [Light3d.BakeDisabled] for lights to exclude them from global illumination.
func (Instance) Current ¶
If true, the ancestor Viewport is currently using this camera.
If multiple cameras are in the scene, one will always be made current. For example, if two Camera3D nodes are present in the scene and only one is current, setting one camera's Current to false will cause the other camera to be made current.
func (Instance) DopplerTracking ¶
func (self Instance) DopplerTracking() DopplerTracking
If not DopplerTrackingDisabled, this camera will simulate the Doppler effect for objects changed in particular _process methods.
Note: The Doppler effect will only be heard on AudioStreamPlayer3Ds if AudioStreamPlayer3D.DopplerTracking is not set to [Audiostreamplayer3d.DopplerTrackingDisabled].
func (Instance) Environment ¶
func (self Instance) Environment() Environment.Instance
The Environment to use for this camera.
func (Instance) Far ¶
The distance to the far culling boundary for this camera relative to its local Z axis. Higher values allow the camera to see further away, while decreasing Far can improve performance if it results in objects being partially or fully culled.
func (Instance) Fov ¶
The camera's field of view angle (in degrees). Only applicable in perspective mode. Since KeepAspect locks one axis, Fov sets the other axis' field of view angle.
For reference, the default vertical field of view value (75.0) is equivalent to a horizontal FOV of:
- ~91.31 degrees in a 4:3 viewport
- ~101.67 degrees in a 16:10 viewport
- ~107.51 degrees in a 16:9 viewport
- ~121.63 degrees in a 21:9 viewport
func (Instance) FrustumOffset ¶
The camera's frustum offset. This can be changed from the default to create "tilted frustum" effects such as Y-shearing.
Note: Only effective if Projection is ProjectionFrustum.
func (Instance) GetCameraProjection ¶
func (self Instance) GetCameraProjection() Projection.XYZW
Returns the projection matrix that this camera uses to render to its associated viewport. The camera must be part of the scene tree to function.
func (Instance) GetCameraRid ¶
Returns the camera's RID from the RenderingServer.
func (Instance) GetCameraTransform ¶
func (self Instance) GetCameraTransform() Transform3D.BasisOrigin
Returns the transform of the camera plus the vertical (VOffset) and horizontal (HOffset) offsets; and any other adjustments made to the position and orientation of the camera by subclassed cameras such as XRCamera3D.
func (Instance) GetCullMaskValue ¶
Returns whether or not the specified layer of the CullMask is enabled, given a 'layer_number' between 1 and 20.
func (Instance) GetFrustum ¶
Returns the camera's frustum planes in world space units as an array of Plane.NormalDs in the following order: near, far, left, top, right, bottom. Not to be confused with FrustumOffset.
func (Instance) GetPyramidShapeRid ¶
Returns the RID of a pyramid shape encompassing the camera's view frustum, ignoring the camera's near plane. The tip of the pyramid represents the position of the camera.
func (Instance) IsPositionBehind ¶
Returns true if the given position is behind the camera (the blue part of the linked diagram). See this diagram for an overview of position query methods.
Note: A position which returns false may still be outside the camera's field of view.
func (Instance) IsPositionInFrustum ¶
Returns true if the given position is inside the camera's frustum (the green part of the linked diagram). See this diagram for an overview of position query methods.
func (Instance) KeepAspect ¶
func (self Instance) KeepAspect() KeepAspect
The axis to lock during Fov/Size adjustments. Can be either KeepWidth or KeepHeight.
func (Instance) MakeCurrent ¶
func (self Instance) MakeCurrent()
Makes this camera the current camera for the Viewport (see class description). If the camera node is outside the scene tree, it will attempt to become current once it's added.
func (Instance) MoreArgs ¶
MoreArgs enables certain functions to be called with additional 'optional' arguments.
func (Instance) Near ¶
The distance to the near culling boundary for this camera relative to its local Z axis. Lower values allow the camera to see objects more up close to its origin, at the cost of lower precision across the entire range. Values lower than the default can lead to increased Z-fighting.
func (Instance) ProjectLocalRayNormal ¶
Returns a normal vector from the screen point location directed along the camera. Orthogonal cameras are normalized. Perspective cameras account for perspective, screen width/height, etc.
func (Instance) ProjectPosition ¶
Returns the 3D point in world space that maps to the given 2D coordinate in the Viewport rectangle on a plane that is the given 'z_depth' distance into the scene away from the camera.
func (Instance) ProjectRayNormal ¶
Returns a normal vector in world space, that is the result of projecting a point on the Viewport rectangle by the inverse camera projection. This is useful for casting rays in the form of (origin, normal) for object intersection or picking.
func (Instance) ProjectRayOrigin ¶
Returns a 3D position in world space, that is the result of projecting a point on the Viewport rectangle by the inverse camera projection. This is useful for casting rays in the form of (origin, normal) for object intersection or picking.
func (Instance) Projection ¶
func (self Instance) Projection() ProjectionType
The camera's projection mode. In ProjectionPerspective mode, objects' Z distance from the camera's local space scales their perceived size.
func (Instance) SetAttributes ¶
func (self Instance) SetAttributes(value CameraAttributes.Instance)
SetAttributes sets the property returned by [GetAttributes].
func (Instance) SetCompositor ¶
func (self Instance) SetCompositor(value Compositor.Instance)
SetCompositor sets the property returned by [GetCompositor].
func (Instance) SetCullMask ¶
SetCullMask sets the property returned by [GetCullMask].
func (Instance) SetCullMaskValue ¶
Based on 'value', enables or disables the specified layer in the CullMask, given a 'layer_number' between 1 and 20.
func (Instance) SetCurrent ¶
SetCurrent sets the property returned by [IsCurrent].
func (Instance) SetDopplerTracking ¶
func (self Instance) SetDopplerTracking(value DopplerTracking)
SetDopplerTracking sets the property returned by [GetDopplerTracking].
func (Instance) SetEnvironment ¶
func (self Instance) SetEnvironment(value Environment.Instance)
SetEnvironment sets the property returned by [GetEnvironment].
func (Instance) SetFrustum ¶
Sets the camera projection to frustum mode (see ProjectionFrustum), by specifying a 'size', an 'offset', and the 'z_near' and 'z_far' clip planes in world space units. See also FrustumOffset.
func (Instance) SetFrustumOffset ¶
SetFrustumOffset sets the property returned by [GetFrustumOffset].
func (Instance) SetHOffset ¶
SetHOffset sets the property returned by [GetHOffset].
func (Instance) SetKeepAspect ¶
func (self Instance) SetKeepAspect(value KeepAspect)
SetKeepAspect sets the property returned by [GetKeepAspectMode].
func (Instance) SetOrthogonal ¶
Sets the camera projection to orthogonal mode (see ProjectionOrthogonal), by specifying a 'size', and the 'z_near' and 'z_far' clip planes in world space units.
As a hint, 3D games that look 2D often use this projection, with 'size' specified in pixels.
func (Instance) SetPerspective ¶
Sets the camera projection to perspective mode (see ProjectionPerspective), by specifying a 'fov' (field of view) angle in degrees, and the 'z_near' and 'z_far' clip planes in world space units.
func (Instance) SetProjection ¶
func (self Instance) SetProjection(value ProjectionType)
SetProjection sets the property returned by [GetProjection].
func (Instance) SetVOffset ¶
SetVOffset sets the property returned by [GetVOffset].
func (Instance) Size ¶
The camera's size in meters measured as the diameter of the width or height, depending on KeepAspect. Only applicable in orthogonal and frustum modes.
func (Instance) UnprojectPosition ¶
Returns the 2D coordinate in the Viewport rectangle that maps to the given 3D point in world space.
Note: When using this to position GUI elements over a 3D viewport, use IsPositionBehind to prevent them from appearing if the 3D point is behind the camera:
// This code block is part of a script that inherits from Node3D. // `control` is a reference to a node inheriting from Control. control.AsCanvasItem().SetVisible(!Viewport.Get(node3d.AsNode()).GetCamera3d().IsPositionBehind(node3d.GlobalTransform().Origin)) control.SetPosition(Viewport.Get(node3d.AsNode()).GetCamera3d().UnprojectPosition(node3d.GlobalTransform().Origin))
type KeepAspect ¶
type KeepAspect int //gd:Camera3D.KeepAspect
const ( // Preserves the horizontal aspect ratio; also known as Vert- scaling. This is usually the best option for projects running in portrait mode, as taller aspect ratios will benefit from a wider vertical FOV. KeepWidth KeepAspect = 0 // Preserves the vertical aspect ratio; also known as Hor+ scaling. This is usually the best option for projects running in landscape mode, as wider aspect ratios will automatically benefit from a wider horizontal FOV. KeepHeight KeepAspect = 1 )
type MoreArgs ¶
MoreArgs is a container for Instance functions with additional 'optional' arguments.
func (MoreArgs) ClearCurrent ¶
If this is the current camera, remove it from being current. If 'enable_next' is true, request to make the next camera current, if any.
type ProjectionType ¶
type ProjectionType int //gd:Camera3D.ProjectionType
const ( // Perspective projection. Objects on the screen becomes smaller when they are far away. ProjectionPerspective ProjectionType = 0 // Orthogonal projection, also known as orthographic projection. Objects remain the same size on the screen no matter how far away they are. ProjectionOrthogonal ProjectionType = 1 // Frustum projection. This mode allows adjusting [FrustumOffset] to create "tilted frustum" effects. // // [FrustumOffset]: https://pkg.go.dev/graphics.gd/classdb/#Instance.FrustumOffset ProjectionFrustum ProjectionType = 2 )