Browse Source

Code style fixes in Procedural geometry docs

Rémi Verschelde 6 years ago
parent
commit
aaca561488

+ 1 - 1
getting_started/scripting/gdscript/index.rst

@@ -7,7 +7,7 @@ GDScript
 
    gdscript_basics
    gdscript_advanced
-   gdscript_styleguide
    gdscript_exports
+   gdscript_styleguide
    static_typing
    gdscript_format_string

+ 71 - 69
tutorials/content/procedural_geometry/arraymesh.rst

@@ -86,12 +86,12 @@ by adding each array to ``surface_array`` and then committing to the mesh.
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-	    arr[Mesh.ARRAY_VERTEX] = verts
-	    arr[Mesh.ARRAY_TEX_UV] = uvs
-	    arr[Mesh.ARRAY_NORMAL] = normals
-	    arr[Mesh.ARRAY_INDEX] = indices
+    arr[Mesh.ARRAY_VERTEX] = verts
+    arr[Mesh.ARRAY_TEX_UV] = uvs
+    arr[Mesh.ARRAY_NORMAL] = normals
+    arr[Mesh.ARRAY_INDEX] = indices
 
-	    mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr) # No blendshapes or compression used
+    mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr) # No blendshapes or compression used.
 
 .. note:: In this example, we used ``Mesh.PRIMITIVE_TRIANGLES``, but you can use any primitive type
           available from mesh.
@@ -104,33 +104,33 @@ Put together the full code looks like:
     extends MeshInstance
 
     func _ready():
-	    var arr = []
-	    arr.resize(Mesh.ARRAY_MAX)
+        var arr = []
+        arr.resize(Mesh.ARRAY_MAX)
 
-	    # PoolVectorXXArrays for mesh construction
-	    var verts = PoolVector3Array()
-	    var uvs = PoolVector2Array()
-	    var normals = PoolVector3Array()
-	    var indices = PoolIntArray()
+        # PoolVectorXXArrays for mesh construction.
+        var verts = PoolVector3Array()
+        var uvs = PoolVector2Array()
+        var normals = PoolVector3Array()
+        var indices = PoolIntArray()
 
-      #######################################
-      ## Insert code here to generate mesh ##
-      #######################################
+        #######################################
+        ## Insert code here to generate mesh ##
+        #######################################
 
-	    # Assign arrays to mesh array
-	    arr[Mesh.ARRAY_VERTEX] = verts
-	    arr[Mesh.ARRAY_TEX_UV] = uvs
-	    arr[Mesh.ARRAY_NORMAL] = normals
-	    arr[Mesh.ARRAY_INDEX] = indices
+        # Assign arrays to mesh array.
+        arr[Mesh.ARRAY_VERTEX] = verts
+        arr[Mesh.ARRAY_TEX_UV] = uvs
+        arr[Mesh.ARRAY_NORMAL] = normals
+        arr[Mesh.ARRAY_INDEX] = indices
 
-	    # create mesh surface from mesh array
-	    mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr) # No blendshapes or compression used
+        # Create mesh surface from mesh array.
+        mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr) # No blendshapes or compression used.
 
 
 The code that goes in the middle can be whatever you want. Below we will present some example code that
 could go in the middle.
 
-Generating Geometry
+Generating geometry
 -------------------
 
 Here is sample code for generating a sphere. Although the code is presented in
@@ -152,51 +152,53 @@ that you find online.
 
     func _ready():
 
