Content

*"Godot" on https://aligot-death.space*, available at https://aligot-death.space/wiki/godot-en

# Godot

Some notes about godot

I usually work in csharp but most of the code here can be easily translated
into godot's language "GDScript" *if necessary* using the API's guide.

## Multimesh buffer's layout#

The `Multimesh` property of a `MultiMeshInstance3D` node exposes its raw data through a `Buffer` property allowing for instance to apply updated data from a compute shader directly.

Its layout is however fairly opaque and hidden in other wiki pages and in the source code: so here is a snippet to avoid (my) hours of headbanging research.

Each instance has a `Transform3D` property describing its position, rotate and scale, itself composed of an Vector3 `Origin` describing its position, and a 3x Vector3 `Basis` describing its rotation and scale. Each Vector3 is being made of three floats values, forming a set of **12** float values in a (in my opinion) non-intuitive order.

If you enable `UseColors=true`, four additional values (R, G, B and A, as a `Color` property) are added **at the end** of this set.

If you enable `UseCustomData=true`, four additional values (for well, custom usages) are added **at the end** of this set.

Depending on the configuration, your data set will be of size 12, 16 or 20, and you need to offset you id's by that factor.

1 int offset 16; //3D base + color enabled, no custom data 2 int BufferId = offset * id; 3 4 data[BufferId + 0] = value.Basis.X.X; 5 data[BufferId + 4] = value.Basis.X.Y; 6 data[BufferId + 8] = value.Basis.X.Z; 7 8 data[BufferId + 1] = value.Basis.Y.X; 9 data[BufferId + 5] = value.Basis.Y.Y; 10 data[BufferId + 9] = value.Basis.Y.Z; 11 12 data[BufferId + 2] = value.Basis.Z.X; 13 data[BufferId + 6] = value.Basis.Z.Y; 14 data[BufferId +10] = value.Basis.Z.Z; 15 16 data[BufferId + 3] = value.Origin.X; 17 data[BufferId + 7] = value.Origin.Y; 18 data[BufferId +11] = value.Origin.Z; 19 20 data[BufferId +12] = value.Color.R; 21 data[BufferId +13] = value.Color.G; 22 data[BufferId +13] = value.Color.B; 23 data[BufferId +13] = value.Color.A;

## MultiMeshInstance (2D)#

In the case of 2D the same applies, but with `Origin` being only a Vector2 and `Basis` being only 2x Vector2, forming a 2+2x2[+ 4][+ 4] data set of size going from 6 to 14.