Exemple #1
0
        protected static ColliderSliceResult PrepareSliceCollider(Vector3 locPos, Collider collider, Mesh mesh, Plane plane)
        {
            var                 result        = new ColliderSliceResult();
            IBzSliceAdapter     adapter       = new BzSliceColliderAdapter(mesh.vertices, collider.gameObject);
            BzMeshDataDissector meshDissector = new BzMeshDataDissector(mesh, plane, null, adapter, null);

            result.SliceResult      = SliceResult.Sliced;
            result.OriginalCollider = collider;
            result.meshDissector    = meshDissector;

            return(result);
        }
Exemple #2
0
        private ColliderSliceResult TrySliceCollider(Vector3 locPos, Collider collider, Mesh mesh, Plane plane)
        {
            IBzSliceAddapter    adapter       = new BzSliceColliderAddapter(mesh.vertices, collider.gameObject);
            BzMeshDataDissector meshDissector = new BzMeshDataDissector(mesh, plane, null, adapter, null);

            ColliderSliceResult result = new ColliderSliceResult();

            result.OriginalCollider = collider;
            result.MeshDissector    = meshDissector;
            result.SliceResult      = meshDissector.Slice();

            return(result);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public bool Slice(Plane plane)
        {
            if (SectionViewMaterial == null)
            {
                throw new InvalidOperationException("SectionViewMaterial == null");
            }

            if (!CheckBounds(plane))                    // AABB check for optimisation
            {
                return(false);
            }

            var colliders = SliceColliders(plane);

            if (colliders == null)
            {
                return(false);
            }

            var        renderer   = GetComponent <MeshRenderer>();
            MeshFilter meshFilter = GetComponent <MeshFilter>();
            var        mesh       = meshFilter.sharedMesh;

            IBzSliceAddapter    adapter       = new BzSliceMeshFilterAddapter(mesh.vertices, gameObject);
            BzMeshDataDissector meshDissector = new BzMeshDataDissector(mesh, plane, renderer.sharedMaterials, adapter, null);

            meshDissector.DefaultSliceMaterial = SectionViewMaterial;

            if (meshDissector.Slice() != SliceResult.Sliced)
            {
                return(false);
            }

            // duplicate object
            var duplicate = Instantiate(this.gameObject, this.gameObject.transform.parent);

            ReplaceColliders(colliders, duplicate);

            var duplRenderer = duplicate.GetComponent <MeshRenderer>();

            meshDissector.RebuildNegMesh(renderer);
            meshDissector.RebuildPosMesh(duplRenderer);

            InvokeEvents(this.gameObject, duplicate);

            OutObjectsNegative = new GameObject[] { this.gameObject };
            OutObjectsPositive = new GameObject[] { duplicate };

            return(true);
        }
Exemple #5
0
        /// <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);
            }
        }