-      ##Set up the PoolVectorXXArrays
-
-	    # Vertex indices
-	    var thisrow = 0
-	    var prevrow = 0
-	    var point = 0
-
-	    # Loop over rings
-	    for i in range(rings+1):
-		    var v = float(i) / (rings)
-		    var w = sin(PI * v)
-		    var y = cos(PI * v)
-
-		    # Loop over segments in ring
-		    for j in range(radial_segments):
-			    var u = float(j) / (radial_segments)
-			    var x = sin(u * PI * 2.0)
-			    var z = cos(u * PI * 2.0)
-			    var vert = Vector3(x * radius * w, y, z * radius * w)
-			    verts.append(vert)
-			    normals.append(vert.normalized())
-			    uvs.append(Vector2(u, v))
-			    point += 1
-
-			    # Create triangles in ring using indices
-			    if (i>0 and j>0):
-				    indices.append(prevrow + j - 1)
-				    indices.append(prevrow + j)
-				    indices.append(thisrow + j - 1)
-
-				    indices.append(prevrow + j)
-				    indices.append(thisrow + j)
-				    indices.append(thisrow + j - 1)
-		    if (i>0):
-			    indices.append(prevrow + radial_segments - 1)
-			    indices.append(prevrow)
-			    indices.append(thisrow + radial_segments - 1)
-			
-			    indices.append(prevrow)
-			    indices.append(prevrow + radial_segments)
-			    indices.append(thisrow + radial_segments - 1)
-		    prevrow = thisrow
-		    thisrow = point
-
-      ##Commit to the ArrayMesh
+        # Set up the PoolVectorXArrays.
+
+        # Vertex indices.
+        var thisrow = 0
+        var prevrow = 0
+        var point = 0
+
+        # Loop over rings.
+        for i in range(rings + 1):
+            var v = float(i) / rings
+            var w = sin(PI * v)
+            var y = cos(PI * v)
+
+            # Loop over segments in ring.
+            for j in range(radial_segments):
+                var u = float(j) / radial_segments
+                var x = sin(u * PI * 2.0)
+                var z = cos(u * PI * 2.0)
+                var vert = Vector3(x * radius * w, y, z * radius * w)
+                verts.append(vert)
+                normals.append(vert.normalized())
+                uvs.append(Vector2(u, v))
+                point += 1
+
+                # Create triangles in ring using indices.
+                if i > 0 and j > 0:
+                    indices.append(prevrow + j - 1)
+                    indices.append(prevrow + j)
+                    indices.append(thisrow + j - 1)
+
+                    indices.append(prevrow + j)
+                    indices.append(thisrow + j)
+                    indices.append(thisrow + j - 1)
+
+            if i > 0:
+                indices.append(prevrow + radial_segments - 1)
+                indices.append(prevrow)
+                indices.append(thisrow + radial_segments - 1)
+
+                indices.append(prevrow)
+                indices.append(prevrow + radial_segments)
+                indices.append(thisrow + radial_segments - 1)
+
+            prevrow = thisrow
+            thisrow = point
+
+      # Commit to the ArrayMesh.
 
 Combined with the code above, this code will generate a sphere.
 
@@ -212,5 +214,5 @@ class. This is useful when you want to generate a mesh and then use it later wit
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-    # Saves mesh to a .tres file with compression enabled
+    # Saves mesh to a .tres file with compression enabled.
     ResourceSaver.save("res://sphere.tres", mesh, 32)

+ 3 - 3
tutorials/content/procedural_geometry/immediategeometry.rst

@@ -26,7 +26,7 @@ Then you call ``add_vertex()`` to add a vertex with those attributes. For exampl
 .. tabs::
   .. code-tab:: gdscript GDScript
 
-    # Add a vertex with normal and uv
+    # Add a vertex with normal and uv.
     set_normal(Vector3(0, 1, 0))
     set_uv(Vector2(1, 1))
     add_vertex(Vector3(0, 0, 1))
@@ -42,7 +42,7 @@ The example code below draws a single triangle.
 
     extends ImmediateGeometry
 
-    func _process(delta):
+    func _process(_delta):
         # Clean up before drawing.
         clear()
 
@@ -50,7 +50,7 @@ The example code below draws a single triangle.
         begin(Mesh.PRIMITIVE_TRIANGLES)
 
         # Prepare attributes for add_vertex.
-        set_normal( Vector3(0, 0, 1))
+        set_normal(Vector3(0, 0, 1))
         set_uv(Vector2(0, 0))
         # Call last for each vertex, adds the above attributes.
         add_vertex(Vector3(-1, -1, 0))

+ 1 - 1
tutorials/content/procedural_geometry/index.rst

@@ -1,4 +1,4 @@
-Procedural Geometry
+Procedural geometry
 ===================
 
 There are many ways to procedurally generate geometry in Godot. In this tutorial series

