protected override void GenerateMesh() { if( _loft == null ) _loft = new Loft(Path, Shape); var meshFilter = GetComponent<MeshFilter>(); if( meshFilter.sharedMesh ) DestroyImmediate(meshFilter.sharedMesh); meshFilter.sharedMesh = _loft.GenerateMesh((uint)pathSegments, (uint)shapeSegments); }
protected override void GenerateMesh() { if (_loft == null) { _loft = new Loft(Path, Shape); } var meshFilter = GetComponent <MeshFilter>(); if (meshFilter.sharedMesh) { DestroyImmediate(meshFilter.sharedMesh); } meshFilter.sharedMesh = _loft.GenerateMesh((uint)pathSegments, (uint)shapeSegments); }
protected override void GenerateMesh() { foreach (Transform child in transform) { DestroyImmediate(child.gameObject); } var rand = new MersenneTwister(randomSeed); var totalHeight = 0.0f; var scaleDown = 1.0f; var combineMeshInstances = new List <CombineInstance>(); for (int i = 0; i < layerCount; ++i) { var baseRadius = Mathf.Lerp(baseRadiusMin, baseRadiusMax, rand.NextSinglePositive()) * scaleDown; var baseBezier = GenerateBaseBezier(baseRadius * scaleDown, rand); var previousTotalHeight = totalHeight; totalHeight += Mathf.Lerp(layerHeightMin, layerHeightMax, rand.NextSinglePositive()) * scaleDown; var heightBezier = Bezier.ConstructSmoothSpline( new Vector3[] { Vector3.up *previousTotalHeight, Vector3.up *totalHeight } ); var heightSegs = (uint)heightSegments; var pathSegs = (uint)(radiusSegments * scaleDown); if (heightSegs > 0 && pathSegs > 2) { var combineMeshInstance = new CombineInstance(); combineMeshInstance.mesh = Loft.GenerateMesh( heightBezier, baseBezier, heightSegs, pathSegs ); combineMeshInstances.Add(combineMeshInstance); var topCap = new CombineInstance(); topCap.mesh = baseBezier.Triangulate(pathSegs, Vector3.up * totalHeight); combineMeshInstances.Add(topCap); } scaleDown *= Mathf.Lerp(scaleDownMin, scaleDownMax, rand.NextSinglePositive()); } var meshFilter = GetComponent <MeshFilter>(); if (meshFilter.sharedMesh) { DestroyImmediate(meshFilter.sharedMesh); } meshFilter.sharedMesh = new Mesh(); meshFilter.sharedMesh.CombineMeshes(combineMeshInstances.ToArray(), true, false); foreach (var combineInstance in combineMeshInstances) { DestroyImmediate(combineInstance.mesh); } }