extern private void SetIndicesNativeArrayImpl(int submesh, MeshTopology topology, UnityEngine.Rendering.IndexFormat indicesFormat, IntPtr indices, int arrayStart, int arraySize, bool calculateBounds, int baseVertex);
// Display routine for 2d examples in the main program void display2() { // to push and pop location and angle Stack <float> positions = new Stack <float>(); Stack <float> angles = new Stack <float>(); // current angle and position float angle = 0f; float3 position = new float3(0, 0, 0); float posy = 0.0f; float posx = 0.0f; // positions to draw towards float3 newPosition; float2 rotated; // start at 0,0,0 // Apply the drawing rules to the string given to us for (int i = 0; i < lang.Count; i++) { byte buff = lang[i]; switch (buff) { case 0: // draw a line ending in a leaf posy += initial_length; newPosition = new float3(position.x, posy, 0); rotated = rotate(position, new float3(position.x, posy, 0), angle); newPosition = new float3(rotated.x, rotated.y, 0); addLineToMesh(lineMesh, position, new float3(rotated.x, rotated.y, 0), Color.green); //drawLSystemLine(position, new Vector3(rotated.x, rotated.y, 0), line, Color.red); // set up for the next draw position = newPosition; posx = newPosition.x; posy = newPosition.y; addCircleToMesh(lineMesh, 0.45f, 0.45f, position, Color.magenta); break; case 1: // draw a line posy += initial_length; newPosition = new float3(position.x, posy, 0); rotated = rotate(position, new float3(position.x, posy, 0), angle); newPosition = new float3(rotated.x, rotated.y, 0); //drawLSystemLine(position, newPosition, line, Color.green); addLineToMesh(lineMesh, position, newPosition, Color.green); // set up for the next draw position = newPosition; posx = newPosition.x; posy = newPosition.y; break; case 6: //[: push position and angle, turn left 45 degrees positions.Push(posy); positions.Push(posx); float currentAngle = angle; angles.Push(currentAngle); angle -= 45; break; case 9: //]: pop position and angle, turn right 45 degrees posx = positions.Pop(); posy = positions.Pop(); position = new float3(posx, posy, 0); angle = angles.Pop(); angle += 45; break; default: break; } // after we recreate the mesh we need to assign it to the original object MeshUpdateFlags flags = MeshUpdateFlags.DontNotifyMeshUsers & MeshUpdateFlags.DontRecalculateBounds & MeshUpdateFlags.DontResetBoneBounds & MeshUpdateFlags.DontValidateIndices; // set vertices var layout = new[] { new VertexAttributeDescriptor(VertexAttribute.Position, VertexAttributeFormat.Float32, 3), new VertexAttributeDescriptor(VertexAttribute.Color, VertexAttributeFormat.UNorm8, 4) }; lineMesh.SetVertexBufferParams(vertices.Count, layout); lineMesh.SetVertexBufferData(vertices, 0, 0, vertices.Count, 0, flags); // set indices UnityEngine.Rendering.IndexFormat format = IndexFormat.UInt32; lineMesh.SetIndexBufferParams(indices.Count, format); lineMesh.SetIndexBufferData(indices, 0, 0, indices.Count, flags); // set submesh SubMeshDescriptor desc = new SubMeshDescriptor(0, indices.Count, MeshTopology.Lines); desc.bounds = new Bounds(); desc.baseVertex = 0; desc.firstVertex = 0; desc.vertexCount = vertices.Count; lineMesh.SetSubMesh(0, desc, flags); } }
extern public void SetIndexBufferParams(int indexCount, UnityEngine.Rendering.IndexFormat format);
private void SetTrianglesImpl(int submesh, UnityEngine.Rendering.IndexFormat indicesFormat, System.Array triangles, int trianglesArrayLength, int start, int length, bool calculateBounds, int baseVertex) { CheckIndicesArrayRange(triangles, trianglesArrayLength, start, length); SetIndicesImpl(submesh, MeshTopology.Triangles, indicesFormat, triangles, start, length, calculateBounds, baseVertex); }