Esempio n. 1
0
        IEnumerator proceedCut(List <CutData> objectsToCut)
        {
            bool             threadRunning = true;
            List <CutResult> cutResults    = new List <CutResult> ();

            System.Threading.Thread thread = new System.Threading.Thread(new ThreadStart(
                                                                             () =>
            {
                foreach (CutData cutData in objectsToCut)
                {
                    SimpleMesh simpleMesh = cutData.SimpleMesh;
                    CutResult cutResult   = Cutter.Cut(simpleMesh.Triangles, simpleMesh.Vertices, simpleMesh.Normals, simpleMesh.UVs, simpleMesh.CuttingPlane);
                    cutData.CutResult     = cutResult;
                    cutResults.Add(cutResult);
                }

                threadRunning = false;
            }
                                                                             ));

            thread.Start();

            yield return(new WaitWhile(() => threadRunning));

            IsBusy = false;
        }
Esempio n. 2
0
        void proceedCutResult(CutData cutData)
        {
            if (cutData == null || cutData.Parent == null || cutData.Child == null || cutData.CutResult == null)
            {
                return;
            }

            Cuttable parent       = cutData.Parent;
            Cuttable child        = cutData.Child;
            Plane    cuttingPlane = cutData.Plane;
            Vector3  cutDirection = cutData.CutDirection;

            Mesh      mesh          = parent.GetMeshFilter().mesh;
            CutResult cutResult     = cutData.CutResult;
            Mesh      aMesh         = cutResult.CreateMeshA();
            Mesh      bMesh         = cutResult.CreateMeshB();
            Mesh      newParentMesh = aMesh;
            Mesh      newChildMesh  = bMesh;

            if (newParentMesh.vertexCount > 0 && newChildMesh.vertexCount > 0)
            {
                //original object base should stay in place so I switch meshes position in case
                //bMesh is closer to an origin point
                flipMeshesPositionIfNeeded(ref newParentMesh, ref newChildMesh, parent.transform);

                parent.SetNewMesh(newParentMesh);
                child.SetNewMesh(newChildMesh);

                //set mesh and position for child
                child.transform.position   = parent.transform.position;
                child.transform.rotation   = parent.transform.rotation;
                child.transform.localScale = parent.transform.localScale;
                child.GetMeshFilter().mesh = newChildMesh;
                child.gameObject.SetActive(true);
                activatedChildren.Add(child);

                //add torque and force to child object
                Rigidbody rb = child.GetComponent <Rigidbody> ();
                addForceAndTorqueToAChildObject(rb, cutDirection);

                //shoot particles
                if (cutResult.EdgeVertices.Count > 0)
                {
                    Vector3 pos = cutResult.EdgeVertices [0];
                    pos = parent.transform.TransformPoint(pos);
                    particleManager.ShootParticles(pos, cutDirection);
                }
            }
            else
            {
                child.gameObject.SetActive(false);
                deactivatedChildrenPool.Enqueue(child);
            }

            parent.IsBusy = false;
            child.IsBusy  = false;
        }