Esempio n. 1
0
 protected override void OnDraw(LineCanvas canvas)
 {
     if (isError)
     {
         canvas.SetStyle("error");
     }
     else
     {
         canvas.SetStyle("entities");
     }
     ForEachSegment((a, b) => {
         canvas.DrawLine(a, b);
     });
 }
Esempio n. 2
0
    public override void UpdateDirty()
    {
        if (!dirty)
        {
            return;
        }

        if (sourceChanged)
        {
            if (Solve() != EquationSystem.SolveResult.OKAY)
            {
                Debug.LogError("Solve Failed!!!!!!");
            }
        }
        canvas.Clear();
        base.UpdateDirty();
        go.transform.SetMatrix(transform);

        canvas.SetStyle("entities");
        foreach (var e in sketch.entityList)
        {
            if (!e.isVisible)
            {
                continue;
            }
            e.Draw(canvas);
        }

        sketch.MarkUnchanged();
        canvas.UpdateDirty();
    }
Esempio n. 3
0
 protected override void OnDraw(LineCanvas canvas)
 {
     canvas.SetStyle("entities");
     ForEachSegment((a, b) => {
         canvas.DrawLine(a, b);
     });
 }
Esempio n. 4
0
 public void DrawConstraints(LineCanvas canvas)
 {
     canvas.ClearStyle("constraints");
     canvas.SetStyle("constraints");
     foreach (var c in sketch.constraintList)
     {
         c.Draw(canvas);
     }
 }
Esempio n. 5
0
    protected override void OnUpdateDirty()
    {
        GameObject.Destroy(go);
        go     = new GameObject("ImportMeshFeature");
        canvas = GameObject.Instantiate(EntityConfig.instance.lineCanvas, go.transform);
        canvas.SetStyle("entities");
        //foreach(var edge in edges) {
        //			canvas.DrawLine(edge.a, edge.b);
        //}
        //meshCheck.drawErrors(canvas);

        /*
         *
         * var vertices = mesh.vertices;
         * var triangles = mesh.GetTriangles(0);
         * var edges = new HashSet<KeyValuePair<Vector3, Vector3>>();
         * var antiEdges = new HashSet<KeyValuePair<Vector3, Vector3>>();
         * var tris = new Dictionary<KeyValuePair<Vector3, Vector3>, int>();
         * for(int i = 0; i < triangles.Length / 3; i++) {
         *      for(int j = 0; j < 3; j++) {
         *              var edge = new KeyValuePair<Vector3, Vector3>(
         *                      Snap(vertices[triangles[i * 3 + j]], vertices),
         *                      Snap(vertices[triangles[i * 3 + (j + 1) % 3]], vertices)
         *              );
         *              if(edge.Key == edge.Value) continue;
         *              tris[edge] =  i * 3 + j;
         *              if(edges.Contains(edge)) continue;
         *              if(antiEdges.Contains(edge)) continue;
         *              var antiEdge = new KeyValuePair<Vector3, Vector3>(edge.Value, edge.Key);
         *              edges.Add(edge);
         *              antiEdges.Add(antiEdge);
         *      }
         * }
         *
         * foreach(var edge in edges) {
         *      var anti = new KeyValuePair<Vector3, Vector3>(edge.Value, edge.Key);
         *      if(tris.ContainsKey(edge) && tris.ContainsKey(anti)) {
         *              var tri0 = tris[edge];
         *              var edg0 = tri0 % 3;
         *              tri0 -= edg0;
         *              var n0 = CalculateNormal(tri0, edg0, vertices, triangles);
         *
         *              var tri1 = tris[anti];
         *              var edg1 = tri1 % 3;
         *              tri1 -= edg1;
         *              var n1 = CalculateNormal(tri1, edg1, vertices, triangles);
         *
         *              if((n0 - n1).magnitude < 1e-4) continue;
         *      } else continue;
         *      canvas.DrawLine(edge.Key, edge.Value);
         * }
         */
        go.SetActive(visible);
    }
Esempio n. 6
0
 public void DrawConstraints(LineCanvas canvas)
 {
     canvas.ClearStyle("constraints");
     canvas.SetStyle("constraints");
     foreach (var c in sketch.constraintList)
     {
         if (!c.isVisible)
         {
             continue;
         }
         c.Draw(canvas);
     }
 }
Esempio n. 7
0
    public void drawErrors(LineCanvas renderer)
    {
        int i = 0;

        int num_errors = 0;

        foreach (Edge e in edges.Values)
        {
            if (e.triangles.Count == 2)
            {
                continue;
            }
            i++;
            num_errors++;
            //switch(e.triangles.size()) {
            switch (e.triangles.Count)
            {
            case 1:
                renderer.SetStyle("error");
                break;

            case 2: {
                renderer.SetStyle("entities");
                break;
            }

            default:
                renderer.SetStyle("hovered");
                break;
            }
            renderer.DrawLine(e.a.pos, e.b.pos);
        }
        if (num_errors != 0)
        {
            //Debug.Log("Achtung!!! STL check num_errors = %d\n", num_errors);
        }
    }
