// Start is called before the first frame update
    void Start()
    {
        disableInspector.enabled = false;

        simulateButton.onClick.AddListener(SimulateButtonClicked);

        inspector.Inspect(settings);
    }
示例#2
0
    public void ActivateFeature(Feature feature)
    {
        bool skipActive = (activeFeature_ == feature);

        if (activeFeature_ != null)
        {
            var ui  = featuresUI.Find(u => u.feature == activeFeature_);
            var btn = ui.GetComponent <Button>();
            var cb  = btn.colors;
            cb.normalColor = Color.white;
            btn.colors     = cb;
            if (!skipActive)
            {
                activeFeature_.active = false;
            }
        }
        activeFeature_ = feature;
        if (activeFeature_ != null)
        {
            var ui  = featuresUI.Find(u => u.feature == activeFeature_);
            var btn = ui.GetComponent <Button>();
            var cb  = btn.colors;
            cb.normalColor = pressedColor;
            btn.colors     = cb;
            if (!skipActive)
            {
                activeFeature_.active = true;
            }
            justSwitchedToSketch = activeFeature_ is SketchFeatureBase;
            inspector.Inspect(activeFeature_);
            UpdateSystem();
        }
        meshDirty = true;
        if (detail != null)
        {
            var visible = true;
            foreach (var f in detail.features)
            {
                f.visible = visible;
                if (f == activeFeature_)
                {
                    visible = false;
                }
            }
        }
    }
示例#3
0
    private void Update()
    {
        if (activeFeature != null)
        {
            if (currentSketch != null && (currentSketch.GetSketch().IsConstraintsChanged() || currentSketch.GetSketch().IsEntitiesChanged()) || sys.IsDirty)
            {
                suppressSolve = false;
            }
            if (currentSketch != null && currentSketch.IsTopologyChanged())
            {
                UpdateSystem();
            }
            var res = (!suppressSolve || sys.HasDragged()) ? sys.Solve() : EquationSystem.SolveResult.DIDNT_CONVEGE;
            if (res == EquationSystem.SolveResult.DIDNT_CONVEGE)
            {
                suppressSolve = true;
            }
            string result = "";
            result += (GC.GetTotalMemory(false) / 1024 / 1024.0).ToString("0.##") + " mb\n";
            result += res.ToString() + "\n";
            if (sys.dofChanged)
            {
                if (res == EquationSystem.SolveResult.OKAY && !sys.HasDragged())
                {
                    int  dof;
                    bool ok = sys.TestRank(out dof);
                    if (!ok)
                    {
                        dofText = "<color=\"#FF3030\">DOF: " + dof + "</color>\n";
                    }
                    else if (dof == 0)
                    {
                        dofText = "<color=\"#30FF30\">DOF: " + dof + "</color>\n";
                    }
                    else
                    {
                        dofText = "<color=\"#FFFFFF\">DOF: " + dof + "</color>\n";
                    }
                }
                else
                {
                    dofText = "<color=\"#303030\">DOF: ?</color>\n";
                }
            }
            result += dofText;
            result += "Undo: " + undoRedo.Count() + "\n";
            result += "UndoSize: " + undoRedo.Size() + "\n";
            //result += sys.stats;
            resultText.text = result.ToString();
        }

        detail.UpdateUntil(activeFeature);
        //detail.Update();
        meshDirty = meshDirty | detail.features.OfType <MeshFeature>().Any(f => f.dirty);
        detail.MarkDirty();
        detail.UpdateDirtyUntil(activeFeature);
        if (meshDirty && !suppressCombine)
        {
            meshDirty = false;
            mesh.Clear();
            Solid result        = null;
            int   combinedCount = 0;
            foreach (var f in detail.features)
            {
                var mf = f as MeshFeature;
                if (mf != null)
                {
                    if (result == null)
                    {
                        result = mf.solid;
                    }
                    else
                    {
                        if (mf.combined == null)
                        {
                            //#if UNITY_WEBGL
                            //if(combinedCount > 0) {
                            //	break;
                            //}
                            //#endif
                            switch (mf.operation)
                            {
                            case CombineOp.Union: mf.combined = Solids.Union(result, mf.solid); break;

                            case CombineOp.Difference: mf.combined = Solids.Difference(result, mf.solid); break;

                            case CombineOp.Intersection: mf.combined = Solids.Intersection(result, mf.solid); break;

                            case CombineOp.Assembly: mf.combined = Solids.Assembly(result, mf.solid); break;
                            }
                            combinedCount++;
                        }
                        result = mf.combined;
                    }
                }
                if (f == activeFeature)
                {
                    break;
                }
            }
            Debug.Log("combined " + combinedCount + " meshes");
            solid = result;
            if (result != null)
            {
                mesh.FromSolid(result);
            }
        }


        if (!CameraController.instance.IsMoving && !suppressHovering)
        {
            double dist = -1.0;
            hovered = detail.HoverUntil(Input.mousePosition, Camera.main, UnityEngine.Matrix4x4.identity, ref dist, activeFeature);

            /*
             * if(hovered == null && solid != null) {
             *      var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             *      var id = solid.Raytrace(ray);
             *      selectedMesh.FromSolid(solid, id);
             * } else {
             *      selectedMesh.Clear();
             * }*/
        }

        canvas.ClearStyle("hovered");
        canvas.ClearStyle("hoveredPoints");
        if (hovered != null)
        {
            DrawCadObject(hovered, "hovered");
        }

        canvas.ClearStyle("selected");
        canvas.ClearStyle("selectedPoints");
        foreach (var idp in selection)
        {
            var obj = detail.GetObjectById(idp);
            if (obj == null)
            {
                continue;
            }
            DrawCadObject(obj, "selected");
        }

        if (selection.Count == 1)
        {
            var obj = detail.GetObjectById(selection[0]);
            inspector.Inspect(obj);
        }
        else
        {
            inspector.Inspect(activeFeature);
        }

        if (activeFeature is SketchFeatureBase)
        {
            var sk = activeFeature as SketchFeatureBase;
            sk.DrawConstraints(canvas);

            //var skk = activeFeature as SketchFeature;
            //if(skk != null) skk.DrawTriangulation(canvas);
        }
        else
        {
            canvas.ClearStyle("constraints");
        }
    }