MeshDataTool

package
v0.0.0-...-c858641 Latest Latest
Warning

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

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

Documentation

Overview

MeshDataTool provides access to individual vertices in a graphics.gd/classdb/Mesh. It allows users to read and edit vertex data of meshes. It also creates an array of faces and edges.

To use MeshDataTool, load a mesh with Instance.CreateFromSurface. When you are finished editing the data commit the data to a mesh with Instance.CommitToSurface.

Below is an example of how MeshDataTool may be used.

package main

import (
	"graphics.gd/classdb/ArrayMesh"
	"graphics.gd/classdb/BoxMesh"
	"graphics.gd/classdb/Mesh"
	"graphics.gd/classdb/MeshDataTool"
	"graphics.gd/classdb/MeshInstance3D"
	"graphics.gd/classdb/Node"
	"graphics.gd/variant/Vector3"
)

func ExampleMeshDataTool(parent Node.Instance) {
	var mesh = ArrayMesh.New()
	mesh.AddSurfaceFromArrays(Mesh.PrimitiveTriangles, BoxMesh.New().AsPrimitiveMesh().GetMeshArrays())
	var mdt = MeshDataTool.New()
	mdt.CreateFromSurface(mesh, 0)
	for i := 0; i < mdt.GetVertexCount(); i++ {
		var vertex = mdt.GetVertex(i)
		// In this example we extend the mesh by one unit, which results in separated faces as it is flat shaded.
		vertex = Vector3.Add(vertex, mdt.GetVertexNormal(i))
		// Save your change.
		mdt.SetVertex(i, vertex)
	}
	mesh.ClearSurfaces()
	mdt.CommitToSurface(mesh)
	var mi = MeshInstance3D.New()
	mi.SetMesh(mesh.AsMesh())
	parent.AddChild(mi.AsNode())
}

See also graphics.gd/classdb/ArrayMesh, graphics.gd/classdb/ImmediateMesh and graphics.gd/classdb/SurfaceTool for procedural geometry generation.

Note: Godot uses clockwise winding order for front faces of triangle primitive modes.

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
	AsMeshDataTool() Instance
}

type Expanded

type Expanded [1]gdclass.MeshDataTool

func (Expanded) CommitToSurface

func (self Expanded) CommitToSurface(mesh ArrayMesh.Instance, compression_flags int) error

Adds a new surface to specified graphics.gd/classdb/Mesh with edited data.

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

func (self *Extension[T]) AsMeshDataTool() 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

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.MeshDataTool

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

func (self Instance) AsMeshDataTool() Instance

func (Instance) AsObject

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

func (Instance) AsRefCounted

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

func (Instance) Clear

func (self Instance) Clear()

Clears all data currently in MeshDataTool.

func (Instance) CommitToSurface

func (self Instance) CommitToSurface(mesh ArrayMesh.Instance) error

Adds a new surface to specified graphics.gd/classdb/Mesh with edited data.

func (Instance) CreateFromSurface

func (self Instance) CreateFromSurface(mesh ArrayMesh.Instance, surface int) error

Uses specified surface of given graphics.gd/classdb/Mesh to populate data for MeshDataTool.

Requires graphics.gd/classdb/Mesh with primitive type [Mesh.PrimitiveTriangles].

func (Instance) GetEdgeCount

func (self Instance) GetEdgeCount() int

Returns the number of edges in this graphics.gd/classdb/Mesh.

func (Instance) GetEdgeFaces

func (self Instance) GetEdgeFaces(idx int) []int32

Returns array of faces that touch given edge.

func (Instance) GetEdgeMeta

func (self Instance) GetEdgeMeta(idx int) any

Returns meta information assigned to given edge.

func (Instance) GetEdgeVertex

func (self Instance) GetEdgeVertex(idx int, vertex int) int

Returns index of specified vertex connected to given edge.

Vertex argument can only be 0 or 1 because edges are comprised of two vertices.

func (Instance) GetFaceCount

func (self Instance) GetFaceCount() int

Returns the number of faces in this graphics.gd/classdb/Mesh.

func (Instance) GetFaceEdge

func (self Instance) GetFaceEdge(idx int, edge int) int

Returns specified edge associated with given face.

Edge argument must be either 0, 1, or 2 because a face only has three edges.

func (Instance) GetFaceMeta

func (self Instance) GetFaceMeta(idx int) any

Returns the metadata associated with the given face.

func (Instance) GetFaceNormal