+ 49 - 50
tutorials/content/procedural_geometry/meshdatatool.rst

@@ -23,8 +23,8 @@ before re-using the MeshDataTool
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-  var mdt = MeshDataTool.new()
-  mdt.create_from_surface(mesh)
+    var mdt = MeshDataTool.new()
+    mdt.create_from_surface(mesh)
 
 ``create_from_surface()`` uses the vertex arrays from the ArrayMesh to calculate two additional arrays,
 one for edges and one for faces.
@@ -43,10 +43,10 @@ To access information from these arrays you use a function of the form ``get_***
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-  mdt.get_vertex_count() # returns number of vertices in vertex array
-  mdt.get_vertex_faces(0) # returns array of faces that contain vertex[0]
-  mdt.get_face_normal(1) # calculates and returns face normal
-  mdt.get_edge_vertex(10, 1) # returns the second vertex comprsing edge at index 10
+    mdt.get_vertex_count() # Returns number of vertices in vertex array.
+    mdt.get_vertex_faces(0) # Returns array of faces that contain vertex[0].
+    mdt.get_face_normal(1) # Calculates and returns face normal.
+    mdt.get_edge_vertex(10, 1) # Returns the second vertex comprsing edge at index 10.
 
 What you choose to do with these functions is up to you. A common use case is to iterate over all vertices
 and transform them in some way:
@@ -54,10 +54,10 @@ and transform them in some way:
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-  for i in range(get_vertex_count):
-    var vert = mdt.get_vertex(i)
-    vert *= 2.0 # scales the vertex by doubling size
-    mdt.set_vertex(i, vert)
+    for i in range(get_vertex_count):
+        var vert = mdt.get_vertex(i)
+        vert *= 2.0 # Scales the vertex by doubling size.
+        mdt.set_vertex(i, vert)
 
 Finally, ``commit_to_surface()`` adds a new surface to the ArrayMesh. So if you are dynamically
 updating an existing ArrayMesh, first delete the existing surface before adding a new one.
@@ -65,8 +65,8 @@ updating an existing ArrayMesh, first delete the existing surface before adding
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-  mesh.surface_remove(0) # delete the first surface of the mesh
-  mdt.commit_to_surface(mesh)
+    mesh.surface_remove(0) # Deletes the first surface of the mesh.
+    mdt.commit_to_surface(mesh)
 
 Below is a complete example that creates a pulsing blob complete with new normals and vertex colors.
 
@@ -79,41 +79,40 @@ Below is a complete example that creates a pulsing blob complete with new normal
     var mdt = MeshDataTool.new()
 
     func _ready():
