private static BzMeshSliceResult GetItemResult(SliceTryItem sliceTryItem, Renderer rendererNeg, Renderer rendererPos) { BzMeshSliceResult itemResult = new BzMeshSliceResult(); itemResult.rendererNeg = rendererNeg; itemResult.rendererPos = rendererPos; var sliceEdgeNegResult = new BzSliceEdgeResult[sliceTryItem.meshDissector.CapsNeg.Count]; for (int i = 0; i < sliceEdgeNegResult.Length; i++) { var edgeResult = new BzSliceEdgeResult(); sliceEdgeNegResult[i] = edgeResult; edgeResult.capsData = sliceTryItem.meshDissector.CapsNeg[i]; } itemResult.sliceEdgesNeg = sliceEdgeNegResult; var sliceEdgePosResult = new BzSliceEdgeResult[sliceTryItem.meshDissector.CapsPos.Count]; for (int i = 0; i < sliceEdgePosResult.Length; i++) { var edgeResult = new BzSliceEdgeResult(); sliceEdgePosResult[i] = edgeResult; edgeResult.capsData = sliceTryItem.meshDissector.CapsPos[i]; } itemResult.sliceEdgesPos = sliceEdgePosResult; return(itemResult); }
/// <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); } }