private void Init(float size, float radius, float detail) { if (material == null) { material = SgtHelper.CreateTempMaterial(SgtHelper.ShaderNamePrefix + "Lightning"); } if (meshFilter == null) { meshFilter = gameObject.AddComponent <MeshFilter>(); } if (meshRenderer == null) { meshRenderer = gameObject.AddComponent <MeshRenderer>(); } SgtProceduralMesh.Clear(); { mesh = SgtObjectPool <Mesh> .Add(mesh); AddVertices(size, radius, detail); AddIndices(); mesh = SgtProceduralMesh.SplitSingle(HideFlags.DontSave); mesh.RecalculateBounds(); meshFilter.sharedMesh = mesh; meshRenderer.sharedMaterial = material; } SgtProceduralMesh.Discard(); }
protected virtual void OnDestroy() { if (Meshes != null) { for (var i = Meshes.Count - 1; i >= 0; i--) { var mesh = Meshes[i]; if (mesh != null) { mesh.Clear(false); SgtObjectPool <Mesh> .Add(Meshes[i]); } } } if (Models != null) { for (var i = Models.Count - 1; i >= 0; i--) { SgtAuroraModel.MarkForDestruction(Models[i]); } } SgtHelper.Destroy(Material); }
protected virtual void OnDestroy() { if (generatedMesh != null) { generatedMesh.Clear(false); SgtObjectPool <Mesh> .Add(generatedMesh); } }
public void PoolMeshNow() { if (mesh != null) { mesh.Clear(false); mesh = SgtObjectPool <Mesh> .Add(mesh); } }
public static void Discard(bool warning = true) { if (meshes.Count > 0) { if (warning == true) { Debug.LogWarning("SgtProceduralMesh generated too many meshes!"); } SgtObjectPool <Mesh> .Add(meshes); } }
public static void Clear() { SgtObjectPool <Mesh> .Add(meshes, m => m.Clear()); positions.Clear(); colors.Clear(); color32s.Clear(); coords1.Clear(); coords2.Clear(); normals.Clear(); tangents.Clear(); }
public void PoolColliderMeshNow(bool destroyCollider = true) { if (colliderMesh != null) { if (destroyCollider == true && meshCollider != null) { meshCollider = SgtHelper.Destroy(meshCollider); } colliderMesh.Clear(false); colliderMesh = SgtObjectPool <Mesh> .Add(colliderMesh); } }
public void PoolMeshNow() { if (mesh != null) { if (meshFilter == null) { meshFilter = gameObject.GetComponent <MeshFilter>(); } mesh.Clear(false); mesh = meshFilter.sharedMesh = SgtObjectPool <Mesh> .Add(mesh); } }
private void Pool() { if (meshCollider != null) { SgtHelper.Destroy(meshCollider.gameObject); meshCollider = null; } if (mesh != null) { mesh.Clear(false); mesh = SgtObjectPool <Mesh> .Add(mesh); } }
protected virtual void OnDestroy() { if (Planes != null) { for (var i = Planes.Count - 1; i >= 0; i--) { SgtProminencePlane.MarkForDestruction(Planes[i]); } } if (Mesh != null) { Mesh.Clear(false); SgtObjectPool <Mesh> .Add(Mesh); } SgtHelper.Destroy(Material); }
protected virtual void RegenerateMesh() { mesh = SgtObjectPool <Mesh> .Add(mesh, m => m.Clear()); SgtProceduralMesh.Clear(); { if (SegmentDetail >= 3) { var angleTotal = SgtHelper.Divide(Mathf.PI * 2.0f, SegmentCount); var angleStep = SgtHelper.Divide(angleTotal, SegmentDetail); var coordStep = SgtHelper.Reciprocal(SegmentDetail); for (var i = 0; i <= SegmentDetail; i++) { var coord = coordStep * i; var angle = angleStep * i; var sin = Mathf.Sin(angle); var cos = Mathf.Cos(angle); SgtProceduralMesh.PushPosition(sin * InnerRadius, 0.0f, cos * InnerRadius); SgtProceduralMesh.PushPosition(sin * OuterRadius, 0.0f, cos * OuterRadius); SgtProceduralMesh.PushNormal(Vector3.up); SgtProceduralMesh.PushNormal(Vector3.up); SgtProceduralMesh.PushCoord1(0.0f, coord); SgtProceduralMesh.PushCoord1(1.0f, coord); } } } SgtProceduralMesh.SplitStrip(HideFlags.DontSave); mesh = SgtProceduralMesh.Pop(); SgtProceduralMesh.Discard(); if (mesh != null) { var bounds = mesh.bounds; mesh.bounds = SgtHelper.NewBoundsCenter(bounds, bounds.center + bounds.center.normalized * BoundsShift); } }
protected override void RegenerateMesh() { mesh = SgtObjectPool <Mesh> .Add(mesh, m => m.Clear()); SgtProceduralMesh.Clear(); { if (SegmentDetail >= 3) { var angleTotal = SgtHelper.Divide(Mathf.PI * 2.0f, SegmentCount); var angleStep = SgtHelper.Divide(angleTotal, SegmentDetail); var coordStep = SgtHelper.Reciprocal(SegmentDetail); for (var i = 0; i <= SegmentDetail; i++) { var coord = coordStep * i; var angle = angleStep * i; var sin = Mathf.Sin(angle); var cos = Mathf.Cos(angle); var iPos = new Vector3(sin * InnerRadius, 0.0f, cos * InnerRadius); var oPos = new Vector3(sin * OuterRadius, 0.0f, cos * OuterRadius); SgtProceduralMesh.PushPosition(iPos); SgtProceduralMesh.PushPosition(oPos); SgtProceduralMesh.PushNormal(Vector3.up); SgtProceduralMesh.PushNormal(Vector3.up); SgtProceduralMesh.PushCoord1(0.0f, coord * InnerRadius); SgtProceduralMesh.PushCoord1(1.0f, coord * OuterRadius); SgtProceduralMesh.PushCoord2(InnerRadius, 0.0f); SgtProceduralMesh.PushCoord2(OuterRadius, 0.0f); } } } SgtProceduralMesh.SplitStrip(HideFlags.DontSave); mesh = SgtProceduralMesh.Pop(); SgtProceduralMesh.Discard(); }
public void PoolMeshNow() { Mesh = SgtObjectPool <Mesh> .Add(Mesh, m => m.Clear()); }
public void UpdateMeshesAndModels() { updateMeshesAndModelsCalled = true; if (Meshes == null) { Meshes = new List <Mesh>(); } if (Models == null) { Models = new List <SgtAuroraModel>(); } if (PathDetail > 0 && PathLengthMin > 0.0f && PathLengthMax > 0.0f) { var meshCount = 1; var mesh = GetMesh(0); var vertexCount = 0; SgtHelper.BeginRandomSeed(Seed); { for (var i = 0; i < PathCount; i++) { AddPath(ref mesh, ref meshCount, ref vertexCount); } } SgtHelper.EndRandomSeed(); BakeMesh(mesh); for (var i = Meshes.Count - 1; i >= meshCount; i--) { var extraMesh = Meshes[i]; if (extraMesh != null) { extraMesh.Clear(false); SgtObjectPool <Mesh> .Add(extraMesh); } Meshes.RemoveAt(i); } } for (var i = 0; i < Meshes.Count; i++) { var model = GetOrAddModel(i); model.SetMesh(Meshes[i]); } // Remove any excess if (Models != null) { var min = Mathf.Max(0, Meshes.Count); for (var i = Models.Count - 1; i >= min; i--) { SgtAuroraModel.Pool(Models[i]); Models.RemoveAt(i); } } }