MultiMesh

package
v0.0.0-...-fe0704e Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

MultiMesh provides low-level mesh instancing. Drawing thousands of 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

Custom AABB for this MultiMesh resource. Setting this manually prevents costly runtime AABB recalculations.

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

Number of instances that will get drawn. This clears and (re)sizes the buffers. Setting data format or flags afterwards will have no effect.

By default, all instances are drawn but you can limit this with VisibleInstanceCount.

func (Instance) Mesh

func (self Instance) Mesh() Mesh.Instance

Mesh resource to be instanced.

The looks of the individual instances can be modified using SetInstanceColor and SetInstanceCustomData.

func (Instance) PhysicsInterpolationQuality

func (self Instance) PhysicsInterpolationQuality() PhysicsInterpolationQuality

Choose whether to use an interpolation method that favors speed or quality.

When using low physics tick rates (typically below 20) or high rates of object rotation, you may get better results from the high quality setting.

Note: Fast quality does not equate to low quality. Except in the special cases mentioned above, the quality should be comparable to high quality.

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)

SetBuffer sets the property returned by [GetBuffer].

func (Instance) SetBufferInterpolated

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

An alternative to setting the 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 Buffer can still be used with interpolation.

func (Instance) SetCustomAabb

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

SetCustomAabb sets the property returned by [GetCustomAabb].

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 UseColors is true on the MultiMesh and BaseMaterial3D.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)

SetInstanceCount sets the property returned by [GetInstanceCount].

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

SetMesh sets the property returned by [GetMesh].

func (*Instance) SetObject

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

func (Instance) SetPhysicsInterpolationQuality

func (self Instance) SetPhysicsInterpolationQuality(value PhysicsInterpolationQuality)

SetPhysicsInterpolationQuality sets the property returned by [GetPhysicsInterpolationQuality].

func (Instance) SetTransformFormat

func (self Instance) SetTransformFormat(value TransformFormat)

SetTransformFormat sets the property returned by [GetTransformFormat].

func (Instance) SetUseColors

func (self Instance) SetUseColors(value bool)

SetUseColors sets the property returned by [IsUsingColors].

func (Instance) SetUseCustomData

func (self Instance) SetUseCustomData(value bool)

SetUseCustomData sets the property returned by [IsUsingCustomData].

func (Instance) SetVisibleInstanceCount

func (self Instance) SetVisibleInstanceCount(value int)

SetVisibleInstanceCount sets the property returned by [GetVisibleInstanceCount].

func (Instance) TransformFormat

func (self Instance) TransformFormat() TransformFormat

Format of transform used to transform mesh, either 2D or 3D.

func (Instance) UseColors

func (self Instance) UseColors() bool

If true, the MultiMesh will use color data (see SetInstanceColor). Can only be set when InstanceCount is 0 or less. This means that you need to call this method before setting the instance count, or temporarily reset it to 0.

func (Instance) UseCustomData

func (self Instance) UseCustomData() bool

If true, the MultiMesh will use custom data (see SetInstanceCustomData). Can only be set when InstanceCount is 0 or less. This means that you need to call this method before setting the instance count, or temporarily reset it to 0.

func (Instance) Virtual

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

func (Instance) VisibleInstanceCount

func (self Instance) VisibleInstanceCount() int

Limits the number of instances drawn, -1 draws all instances. Changing this does not change the sizes of the buffers.

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