protected static ColliderSliceResult PrepareSliceCollider(Collider collider, Mesh mesh, Plane plane) { var result = new ColliderSliceResult(); IBzSliceAdapter adapter = new BzSliceColliderAdapter(mesh.vertices, collider.gameObject); SliceConfigurationDto conf = BzSliceConfiguration.GetDefault(); BzMeshDataDissector meshDissector = new BzMeshDataDissector(mesh, plane, null, adapter, conf); result.SliceResult = SliceResult.Sliced; result.OriginalCollider = collider; result.meshDissector = meshDissector; return(result); }
/// <summary> /// Start slicing process /// </summary> /// <param name="addData">You can pass any object. You will </param> /// <returns>Returns true if pre-slice conditions was succeeded and task was added to the queue</returns> private void StartSlice(BzSliceTryData sliceTryData, IBzSliceAdapter[] adapters, Action <BzSliceTryResult> callBack) { Renderer[] renderers = GetRenderers(gameObject); SliceTryItem[] items = new SliceTryItem[renderers.Length]; for (int i = 0; i < renderers.Length; i++) { var renderer = renderers[i]; var adapterAndMesh = GetAdapterAndMesh(renderer); if (adapterAndMesh == null) { continue; } Mesh mesh = adapterAndMesh.mesh; IBzSliceAdapter adapter = adapters == null ? adapterAndMesh.adapter : adapters[i]; var configuration = renderer.gameObject.GetComponent <BzSliceConfiguration>(); var confDto = configuration == null?BzSliceConfiguration.GetDefault() : configuration.GetDto(); var meshDissector = new BzMeshDataDissector(mesh, sliceTryData.plane, renderer.sharedMaterials, adapter, confDto); meshDissector.DefaultSliceMaterial = defaultSliceMaterial; SliceTryItem sliceTryItem = new SliceTryItem(); sliceTryItem.meshRenderer = renderer; sliceTryItem.meshDissector = meshDissector; items[i] = sliceTryItem; } SliceTry sliceTry = new SliceTry(); sliceTry.items = items; sliceTry.callBack = callBack; sliceTry.sliceData = sliceTryData; sliceTry.position = transform.position; sliceTry.rotation = transform.rotation; if (asynchronously) { StartWorker(WorkForWorker, sliceTry); _sliceTrys.Enqueue(sliceTry); } else { Work(sliceTry); SliceTryFinished(sliceTry); } }