MultiMesh

package
v0.0.0-...-e1beaa7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

MultiMesh provides low-level mesh instancing. Drawing thousands of graphics.gd/classdb/MeshInstance3D nodes can be slow, since each object is submitted to the GPU then drawn individually.

MultiMesh is much faster as it can draw thousands of instances with a single draw call, resulting in less API overhead.

As a drawback, if the instances are too far away from each other, performance may be reduced as every single instance will always render (they are spatially indexed as one, for the whole object).

Since instances may have any behavior, the AABB used for visibility must be provided by the user.

Note: A MultiMesh is a single object, therefore the same maximum lights per object restriction applies. This means, that once the maximum lights are consumed by one or more instances, the rest of the MultiMesh instances will not receive any lighting.

Note: Blend Shapes will be ignored if used in a MultiMesh.

Index

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 Any

type Any interface {
	gd.IsClass
	AsMultiMesh() Instance
}

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

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]) AsMultiMesh

func (self *Extension[T]) AsMultiMesh() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

func (*Extension[T]) AsResource

func (self *Extension[T]) AsResource() Resource.Instance

type ID

type ID Object.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.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.MultiMesh

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 New

func New() Instance

func (Instance) AsMultiMesh

func (self Instance) AsMultiMesh() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResource

func (self Instance) AsResource() Resource.Instance

func (Instance) Buffer

func (self Instance) Buffer() []float32

func (Instance) CustomAabb

func (self Instance) CustomAabb() AABB.PositionSize

func (Instance) GetAabb

func (self Instance) GetAabb() AABB.PositionSize

Returns the visibility axis-aligned bounding box in local space.

func (Instance) GetInstanceColor

func (self Instance) GetInstanceColor(instance int) Color.RGBA

Gets a specific instance's color multiplier.

func (Instance) GetInstanceCustomData

func (self Instance) GetInstanceCustomData(instance int) Color.RGBA

Returns the custom data that has been set for a specific instance.

func (Instance) GetInstanceTransform

func (self Instance) GetInstanceTransform(instance int) Transform3D.BasisOrigin

Returns the [Transform3D.BasisOrigin] of a specific instance.

func (Instance) GetInstanceTransform2d

func (self Instance) GetInstanceTransform2d(instance int) Transform2D.OriginXY

Returns the [Transform2D.OriginXY] of a specific instance.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) InstanceCount

func (self Instance) InstanceCount() int

func (Instance) Mesh

func (self Instance) Mesh() Mesh.Instance

func (Instance) PhysicsInterpolationQuality

func (self Instance) PhysicsInterpolationQuality() PhysicsInterpolationQuality

func (Instance) ResetInstancePhysicsInterpolation

func (self Instance) ResetInstancePhysicsInterpolation(instance int)

When using physics interpolation, this function allows you to prevent interpolation on an instance in the current physics tick.

This allows you to move instances instantaneously, and should usually be used when initially placing an instance such as a bullet to prevent graphical glitches.

func (Instance) SetBuffer

func (self Instance) SetBuffer(value []float32)

func (Instance) SetBufferInterpolated

func (self Instance) SetBufferInterpolated(buffer_curr []float32, buffer_prev []float32)

An alternative to setting the Instance.Buffer property, which can be used with physics interpolation. This method takes two arrays, and can set the data for the current and previous tick in one go. The renderer will automatically interpolate the data at each frame.

This is useful for situations where the order of instances may change from physics tick to tick, such as particle systems.

When the order of instances is coherent, the simpler alternative of setting Instance.Buffer can still be used with interpolation.

func (Instance) SetCustomAabb

func (self Instance) SetCustomAabb(value AABB.PositionSize)

func (Instance) SetInstanceColor

func (self Instance) SetInstanceColor(instance int, color Color.RGBA)

Sets the color of a specific instance by multiplying the mesh's existing vertex colors. This allows for different color tinting per instance.

Note: Each component is stored in 32 bits in the Forward+ and Mobile rendering methods, but is packed into 16 bits in the Compatibility rendering method.

For the color to take effect, ensure that Instance.UseColors is true on the graphics.gd/classdb/MultiMesh and graphics.gd/classdb/BaseMaterial3D.Instance.VertexColorUseAsAlbedo is true on the material. If you intend to set an absolute color instead of tinting, make sure the material's albedo color is set to pure white (Color(1, 1, 1)).

func (Instance) SetInstanceCount

func (self Instance) SetInstanceCount(value int)

func (Instance) SetInstanceCustomData

func (self Instance) SetInstanceCustomData(instance int, custom_data Color.RGBA)

Sets custom data for a specific instance. 'custom_data' is a [Color.RGBA] type only to contain 4 floating-point numbers.

Note: Each number is stored in 32 bits in the Forward+ and Mobile rendering methods, but is packed into 16 bits in the Compatibility rendering method.

For the custom data to be used, ensure that Instance.UseCustomData is true.

This custom instance data has to be manually accessed in your custom shader using INSTANCE_CUSTOM.

func (Instance) SetInstanceTransform

func (self Instance) SetInstanceTransform(instance int, transform Transform3D.BasisOrigin)

Sets the [Transform3D.BasisOrigin] for a specific instance.

func (Instance) SetInstanceTransform2d

func (self Instance) SetInstanceTransform2d(instance int, transform Transform2D.OriginXY)

Sets the [Transform2D.OriginXY] for a specific instance.

func (Instance) SetMesh

func (self Instance) SetMesh(value Mesh.Instance)

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetPhysicsInterpolationQuality

func (self Instance) SetPhysicsInterpolationQuality(value PhysicsInterpolationQuality)

func (Instance) SetTransformFormat

func (self Instance) SetTransformFormat(value TransformFormat)

func (Instance) SetUseColors

func (self Instance) SetUseColors(value bool)

func (Instance) SetUseCustomData

func (self Instance) SetUseCustomData(value bool)

func (Instance) SetVisibleInstanceCount

func (self Instance) SetVisibleInstanceCount(value int)

func (Instance) TransformFormat

func (self Instance) TransformFormat() TransformFormat

func (Instance) UseColors

func (self Instance) UseColors() bool

func (Instance) UseCustomData

func (self Instance) UseCustomData() bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

func (Instance) VisibleInstanceCount

func (self Instance) VisibleInstanceCount() int

type PhysicsInterpolationQuality

type PhysicsInterpolationQuality int //gd:MultiMesh.PhysicsInterpolationQuality
const (
	// Always interpolate using Basis lerping, which can produce warping artifacts in some situations.
	InterpQualityFast PhysicsInterpolationQuality = 0
	// Attempt to interpolate using Basis slerping (spherical linear interpolation) where possible, otherwise fall back to lerping.
	InterpQualityHigh PhysicsInterpolationQuality = 1
)

type TransformFormat

type TransformFormat int //gd:MultiMesh.TransformFormat
const (
	// Use this when using 2D transforms.
	Transform2d TransformFormat = 0
	// Use this when using 3D transforms.
	Transform3d TransformFormat = 1
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL