Esempio n. 1
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            var mpos = Input.mousePosition;
            mpos.z    = 10.0f;
            start_pos = Camera.main.ScreenToWorldPoint(mpos);

            dragging         = true;
            renderer.enabled = true;
        }

        if (dragging)
        {
            var mpos = Input.mousePosition;
            mpos.z  = 10.0f;
            end_pos = Camera.main.ScreenToWorldPoint(mpos);

            renderer.SetPositions(new Vector3[] { start_pos, end_pos });
        }

        if (Input.GetMouseButtonUp(0))
        {
            Create();

            var victims = FindCutVictims();
            victims.ForEach(v => cutter.Cut(plane, v));

            dragging = false;
        }
    }
Esempio n. 2
0
    private void Cut()
    {
        if (cut0)
        {
            Destroy(cut0);
        }
        if (cut1)
        {
            Destroy(cut1);
        }

        PrimitivesPro.MeshUtils.SetGameObjectActive(OriginalObject.gameObject, false);

        try
        {
            ContourData contour;

            // create 2 new objects
            GenerationTimeMS = cutter.Cut(OriginalObject.gameObject, plane, triangulate, false, out cut0, out cut1, out contour);

            success++;

            if (GenerationTimeMS > maxTime)
            {
                maxTime = GenerationTimeMS;
            }

            if (GenerationTimeMS < minTime)
            {
                minTime = GenerationTimeMS;
            }

            sumTime += GenerationTimeMS;
            sumSteps++;
        }
        catch (Exception)
        {
            Debug.Log("Cutter exception!");
            return;
        }

        if (cut0 != null)
        {
            tweenAmount[0]     = plane.Normal * 0.02f;
            tweenAmount[1]     = plane.Normal * -0.02f;
            targetTweenTimeout = 0.5f;
            cutTimeout         = 0.5f;
        }
    }
Esempio n. 3
0
        // Token: 0x060041FE RID: 16894 RVA: 0x0014F924 File Offset: 0x0014DD24
        public void Cut()
        {
            MeshCutter meshCutter = new MeshCutter();

            PrimitivesPro.Utils.Plane plane = this.ComputePlane();
            GameObject  gameObject;
            GameObject  gameObject2;
            ContourData contourData;

            base.GenerationTimeMS = meshCutter.Cut(this.cuttingObject, plane, this.triangulateHoles, this.deleteOriginal, this.crossSection, out gameObject, out gameObject2, out contourData);
            if (gameObject != null)
            {
                gameObject.AddComponent <DefaultObject>();
                gameObject2.AddComponent <DefaultObject>();
            }
        }