Esempio n. 8
0
    void DrawCadObject(ICADObject obj, string style)
    {
        var he = obj as IEntity;

        canvas.SetStyle((he != null && he.type == IEntityType.Point) ? style + "Points" : style);
        if (he != null)
        {
            canvas.DrawSegments((obj as IEntity).SegmentsInPlane(null));
        }
        else
        if (obj is SketchObject)
        {
            (obj as SketchObject).Draw(canvas);
        }
    }
Esempio n. 9
0
    void DrawCadObject(ICADObject obj, string style)
    {
        var sko = obj as SketchObject;

        if (sko != null && !sko.isVisible)
        {
            return;
        }
        var he = obj as IEntity;

        canvas.SetStyle((he != null && he.type == IEntityType.Point) ? style + "Points" : style);
        if (he != null)
        {
            canvas.DrawSegments((obj as IEntity).SegmentsInPlane(null));
        }
        else
        if (sko != null)
        {
            sko.Draw(canvas);
        }
    }
Esempio n. 10
0
 protected override void OnUpdateDirty()
 {
     if (edges == null)
     {
         if (canvas == null)
         {
             go     = new GameObject("MeshImportFeature");
             canvas = GameObject.Instantiate(EntityConfig.instance.lineCanvas, go.transform);
         }
         else
         {
             canvas.Clear();
         }
         canvas.SetStyle("entities");
         if (useThreshold)
         {
             edges = meshCheck.GenerateEdges(thresholdAngle);
         }
         else
         {
             edges = new List <Pair <Vector3, Vector3> >();
             var indices  = mesh.GetIndices(0);
             var vertices = mesh.vertices;
             for (int i = 0; i < indices.Length / 3; i++)
             {
                 for (int j = 0; j < 3; j++)
                 {
                     edges.Add(new Pair <Vector3, Vector3>(vertices[indices[i * 3 + j]], vertices[indices[i * 3 + (j + 1) % 3]]));
                 }
             }
         }
         foreach (var edge in edges)
         {
             canvas.DrawLine(edge.a, edge.b);
         }
         meshCheck.drawErrors(canvas);
     }
     go.transform.SetMatrix(basis.matrix);
     go.SetActive(visible);
 }
Esempio n. 11
0
 protected override void OnUpdateDirty()
 {
     if (edges == null)
     {
         if (canvas == null)
         {
             go     = new GameObject("MeshImportFeature");
             canvas = GameObject.Instantiate(EntityConfig.instance.lineCanvas, go.transform);
         }
         else
         {
             canvas.Clear();
         }
         canvas.SetStyle("entities");
         edges = meshCheck.GenerateEdges(thresholdAngle);
         foreach (var edge in edges)
         {
             canvas.DrawLine(edge.a, edge.b);
         }
         meshCheck.drawErrors(canvas);
     }
     go.transform.SetMatrix(basis.matrix);
     go.SetActive(visible);
 }
Esempio n. 12
0
    private void Update()
    {
        if (activeFeature != null)
        {
            if (currentSketch != null && currentSketch.IsTopologyChanged())
            {
                UpdateSystem();
            }
            var    res    = sys.Solve();
            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 += sys.stats;
            resultText.text = result.ToString();
        }

        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;
                            }
                            combinedCount++;
                        }
                        result = mf.combined;
                    }
                }
                if (f == activeFeature)
                {
                    break;
                }
            }
            Debug.Log("combined " + combinedCount + " meshes");
            solid = result;
            if (result != null)
            {
                mesh.FromSolid(result);
            }
        }

        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");
        if (hovered != null)
        {
            canvas.SetStyle("hovered");
            if (hovered is IEntity)
            {
                canvas.DrawSegments((hovered as IEntity).SegmentsInPlane(null));
            }
            else
            if (hovered is SketchObject)
            {
                (hovered as SketchObject).Draw(canvas);
            }
        }

        if (activeFeature is SketchFeatureBase)
        {
            var sk = activeFeature as SketchFeatureBase;
            if (sk.ShouldRedrawConstraints() || justSwitchedToSketch)
            {
                sk.DrawConstraints(canvas);
            }
        }
        else
        {
            canvas.ClearStyle("constraints");
        }
    }
Esempio n. 13
0
 protected override void OnDraw(LineCanvas canvas)
 {
     canvas.SetStyle("points");
     canvas.DrawPoint(pos);
 }