MeshDataTool

package
v0.0.0-...-fa94a0d Latest Latest
Warning

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

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

Documentation

Overview

MeshDataTool provides access to individual vertices in a 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 CreateFromSurface. When you are finished editing the data commit the data to a mesh with 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 ArrayMesh, ImmediateMesh and 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 = MoreArgs

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 Mesh with edited data.

func (Instance) CreateFromSurface

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

Uses specified surface of given Mesh to populate data for MeshDataTool.

Requires Mesh with primitive type [Mesh.PrimitiveTriangles].

func (Instance) GetEdgeCount

func (self Instance) GetEdgeCount() int

Returns the number of edges in this 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 the index of the specified 'vertex' connected to the edge at index 'idx'.

'vertex' can only be 0 or 1, as edges are composed of two vertices.

func (Instance) GetFaceCount

func (self Instance) GetFaceCount() int

Returns the number of faces in this Mesh.

func (Instance) GetFaceEdge

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

Returns the edge associated with the face at index 'idx'.

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

func (self Instance) MoreArgs() MoreArgs

MoreArgs enables certain functions to be called with additional 'optional' arguments.

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

type MoreArgs

type MoreArgs [1]gdclass.MeshDataTool

MoreArgs is a container for Instance functions with additional 'optional' arguments.

func (MoreArgs) CommitToSurface

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

Adds a new surface to specified Mesh with edited data.

Jump to

Keyboard shortcuts

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