Esempio n. 4
0
        public void Cut()
        {
            MeshUtils.Log("Cutting: " + cuttingObject.name);

            var cutter = new MeshCutter();

            // create cutting plane
            var plane = ComputePlane();

            ContourData contour;

            GameObject cut0, cut1;

            GenerationTimeMS = cutter.Cut(cuttingObject, plane, triangulateHoles, deleteOriginal, out cut0, out cut1, out contour);

            if (cut0 != null)
            {
                cut0.AddComponent <DefaultObject>();
                cut1.AddComponent <DefaultObject>();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// run cutting algorithm
        /// </summary>
        public void Cut(GameObject primitive, bool fillHoles, bool deleteOriginal)
        {
            MeshUtils.Log("Cutting: " + primitive.name);

            var cutter = new MeshCutter();

            // create cutting plane
            var plane = ComputePlane();

            ContourData contour;

            GameObject cut0, cut1;

            GenerationTimeMS = cutter.Cut(primitive, plane, fillHoles, deleteOriginal, out cut0, out cut1, out contour);

//            contour.ShowContourDBG(float.MaxValue);
//            contour.CreateGameObject(true);

            if (cut0 != null)
            {
                cut0.AddComponent <DefaultObject>();
                cut1.AddComponent <DefaultObject>();
            }
        }
Esempio n. 6
0
    private void Cut()
    {
        if (cut0)
        {
            Destroy(cut0);
        }
        if (cut1)
        {
            Destroy(cut1);
        }

        PrimitivesPro.MeshUtils.SetGameObjectActive(OriginalObject.gameObject, false);

        // get mesh of the primitive
        var meshToCut = OriginalObject.GetComponent <MeshFilter>().sharedMesh;

        Mesh        mesh0 = null, mesh1 = null;
        ContourData contours;

        try
        {
            // create 2 new objects
            GenerationTimeMS = cutter.Cut(meshToCut, OriginalObject.transform, plane, triangulate, MeshCutter.defaultCrossSection, out mesh0, out mesh1, out contours);

            if (true)
            {
                success++;

                if (GenerationTimeMS > maxTime)
                {
                    maxTime = GenerationTimeMS;
                }

                if (GenerationTimeMS < minTime)
                {
                    minTime = GenerationTimeMS;
                }

//                foreach (var vector3se in contours)
//                {
//                    foreach (var vector3 in vector3se)
//                    {
//                        var pri = PrimitivesPro.GameObjects.Sphere.Create(0.1f, 10, 0, 0, NormalsType.Vertex, PivotPosition.Center);
//                        pri.transform.position = OriginalObject.transform.position;
//                        pri.transform.rotation = OriginalObject.transform.rotation;
//                        pri.transform.localScale = OriginalObject.transform.localScale;
//
//                        pri.transform.Translate(vector3);
//                    }
//                }

                sumTime += GenerationTimeMS;
                sumSteps++;
            }
        }
        catch (Exception ex)
        {
            failed++;

            UnityEngine.Debug.Log("Exception!!! " + ex);
            UnityEngine.Debug.Break();

            return;
        }

        if (mesh0 != null)
        {
            cut0 = new GameObject(OriginalObject.name + "_cut0");
            var meshFilter0 = cut0.AddComponent <MeshFilter>();
            meshFilter0.sharedMesh = mesh0;

            var renderer0 = cut0.AddComponent <MeshRenderer>();
            renderer0.sharedMaterial = new Material(Shader.Find("Diffuse"));

            cut0.transform.position   = OriginalObject.transform.position;
            cut0.transform.rotation   = OriginalObject.transform.rotation;
            cut0.transform.localScale = OriginalObject.transform.localScale;

            cut0.transform.position += plane.Normal * 1f;
        }

        if (mesh1 != null)
        {
            cut1 = new GameObject(OriginalObject.name + "_cut1");
            var meshFilter1 = cut1.AddComponent <MeshFilter>();
            meshFilter1.sharedMesh = mesh1;

            var renderer1 = cut1.AddComponent <MeshRenderer>();
            renderer1.sharedMaterial = new Material(Shader.Find("Diffuse"));

            cut1.transform.position   = OriginalObject.transform.position;
            cut1.transform.rotation   = OriginalObject.transform.rotation;
            cut1.transform.localScale = OriginalObject.transform.localScale;

            cut1.transform.position -= plane.Normal * 1f;
        }
    }
Esempio n. 7
0
    bool ProcessCutter(out long cuttingTime)
    {
        ExploderUtils.Assert(state == State.ProcessCutter || state == State.DryRun, "Wrong state!");

        var stopWatch = new Stopwatch();

        stopWatch.Start();

        bool cutting        = true;
        bool timeBudgetStop = false;
        var  cycleCounter   = 0;

        while (cutting)
        {
            cycleCounter++;

            if (cycleCounter > TargetFragments)
            {
                ExploderUtils.Log("Explode Infinite loop!");
                break;
            }

            var fragmentsCount = meshSet.Count;

            newFragments.Clear();
            meshToRemove.Clear();

            cutting = false;

            foreach (var mesh in meshSet)
            {
                if (levelCount[mesh.level] > 0)
                {
                    // TODO: for possible improvements change random value to something more sofisticated
                    var randomPlaneNormal = Random.insideUnitSphere;

                    var plane = new Exploder.MeshCutter.Math.Plane(randomPlaneNormal, mesh.transform.TransformPoint(mesh.centroid));

                    var triangulateHoles         = true;
                    var crossSectionVertexColour = Color.white;
                    var crossSectionUV           = new Vector4(0, 0, 1, 1);

                    if (mesh.option)
                    {
                        triangulateHoles         = !mesh.option.Plane2D;
                        crossSectionVertexColour = mesh.option.CrossSectionVertexColor;
                        crossSectionUV           = mesh.option.CrossSectionUV;
                        splitMeshIslands        |= mesh.option.SplitMeshIslands;
                    }

#if PHYSICS_2D
                    if (Use2DCollision)
                    {
                        triangulateHoles = false;
                    }
#endif

                    List <CutterMesh> meshes = null;
                    cutter.Cut(mesh.mesh, mesh.transform, plane, triangulateHoles, ref meshes, crossSectionVertexColour, crossSectionUV);

                    cutting = true;

                    if (meshes != null)
                    {
                        foreach (var cutterMesh in meshes)
                        {
                            newFragments.Add(new CutMesh
                            {
                                mesh     = cutterMesh.mesh,
                                centroid = cutterMesh.centroid,

                                material        = mesh.material,
                                vertices        = mesh.vertices,
                                transform       = mesh.transform,
                                distance        = mesh.distance,
                                level           = mesh.level,
                                fragments       = mesh.fragments,
                                original        = mesh.original,
                                skinnedOriginal = mesh.skinnedOriginal,

                                parent     = mesh.transform.parent,
                                position   = mesh.transform.position,
                                rotation   = mesh.transform.rotation,
                                localScale = mesh.transform.localScale,

                                option = mesh.option,
                            });
                        }

                        meshToRemove.Add(mesh);

                        levelCount[mesh.level] -= 1;

                        // stop this madness!
                        if (fragmentsCount + newFragments.Count - meshToRemove.Count >= TargetFragments)
                        {
                            cuttingTime = stopWatch.ElapsedMilliseconds;
                            return(true);
                        }

                        // computation took more than FrameBudget ...
                        if (stopWatch.ElapsedMilliseconds > FrameBudget)
                        {
                            timeBudgetStop = true;
                            break;
                        }
                    }
                }
            }

            meshSet.ExceptWith(meshToRemove);
            meshSet.UnionWith(newFragments);

            if (timeBudgetStop)
            {
                break;
            }
        }

        cuttingTime = stopWatch.ElapsedMilliseconds;

        // explosion is finished
        if (!timeBudgetStop)
        {
            return(true);
        }

        return(false);
    }
Esempio n. 8
0
    // Update is called once per frame
    void Update()
    {
        switch (state)
        {
        case MainState.wait:
            if (SmoothChecker.instance.AvgTime < 0.05f && LoadData.isDone)
            {
                titleFade.Run();
                BeginSE.Play();
                titlerhythm.enabled = false;
                state++;
            }
            break;

        case MainState.titlefade:
            if (titleFade.IsEnd())
            {
                BeginSE.Stop();
                titleFade.enabled = false;
                flickFade.Run();
                titlerhythm.enabled = true;
                taiko.Play();
                state++;
            }
            break;

        case MainState.begin:
            time += Time.unscaledDeltaTime;
#if UNITY_ANDROID
            if (time > 15.0f)
            {
                Handheld.PlayFullScreenMovie("demo.mp4", Color.black, FullScreenMovieControlMode.CancelOnInput, FullScreenMovieScalingMode.AspectFill);
                Application.LoadLevel("NewTitle");
            }
#endif
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                dynamicRenderTexture.Print();
                time = .0f;
                state++;
            }
            break;

        case MainState.printed:
            if (flickManager.IsEndFlick())
            {
                Camera.main.transform.position = stageSelectStarter.NextCamera.transform.position;
                Camera.main.transform.rotation = stageSelectStarter.NextCamera.transform.rotation;

                Vector2 FlickStartPos = flickManager.FlickStartPos;

                FlickStartPos.x /= Screen.width;
                FlickStartPos.y /= Screen.height;


                Vector2 FlickEndPos = flickManager.FlickEndPos;

                FlickEndPos.x /= Screen.width;
                FlickEndPos.y /= Screen.height;

                ConvertStart   = Camera.main.ViewportToWorldPoint(new Vector3(FlickStartPos.x, FlickStartPos.y, 4.0f));
                ConvertEnd     = Camera.main.ViewportToWorldPoint(new Vector3(FlickEndPos.x, FlickEndPos.y, 4.0f));
                ConvertForward = Camera.main.ViewportToWorldPoint(new Vector3(FlickStartPos.x, FlickStartPos.y, 6.0f));


                stageSelectStarter.NextCanvas.worldCamera = Camera.main;
                fullScreenMesh.transform.position         = Camera.main.transform.position + Camera.main.transform.forward * 20.0f;

                fullScreenMesh.CreateMesh();
                fullScreenMesh.SetTexture(dynamicRenderTexture.renderTexture);


                swordEffectAnimation.transform.right    = (ConvertEnd - ConvertStart).normalized;
                swordEffectAnimation.transform.position = (ConvertEnd + ConvertStart) / 2;
                swordEffectAnimation.AnimationStart();

                audioSource.Play();
                state++;
            }

            break;

        case MainState.cut:

            time     += Time.unscaledDeltaTime;
            moveSpeed = MoveCurve.Evaluate(time) * 20.0f;

            WorldCanvas.SetActive(false);


            //Vector2 vec0 = Random .insideUnitCircle;
            //Vector2 vec1 = Random .insideUnitCircle;
            if (!Cuted)
            {
                meshCutter.Cut(ConvertStart, ConvertEnd, (ConvertForward - ConvertStart).normalized, Vector3.forward);
                Cuted = true;
            }

            if (flickManager.IsEndFlick())
            {
                Camera.main.transform.position = stageSelectStarter.NextCamera.transform.position;
                Camera.main.transform.rotation = stageSelectStarter.NextCamera.transform.rotation;

                Vector2 FlickStartPos = flickManager.FlickStartPos;

                FlickStartPos.x /= Screen.width;
                FlickStartPos.y /= Screen.height;


                Vector2 FlickEndPos = flickManager.FlickEndPos;

                FlickEndPos.x /= Screen.width;
                FlickEndPos.y /= Screen.height;

                ConvertStart   = Camera.main.ViewportToWorldPoint(new Vector3(FlickStartPos.x, FlickStartPos.y, 4.0f));
                ConvertEnd     = Camera.main.ViewportToWorldPoint(new Vector3(FlickEndPos.x, FlickEndPos.y, 4.0f));
                ConvertForward = Camera.main.ViewportToWorldPoint(new Vector3(FlickStartPos.x, FlickStartPos.y, 6.0f));

                meshCutter.Cut(ConvertStart, ConvertEnd, (ConvertForward - ConvertStart).normalized, Vector3.forward);

                swordEffectAnimation.transform.right    = (ConvertEnd - ConvertStart).normalized;
                swordEffectAnimation.transform.position = (ConvertEnd + ConvertStart) / 2;
                swordEffectAnimation.AnimationStart();

                audioSource.Play();
            }
            if (time > 1.4f)
            {
                stageSelectStarter.AllEnable();
                stageSelectStarter.NextCanvas.worldCamera = stageSelectStarter.NextCamera;
                state++;
                //LoadData .allowSceneActivation = true;
            }

            break;
        }
    }