private void CreateRibbonCircles(float[] radii, float[] thicknesses, int[] radialSubdivisionsArr, float[] tangentAngles) { MeshFilter meshFilter = _ribbonCircleObject.GetComponent <MeshFilter>(); if (meshFilter == null) { meshFilter = _ribbonCircleObject.AddComponent <MeshFilter>(); } MeshRenderer meshRenderer = _ribbonCircleObject.GetComponent <MeshRenderer>(); if (meshRenderer == null) { meshRenderer = _ribbonCircleObject.AddComponent <MeshRenderer>(); } meshRenderer.shadowCastingMode = (_shouldMeshUseShadows ? UnityEngine.Rendering.ShadowCastingMode.TwoSided : UnityEngine.Rendering.ShadowCastingMode.Off); meshRenderer.receiveShadows = _shouldMeshUseShadows; meshRenderer.material = _ribbonCircleMaterial; ShapeCombiner c = new ShapeCombiner(); if (radii.Length != thicknesses.Length || radii.Length != radialSubdivisionsArr.Length) { Debug.LogError("[RibbonCircleCreator] radii/thickness/subdivision arrays must match each other in size."); } for (int i = 0; i < radii.Length; i++) { c.AddShape(new RibbonCircle(radii[i], thicknesses[i], radialSubdivisionsArr[i], tangentAngles[i])); } meshFilter.mesh = c.FinalizeCurrentMesh(); }
IEnumerator Start() { ShapeCombiner c = new ShapeCombiner(65536, shouldOptimize: true, shouldUpload: true, infiniteBounds: false); MeshObjectCreator.CreateObjectsRealtime(c, _mat, transform); Tube tube = new Tube(8); for (int i = 0; i < _ribbonCount; i++) { tube.Clear(); float offset = Random.Range(0, 360); float radius = Random.Range(0.5f, 1.5f); for (int j = 0; j < _segments; j++) { tube.Add(new MeshPoint(new Vector3(j * 0.04f, radius * Mathf.Sin(j * 0.1f + offset), radius * Mathf.Cos(j * 0.1f + offset))), 0.03f); } yield return(null); c.AddShape(tube); } c.FinalizeCurrentMesh(); }