@@ -15,6 +15,10 @@ Attributes are added before each vertex is added:
15
15
.. tabs ::
16
16
.. code-tab :: gdscript GDScript
17
17
18
+ var st = SurfaceTool.new()
19
+
20
+ st.begin(Mesh.PRIMITIVE_TRIANGLES)
21
+
18
22
st.set_normal() # Overwritten by normal below.
19
23
st.set_normal() # Added to next vertex.
20
24
st.set_color() # Added to next vertex.
@@ -29,16 +33,20 @@ Attributes are added before each vertex is added:
29
33
st.AddVertex(); // Captures normal and color above.
30
34
st.SetNormal(); // Normal never added to a vertex.
31
35
32
- When finished generating your geometry with the :ref: `SurfaceTool <class_surfacetool >`
36
+ When finished generating your geometry with the :ref: `SurfaceTool <class_surfacetool >`,
33
37
call ``commit() `` to finish generating the mesh. If an :ref: `ArrayMesh <class_ArrayMesh >` is passed
34
- to ``commit() `` then it appends a new surface to the end of the ArrayMesh. While if nothing is passed
38
+ to ``commit() ``, then it appends a new surface to the end of the ArrayMesh. While if nothing is passed
35
39
in, ``commit() `` returns an ArrayMesh.
36
40
37
41
.. tabs ::
38
42
.. code-tab :: gdscript GDScript
39
43
44
+ # Add surface to existing ArrayMesh.
40
45
st.commit(mesh)
41
- # Or:
46
+
47
+ # -- Or Alternatively --
48
+
49
+ # Create new ArrayMesh.
42
50
var mesh = st.commit()
43
51
44
52
.. code-tab :: csharp
@@ -47,7 +55,7 @@ in, ``commit()`` returns an ArrayMesh.
47
55
// Or:
48
56
var mesh = st.Commit();
49
57
50
- Code creates a triangle with indices
58
+ The code below creates a triangle without indices.
51
59
52
60
.. tabs ::
53
61
.. code-tab :: gdscript GDScript
@@ -97,14 +105,37 @@ Code creates a triangle with indices
97
105
var mesh = st.Commit();
98
106
99
107
You can optionally add an index array, either by calling ``add_index() `` and adding
100
- vertices to the index array or by calling ``index() `` which shrinks the vertex array
101
- to remove duplicate vertices.
108
+ vertices to the index array manually, or by calling ``index() `` once,
109
+ which generates the index array automatically and
110
+ shrinks the vertex array to remove duplicate vertices.
102
111
103
112
.. tabs ::
104
113
.. code-tab :: gdscript GDScript
114
+ # Suppose we have a quad defined by 6 vertices as follows
115
+ st.add_vertex(Vector3(-1, 1, 0))
116
+ st.add_vertex(Vector3(1, 1, 0))
117
+ st.add_vertex(Vector3(-1, -1, 0))
118
+
119
+ st.add_vertex(Vector3(1, 1, 0))
120
+ st.add_vertex(Vector3(1, -1, 0))
121
+ st.add_vertex(Vector3(-1, -1, 0))
122
+
123
+ # We can make the quad more efficient by using an index array and only utilizing 4 vertices
124
+
125
+ # Suppose we have a quad defined by 6 vertices as follows
126
+ st.add_vertex(Vector3(-1, 1, 0))
127
+ st.add_vertex(Vector3(1, 1, 0))
128
+ st.add_vertex(Vector3(-1, -1, 0))
129
+
130
+ st.add_vertex(Vector3(1, 1, 0))
131
+ st.add_vertex(Vector3(1, -1, 0))
132
+ st.add_vertex(Vector3(-1, -1, 0))
133
+
134
+ # We can make the quad more efficient by using an index array and only utilizing 4 vertices
105
135
106
136
# Creates a quad from four corner vertices.
107
- # add_index does not need to be called before add_vertex.
137
+ # add_index() can be called before or after add_vertex()
138
+ # since it's not an attribute of a vertex itself.
108
139
st.add_index(0)
109
140
st.add_index(1)
110
141
st.add_index(2)
@@ -113,7 +144,7 @@ to remove duplicate vertices.
113
144
st.add_index(3)
114
145
st.add_index(2)
115
146
116
- # Alternatively:
147
+ # Alternatively we can use `` st.index() `` which will create the quad for us and remove the duplicate vertices
117
148
st.index()
118
149
119
150
.. code-tab :: csharp
@@ -161,12 +192,15 @@ normals set already.
161
192
st.generate_normals()
162
193
st.generate_tangents()
163
194
195
+ st.commit(mesh)
196
+
164
197
.. code-tab :: csharp
165
198
166
199
st.GenerateNormals();
167
200
st.GenerateTangents();
168
201
169
- By default, when generating normals, they will be calculated on a per-face basis. If you want
170
- smooth vertex normals, when adding vertices, call ``add_smooth_group() ``. ``add_smooth_group() ``
171
- needs to be called while building the geometry, e.g. before the call to ``add_vertex() ``
172
- (if non-indexed) or ``add_index() `` (if indexed).
202
+ By default, when generating normals, they will be calculated on a per-vertex basis (i.e. they will
203
+ be "smooth normals"). If you want flat vertex normals (i.e. a single normal vector per face), when
204
+ adding vertices, call ``add_smooth_group(i) `` where ``i `` is a unique number per vertex.
205
+ ``add_smooth_group() `` needs to be called while building the geometry, e.g. before the call to
206
+ ``add_vertex() ``.
0 commit comments