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 ¶
- type Advanced
- type Any
- type Expanded
- type Extension
- type ID
- type Instance
- func (self Instance) AsMeshDataTool() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) Clear()
- func (self Instance) CommitToSurface(mesh ArrayMesh.Instance) error
- func (self Instance) CreateFromSurface(mesh ArrayMesh.Instance, surface int) error
- func (self Instance) GetEdgeCount() int
- func (self Instance) GetEdgeFaces(idx int) []int32
- func (self Instance) GetEdgeMeta(idx int) any
- func (self Instance) GetEdgeVertex(idx int, vertex int) int
- func (self Instance) GetFaceCount() int
- func (self Instance) GetFaceEdge(idx int, edge int) int
- func (self Instance) GetFaceMeta(idx int) any
- func (self Instance) GetFaceNormal(idx int) Vector3.XYZ
- func (self Instance) GetFaceVertex(idx int, vertex int) int
- func (self Instance) GetFormat() int
- func (self Instance) GetMaterial() Material.Instance
- func (self Instance) GetVertex(idx int) Vector3.XYZ
- func (self Instance) GetVertexBones(idx int) []int32
- func (self Instance) GetVertexColor(idx int) Color.RGBA
- func (self Instance) GetVertexCount() int
- func (self Instance) GetVertexEdges(idx int) []int32
- func (self Instance) GetVertexFaces(idx int) []int32
- func (self Instance) GetVertexMeta(idx int) any
- func (self Instance) GetVertexNormal(idx int) Vector3.XYZ
- func (self Instance) GetVertexTangent(idx int) Plane.NormalD
- func (self Instance) GetVertexUv(idx int) Vector2.XY
- func (self Instance) GetVertexUv2(idx int) Vector2.XY
- func (self Instance) GetVertexWeights(idx int) []float32
- func (self Instance) ID() ID
- func (self Instance) SetEdgeMeta(idx int, meta any)
- func (self Instance) SetFaceMeta(idx int, meta any)
- func (self Instance) SetMaterial(material Material.Instance)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetVertex(idx int, vertex Vector3.XYZ)
- func (self Instance) SetVertexBones(idx int, bones []int32)
- func (self Instance) SetVertexColor(idx int, color Color.RGBA)
- func (self Instance) SetVertexMeta(idx int, meta any)
- func (self Instance) SetVertexNormal(idx int, normal Vector3.XYZ)
- func (self Instance) SetVertexTangent(idx int, tangent Plane.NormalD)
- func (self Instance) SetVertexUv(idx int, uv Vector2.XY)
- func (self Instance) SetVertexUv2(idx int, uv2 Vector2.XY)
- func (self Instance) SetVertexWeights(idx int, weights []float32)
- func (self Instance) Virtual(name string) reflect.Value
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 Expanded ¶
type Expanded [1]gdclass.MeshDataTool
func (Expanded) CommitToSurface ¶
Adds a new surface to specified graphics.gd/classdb/Mesh with edited data.
type Extension ¶
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 (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
type 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.
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 (Instance) AsMeshDataTool ¶
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) CommitToSurface ¶
Adds a new surface to specified graphics.gd/classdb/Mesh with edited data.
func (Instance) CreateFromSurface ¶
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 ¶
Returns the number of edges in this graphics.gd/classdb/Mesh.
func (Instance) GetEdgeFaces ¶
Returns array of faces that touch given edge.
func (Instance) GetEdgeMeta ¶
Returns meta information assigned to given edge.
func (Instance) GetEdgeVertex ¶
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 ¶
Returns the number of faces in this graphics.gd/classdb/Mesh.
func (Instance) GetFaceEdge ¶
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 ¶
Returns the metadata associated with the given face.
func (Instance) GetFaceNormal ¶
Calculates and returns the face normal of the given face.
func (Instance) GetFaceVertex ¶
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 ¶
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 ¶
Returns the material assigned to the graphics.gd/classdb/Mesh.
func (Instance) GetVertexBones ¶
Returns the bones of the given vertex.
func (Instance) GetVertexColor ¶
Returns the color of the given vertex.
func (Instance) GetVertexCount ¶
Returns the total number of vertices in graphics.gd/classdb/Mesh.
func (Instance) GetVertexEdges ¶
Returns an array of edges that share the given vertex.
func (Instance) GetVertexFaces ¶
Returns an array of faces that share the given vertex.
func (Instance) GetVertexMeta ¶
Returns the metadata associated with the given vertex.
func (Instance) GetVertexNormal ¶
Returns the normal of the given vertex.
func (Instance) GetVertexTangent ¶
Returns the tangent of the given vertex.
func (Instance) GetVertexUv ¶
Returns the UV of the given vertex.
func (Instance) GetVertexUv2 ¶
Returns the UV2 of the given vertex.
func (Instance) GetVertexWeights ¶
Returns bone weights of the given vertex.
func (Instance) SetEdgeMeta ¶
Sets the metadata of the given edge.
func (Instance) SetFaceMeta ¶
Sets the metadata of the given face.
func (Instance) SetMaterial ¶
Sets the material to be used by newly-constructed graphics.gd/classdb/Mesh.
func (Instance) SetVertexBones ¶
Sets the bones of the given vertex.
func (Instance) SetVertexColor ¶
Sets the color of the given vertex.
func (Instance) SetVertexMeta ¶
Sets the metadata associated with the given vertex.
func (Instance) SetVertexNormal ¶
Sets the normal of the given vertex.
func (Instance) SetVertexTangent ¶
Sets the tangent of the given vertex.
func (Instance) SetVertexUv ¶
Sets the UV of the given vertex.
func (Instance) SetVertexUv2 ¶
Sets the UV2 of the given vertex.
func (Instance) SetVertexWeights ¶
Sets the bone weights of the given vertex.