|
@@ -21,6 +21,14 @@ Attributes are added before each vertex is added:
|
|
|
st.add_vertex() # Captures normal and color above.
|
|
|
st.set_normal() # Normal never added to a vertex.
|
|
|
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ st.SetNormal(); // Overwritten by normal below.
|
|
|
+ st.SetNormal(); // Added to next vertex.
|
|
|
+ st.SetColor(); // Added to next vertex.
|
|
|
+ st.AddVertex(); // Captures normal and color above.
|
|
|
+ st.SetNormal(); // Normal never added to a vertex.
|
|
|
+
|
|
|
When finished generating your geometry with the :ref:`SurfaceTool <class_surfacetool>`
|
|
|
call ``commit()`` to finish generating the mesh. If an :ref:`ArrayMesh <class_ArrayMesh>` is passed
|
|
|
to ``commit()`` then it appends a new surface to the end of the ArrayMesh. While if nothing is passed
|
|
@@ -33,6 +41,12 @@ in, ``commit()`` returns an ArrayMesh.
|
|
|
# Or:
|
|
|
var mesh = st.commit()
|
|
|
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ st.Commit(mesh);
|
|
|
+ // Or:
|
|
|
+ var mesh = st.Commit();
|
|
|
+
|
|
|
Code creates a triangle with indices
|
|
|
|
|
|
.. tabs::
|
|
@@ -59,6 +73,29 @@ Code creates a triangle with indices
|
|
|
# Commit to a mesh.
|
|
|
var mesh = st.commit()
|
|
|
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ var st = new SurfaceTool();
|
|
|
+
|
|
|
+ st.Begin(Mesh.PrimitiveType.Triangles);
|
|
|
+
|
|
|
+ // Prepare attributes for AddVertex.
|
|
|
+ st.SetNormal(new Vector3(0, 0, 1));
|
|
|
+ st.SetUV(new Vector2(0, 0));
|
|
|
+ // Call last for each vertex, adds the above attributes.
|
|
|
+ st.AddVertex(new Vector3(-1, -1, 0));
|
|
|
+
|
|
|
+ st.SetNormal(new Vector3(0, 0, 1));
|
|
|
+ st.SetUV(new Vector2(0, 1));
|
|
|
+ st.AddVertex(new Vector3(-1, 1, 0));
|
|
|
+
|
|
|
+ st.SetNormal(new Vector3(0, 0, 1));
|
|
|
+ st.SetUV(new Vector2(1, 1));
|
|
|
+ st.AddVertex(new Vector3(1, 1, 0));
|
|
|
+
|
|
|
+ // Commit to a mesh.
|
|
|
+ var mesh = st.Commit();
|
|
|
+
|
|
|
You can optionally add an index array, either by calling ``add_index()`` and adding
|
|
|
vertices to the index array or by calling ``index()`` which shrinks the vertex array
|
|
|
to remove duplicate vertices.
|
|
@@ -67,7 +104,7 @@ to remove duplicate vertices.
|
|
|
.. code-tab:: gdscript GDScript
|
|
|
|
|
|
# Creates a quad from four corner vertices.
|
|
|
- # Add_index does not need to be called before add_vertex.
|
|
|
+ # add_index does not need to be called before add_vertex.
|
|
|
st.add_index(0)
|
|
|
st.add_index(1)
|
|
|
st.add_index(2)
|
|
@@ -79,6 +116,21 @@ to remove duplicate vertices.
|
|
|
# Alternatively:
|
|
|
st.index()
|
|
|
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ // Creates a quad from four corner vertices.
|
|
|
+ // AddIndex does not need to be called before AddVertex.
|
|
|
+ st.AddIndex(0);
|
|
|
+ st.AddIndex(1);
|
|
|
+ st.AddIndex(2);
|
|
|
+
|
|
|
+ st.AddIndex(1);
|
|
|
+ st.AddIndex(3);
|
|
|
+ st.AddIndex(2);
|
|
|
+
|
|
|
+ // Alternatively:
|
|
|
+ st.Index();
|
|
|
+
|
|
|
Similarly, if you have an index array, but you want each vertex to be unique (e.g. because
|
|
|
you want to use unique normals or colors per face instead of per-vertex), you can call ``deindex()``.
|
|
|
|
|
@@ -87,6 +139,10 @@ you want to use unique normals or colors per face instead of per-vertex), you ca
|
|
|
|
|
|
st.deindex()
|
|
|
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ st.Deindex();
|
|
|
+
|
|
|
If you don't add custom normals yourself, you can add them using ``generate_normals()``, which should
|
|
|
be called after generating geometry and before committing the mesh using ``commit()`` or
|
|
|
``commit_to_arrays()``. Calling ``generate_normals(true)`` will flip the resulting normals. As a side
|
|
@@ -105,6 +161,11 @@ normals set already.
|
|
|
st.generate_normals()
|
|
|
st.generate_tangents()
|
|
|
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ st.GenerateNormals();
|
|
|
+ st.GenerateTangents();
|
|
|
+
|
|
|
By default, when generating normals, they will be calculated on a per-face basis. If you want
|
|
|
smooth vertex normals, when adding vertices, call ``add_smooth_group()``. ``add_smooth_group()``
|
|
|
needs to be called while building the geometry, e.g. before the call to ``add_vertex()``
|