func (self Instance) GetFaceNormal(idx int) Vector3.XYZ

Calculates and returns the face normal of the given face.

func (Instance) GetFaceVertex

func (self Instance) GetFaceVertex(idx int, vertex int) int

Returns the specified vertex index of the given face.

'vertex' must be either 0, 1, or 2 because faces contain three vertices.

func (Instance) GetFormat

func (self Instance) GetFormat() int

Returns the graphics.gd/classdb/Mesh's format as a combination of the [Mesh.ArrayFormat] flags. For example, a mesh containing both vertices and normals would return a format of 3 because [Mesh.ArrayFormatVertex] is 1 and [Mesh.ArrayFormatNormal] is 2.

func (Instance) GetMaterial

func (self Instance) GetMaterial() Material.Instance

Returns the material assigned to the graphics.gd/classdb/Mesh.

func (Instance) GetVertex

func (self Instance) GetVertex(idx int) Vector3.XYZ

Returns the position of the given vertex.

func (Instance) GetVertexBones

func (self Instance) GetVertexBones(idx int) []int32

Returns the bones of the given vertex.

func (Instance) GetVertexColor

func (self Instance) GetVertexColor(idx int) Color.RGBA

Returns the color of the given vertex.

func (Instance) GetVertexCount

func (self Instance) GetVertexCount() int

Returns the total number of vertices in graphics.gd/classdb/Mesh.

func (Instance) GetVertexEdges

func (self Instance) GetVertexEdges(idx int) []int32

Returns an array of edges that share the given vertex.

func (Instance) GetVertexFaces

func (self Instance) GetVertexFaces(idx int) []int32

Returns an array of faces that share the given vertex.

func (Instance) GetVertexMeta

func (self Instance) GetVertexMeta(idx int) any

Returns the metadata associated with the given vertex.

func (Instance) GetVertexNormal

func (self Instance) GetVertexNormal(idx int) Vector3.XYZ

Returns the normal of the given vertex.

func (Instance) GetVertexTangent

func (self Instance) GetVertexTangent(idx int) Plane.NormalD

Returns the tangent of the given vertex.

func (Instance) GetVertexUv

func (self Instance) GetVertexUv(idx int) Vector2.XY

Returns the UV of the given vertex.

func (Instance) GetVertexUv2

func (self Instance) GetVertexUv2(idx int) Vector2.XY

Returns the UV2 of the given vertex.

func (Instance) GetVertexWeights

func (self Instance) GetVertexWeights(idx int) []float32

Returns bone weights of the given vertex.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) SetEdgeMeta

func (self Instance) SetEdgeMeta(idx int, meta any)

Sets the metadata of the given edge.

func (Instance) SetFaceMeta

func (self Instance) SetFaceMeta(idx int, meta any)

Sets the metadata of the given face.

func (Instance) SetMaterial

func (self Instance) SetMaterial(material Material.Instance)

Sets the material to be used by newly-constructed graphics.gd/classdb/Mesh.

func (*Instance) SetObject

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

func (Instance) SetVertex

func (self Instance) SetVertex(idx int, vertex Vector3.XYZ)

Sets the position of the given vertex.

func (Instance) SetVertexBones

func (self Instance) SetVertexBones(idx int, bones []int32)

Sets the bones of the given vertex.

func (Instance) SetVertexColor

func (self Instance) SetVertexColor(idx int, color Color.RGBA)

Sets the color of the given vertex.

func (Instance) SetVertexMeta

func (self Instance) SetVertexMeta(idx int, meta any)

Sets the metadata associated with the given vertex.

func (Instance) SetVertexNormal

func (self Instance) SetVertexNormal(idx int, normal Vector3.XYZ)

Sets the normal of the given vertex.

func (Instance) SetVertexTangent

func (self Instance) SetVertexTangent(idx int, tangent Plane.NormalD)

Sets the tangent of the given vertex.

func (Instance) SetVertexUv

func (self Instance) SetVertexUv(idx int, uv Vector2.XY)

Sets the UV of the given vertex.

func (Instance) SetVertexUv2

func (self Instance) SetVertexUv2(idx int, uv2 Vector2.XY)

Sets the UV2 of the given vertex.

func (Instance) SetVertexWeights

func (self Instance) SetVertexWeights(idx int, weights []float32)

Sets the bone weights of the given vertex.

func (Instance) Virtual

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

Jump to

Keyboard shortcuts

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