/// <summary> /// Starts the build flow. /// </summary> /// <param name="mesh"></param> /// <param name="settings"></param> public override void Start(Mesh mesh, GeometryBuilderSettings settings) { _settings = (PyramidGeometryBuilderSettings)settings; _numSides = _settings.NumSides; CalculateBufferLength(_settings.NumSides, out _numVertices, out _numTriangles); _numVertices += 1; }
/// <summary> /// Builds geometry for a circle. /// </summary> public override void Start(Mesh mesh, GeometryBuilderSettings settings) { base.Start(mesh, settings); _settings = (CircleGeometryBuilderSettings)settings; _numSides = Mathf.Max(3, _settings.NumSides); CalculateBufferLength(_numSides, out _numVertices, out _numTriangles); }
/// <summary> /// Starts the contruction flow. /// </summary> /// <param name="mesh"></param> /// <param name="settings"></param> public override void Start( Mesh mesh, GeometryBuilderSettings settings) { _settings = (PlaneGeometryBuilderSettings)settings; _xVerts = Mathf.Max(2, _settings.NumXVerts); _zVerts = Mathf.Max(2, _settings.NumZVerts); _numQuads = (_xVerts - 1) * (_zVerts - 1); _numVertices = _xVerts * _zVerts; _numTriangles = _numQuads * 2; }
/// <summary> /// On start, creates a Unity sphere and pulls off buffers. /// </summary> /// <param name="mesh"></param> /// <param name="settings"></param> public override void Start(Mesh mesh, GeometryBuilderSettings settings) { var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.hideFlags = HideFlags.HideAndDontSave; var sphereMesh = sphere.GetComponent <MeshFilter>().sharedMesh; _vertices = sphereMesh.vertices; _triangles = sphereMesh.triangles; _uvs = sphereMesh.uv; _normals = sphereMesh.normals; if (Application.isPlaying) { Object.Destroy(sphere); } else { Object.DestroyImmediate(sphere); } }
/// <summary> /// Builds mesh. /// </summary> public override void Start(Mesh mesh, GeometryBuilderSettings settings) { _settings = (CylinderGeometryBuilderSettings)settings; _numSides = Mathf.Max(3, _settings.NumSides); // calculate buffer lengths // start with sides int numTotalVerts = 2 * _numSides; int numTotalTriangles = 2 * _numSides; // add endcaps if (_settings.Endcaps) { numTotalVerts += 2 * (_numSides + 1); numTotalTriangles += 2 * _numSides; } _numVertices = numTotalVerts; _numTriangles = numTotalTriangles; _startVertSideCircleTop = 0; _startVertSideCircleBottom = _numSides; _startVertCircleTop = 2 * _numSides; _startVertCircleBottom = _startVertCircleTop + _numSides + 1; _startTriangleCircleTop = _numSides * 6; _startTriangleCircleBottom = _startTriangleCircleBottom + 3 * _numSides; Debug.Log("NumSides : " + _numSides); Debug.Log("NumVerts : " + _numVertices); Debug.Log("NumTris : " + _numTriangles); Debug.Log("StartVertSideCircleTop : " + _startVertSideCircleTop); Debug.Log("StartVertSideCircleBottom : " + _startVertSideCircleBottom); Debug.Log("StartVertCircleTop : " + _startVertCircleTop); Debug.Log("StartVertCircleBottom : " + _startVertCircleBottom); }
/// <summary> /// Builds geometry. /// </summary> /// <param name="mesh"></param> /// <param name="builder"></param> /// <param name="settings"></param> public static void Build( Mesh mesh, IGeometryBuilder builder, GeometryBuilderSettings settings) { if (null == mesh || null == builder || null == settings) { return; } // begin flow builder.Start(mesh, settings); // create buffers int[] triangles = null; Vector3[] vertices = null; Vector2[] uvs = null; Vector2[] uv1s = null; Vector2[] uv2s = null; Vector3[] normals = null; Color[] colors = null; // must always have a layout builder.Layout(out vertices, out triangles); settings.Vertex.Transform(ref vertices, ref triangles); // fill other buffers if (settings.UV.Enabled) { builder.UV(out uvs, settings.UV); settings.UV.Transform(ref uvs); } if (settings.UV1.Enabled) { builder.UV(out uv1s, settings.UV1); settings.UV1.Transform(ref uv1s); } if (settings.UV2.Enabled) { builder.UV(out uv2s, settings.UV2); settings.UV2.Transform(ref uv2s); } if (settings.Color.Enabled) { builder.Colors(out colors); settings.Color.Transform(ref colors); } if (settings.Normals.Enabled) { builder.Normals(out normals); settings.Normals.Transform(ref normals); } // set buffers, layout first mesh.SetLayout(ref vertices, ref triangles); mesh.uv = uvs; mesh.uv2 = uv1s; mesh.uv2 = uv2s; mesh.colors = colors; mesh.normals = normals; }
/// <summary> /// Starts the build flow. /// </summary> /// <param name="mesh"></param> /// <param name="settings"></param> public override void Start(Mesh mesh, GeometryBuilderSettings settings) { _settings = (GeosphereGeometryBuilderSettings)settings; }
/// <summary> /// Starts the build flow. /// </summary> /// <param name="mesh"></param> /// <param name="settings"></param> public virtual void Start(Mesh mesh, GeometryBuilderSettings settings) { _numVertices = _numTriangles = -1; }