-	    sn.period = 0.7
-	
-	    mdt.create_from_surface(mesh, 0)
-	
-	    for i in range(mdt.get_vertex_count()):
-		    var vertex = mdt.get_vertex(i).normalized()
-		    # Push out vertex by noise
-		    vertex = vertex * (sn.get_noise_3dv(vertex)*0.5+0.75)
-		    mdt.set_vertex(i, vertex)
-
-    	# Calculate vertex normals, face-by-face
-	    for i in range(mdt.get_face_count()):
-		    # Get the index in the vertex array
-		    var a = mdt.get_face_vertex(i, 0)
-		    var b = mdt.get_face_vertex(i, 1)
-		    var c = mdt.get_face_vertex(i, 2)
-		    # Get vertex position using vertex index
-		    var ap = mdt.get_vertex(a)
-		    var bp = mdt.get_vertex(b)
-		    var cp = mdt.get_vertex(c)
-		    # Calculate face normal
-		    var n = (bp - cp).cross(ap - bp).normalized()
-		    # Add face normal to current vertex normal
-		    # this will not result in perfect normals, but it will be close
-		    mdt.set_vertex_normal(a, n + mdt.get_vertex_normal(a))
-		    mdt.set_vertex_normal(b, n + mdt.get_vertex_normal(b))
-		    mdt.set_vertex_normal(c, n + mdt.get_vertex_normal(c))
-
-    	# Run through vertices one last time to normalize normals and
-	    # set color to normal
-	    for i in range(mdt.get_vertex_count()):
-		    var v = mdt.get_vertex_normal(i).normalized()
-		    mdt.set_vertex_normal(i, v)
-		    mdt.set_vertex_color(i, Color(v.x, v.y, v.z))
-
-	    mesh.surface_remove(0)
-	    mdt.commit_to_surface(mesh)
-
+        sn.period = 0.7
+
+        mdt.create_from_surface(mesh, 0)
+
+        for i in range(mdt.get_vertex_count()):
+            var vertex = mdt.get_vertex(i).normalized()
+            # Push out vertex by noise.
+            vertex = vertex * (sn.get_noise_3dv(vertex) * 0.5 + 0.75)
+            mdt.set_vertex(i, vertex)
+
+        # Calculate vertex normals, face-by-face.
+        for i in range(mdt.get_face_count()):
+            # Get the index in the vertex array.
+            var a = mdt.get_face_vertex(i, 0)
+            var b = mdt.get_face_vertex(i, 1)
+            var c = mdt.get_face_vertex(i, 2)
+            # Get vertex position using vertex index.
+            var ap = mdt.get_vertex(a)
+            var bp = mdt.get_vertex(b)
+            var cp = mdt.get_vertex(c)
+            # Calculate face normal.
+            var n = (bp - cp).cross(ap - bp).normalized()
+            # Add face normal to current vertex normal.
+            # This will not result in perfect normals, but it will be close.
+            mdt.set_vertex_normal(a, n + mdt.get_vertex_normal(a))
+            mdt.set_vertex_normal(b, n + mdt.get_vertex_normal(b))
+            mdt.set_vertex_normal(c, n + mdt.get_vertex_normal(c))
+
+        # Run through vertices one last time to normalize normals and
+        # set color to normal.
+        for i in range(mdt.get_vertex_count()):
+            var v = mdt.get_vertex_normal(i).normalized()
+            mdt.set_vertex_normal(i, v)
+            mdt.set_vertex_color(i, Color(v.x, v.y, v.z))
+
+        mesh.surface_remove(0)
+        mdt.commit_to_surface(mesh)

+ 19 - 19
tutorials/content/procedural_geometry/surfacetool.rst

@@ -15,11 +15,11 @@ Attributes are added before each vertex is added:
 .. tabs::
  .. code-tab:: gdscript GDScript
     
-    st.add_normal() # overwritten by normal below
-    st.add_normal() # added to next vertex
-    st.add_color() # added to next vertex
-    st.add_vertex() # captures normal and color above
-    st.add_normal() # normal never added to a vertex
+    st.add_normal() # Overwritten by normal below.
+    st.add_normal() # Added to next vertex.
+    st.add_color() # Added to next vertex.
+    st.add_vertex() # Captures normal and color above.
+    st.add_normal() # Normal never added to a vertex.
 
 When finished generating your geometry with the :ref:`SurfaceTool <class_surfacetool>`
 call ``commit()`` to finished generating the mesh. If an :ref:`ArrayMesh <class_ArrayMesh>` is passed
@@ -29,9 +29,9 @@ in, ``commit()`` returns an ArrayMesh.
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-  st.commit(mesh)
-  #or 
-  var mesh = st.commit()
+    st.commit(mesh)
+    # Or: 
+    var mesh = st.commit()
 
 Code creates a triangle with indices
 
@@ -66,18 +66,18 @@ to remove duplicate vertices.
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-  # creates a quad from four corner vertices
-  # add_index does not need to be called before add_vertex
-  st.add_index(0)
-  st.add_index(1)
-  st.add_index(2)
+    # Creates a quad from four corner vertices.
+    # Add_index does not need to be called before add_vertex.
+    st.add_index(0)
+    st.add_index(1)
+    st.add_index(2)
 
-  st.add_index(1)
-  st.add_index(3)
-  st.add_index(2)
+    st.add_index(1)
+    st.add_index(3)
+    st.add_index(2)
 
-  # or alternatively
-  st.index()
+    # Or 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()``.
@@ -85,7 +85,7 @@ you want to use unique normals or colors per face instead of per-vertex), you ca
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-  st.deindex()
+    st.deindex()
 
 If you don't add custom normals yourself, you can add them using ``generate_normals()``. The same goes for tangents.