//-----------------------------
    private void PlayGraph()
    {
        GComponent obj = _demoObjects["Graph"];

        Shape shape;

        shape = obj.GetChild("pie").asGraph.shape;
        EllipseMesh ellipse = shape.graphics.GetMeshFactory <EllipseMesh>();

        ellipse.startDegree = 30;
        ellipse.endDegreee  = 300;
        shape.graphics.SetMeshDirty();

        shape = obj.GetChild("trapezoid").asGraph.shape;
        PolygonMesh trapezoid = shape.graphics.GetMeshFactory <PolygonMesh>();

        trapezoid.usePercentPositions = true;
        trapezoid.points.Clear();
        trapezoid.points.Add(new Vector2(0f, 1f));
        trapezoid.points.Add(new Vector2(0.3f, 0));
        trapezoid.points.Add(new Vector2(0.7f, 0));
        trapezoid.points.Add(new Vector2(1f, 1f));
        trapezoid.texcoords.Clear();
        trapezoid.texcoords.AddRange(VertexBuffer.NormalizedUV);
        shape.graphics.SetMeshDirty();
        shape.graphics.texture = (NTexture)UIPackage.GetItemAsset("Basics", "change");

        shape = obj.GetChild("line").asGraph.shape;
        LineMesh line = shape.graphics.GetMeshFactory <LineMesh>();

        line.lineWidthCurve = AnimationCurve.Linear(0, 25, 1, 10);
        line.roundEdge      = true;
        line.gradient       = lineGradient;
        line.path.Create(new GPathPoint[] {
            new GPathPoint(new Vector3(0, 120, 0)),
            new GPathPoint(new Vector3(20, 120, 0)),
            new GPathPoint(new Vector3(100, 100, 0)),
            new GPathPoint(new Vector3(180, 30, 0)),
            new GPathPoint(new Vector3(100, 0, 0)),
            new GPathPoint(new Vector3(20, 30, 0)),
            new GPathPoint(new Vector3(100, 100, 0)),
            new GPathPoint(new Vector3(180, 120, 0)),
            new GPathPoint(new Vector3(200, 120, 0)),
        });
        shape.graphics.SetMeshDirty();
        GTween.To(0, 1, 5).SetEase(EaseType.Linear).SetTarget(shape.graphics).OnUpdate((GTweener t) =>
        {
            ((NGraphics)t.target).GetMeshFactory <LineMesh>().fillEnd = t.value.x;
            ((NGraphics)t.target).SetMeshDirty();
        });

        shape = obj.GetChild("line2").asGraph.shape;
        LineMesh line2 = shape.graphics.GetMeshFactory <LineMesh>();

        line2.lineWidth = 3;
        line2.roundEdge = true;
        line2.path.Create(new GPathPoint[] {
            new GPathPoint(new Vector3(0, 120, 0), GPathPoint.CurveType.Straight),
            new GPathPoint(new Vector3(60, 30, 0), GPathPoint.CurveType.Straight),
            new GPathPoint(new Vector3(80, 90, 0), GPathPoint.CurveType.Straight),
            new GPathPoint(new Vector3(140, 30, 0), GPathPoint.CurveType.Straight),
            new GPathPoint(new Vector3(160, 90, 0), GPathPoint.CurveType.Straight),
            new GPathPoint(new Vector3(220, 30, 0), GPathPoint.CurveType.Straight)
        });
        shape.graphics.SetMeshDirty();

        GObject  image = obj.GetChild("line3");
        LineMesh line3 = image.displayObject.graphics.GetMeshFactory <LineMesh>();

        line3.lineWidth = 30;
        line3.roundEdge = false;
        line3.path.Create(new GPathPoint[] {
            new GPathPoint(new Vector3(0, 30, 0), new Vector3(50, -30), new Vector3(150, -50)),
            new GPathPoint(new Vector3(200, 30, 0), new Vector3(300, 130)),
            new GPathPoint(new Vector3(400, 30, 0))
        });
        image.displayObject.graphics.SetMeshDirty();
    }
    private MeshBase GetChoosenMesh(MeshCreator meshCreator)
    {
        float?minArea = meshCreator.splineSimplification != SplineSimplification.Type.None
            ? meshCreator.minAbsoluteSplineArea
            : (float?)null;

        switch (meshCreator.meshType)
        {
        case MeshCreator.MeshType.Triangle:
            return(TriangleMesh.AddTriangle(meshCreator.transform.position, meshCreator.triangleVertex1,
                                            meshCreator.triangleVertex2, meshCreator.triangleVertex3, Space.World, meshCreator.material,
                                            meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Rectangle:
            return(RectangleMesh.AddRectangle(meshCreator.transform.position, meshCreator.boxSize,
                                              meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Circle:
            return(CircleMesh.AddCircle(meshCreator.transform.position, meshCreator.circleRadius,
                                        meshCreator.circleSides, meshCreator.circleUseCircleCollider, meshCreator.material,
                                        meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Quadrangle:
            Vector2[] verts = new Vector2[4] {
                meshCreator.quadrangleVertex1, meshCreator.quadrangleVertex2,
                meshCreator.quadrangleVertex3, meshCreator.quadrangleVertex4
            };
            return(QuadrangleMesh.AddQuadrangle(meshCreator.transform.position, verts, Space.World,
                                                meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Ellipse:
            return(EllipseMesh.AddEllipse(meshCreator.transform.position, meshCreator.ellipseHorizontalRadius,
                                          meshCreator.ellipseVerticalRadius, meshCreator.ellipseSides, meshCreator.material,
                                          meshCreator.attachRigidbody));

        case MeshCreator.MeshType.PointedCircle:
            return(PointedCircleMesh.AddPointedCircle(meshCreator.transform.position, meshCreator.pointedCircleRadius,
                                                      meshCreator.pointedCircleSides, meshCreator.pointedCircleShift, meshCreator.material,
                                                      meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Cake:
            return(CakeMesh.AddCakeMesh(meshCreator.transform.position, meshCreator.cakeRadius, meshCreator.cakeSides,
                                        meshCreator.cakeSidesToFill, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Convex:
            return(ConvexMesh.AddConvexMesh(meshCreator.transform.position,
                                            MeshHelper.ConvertVec2ToVec3(meshCreator.convexPoints),
                                            meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Star:
            return(StarMesh.AddStar(meshCreator.transform.position, meshCreator.starRadiusA, meshCreator.starRadiusB,
                                    meshCreator.starSides, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Gear:
            return(GearMesh.AddGear(meshCreator.transform.position, meshCreator.gearInnerRadius, meshCreator.gearRootRadius,
                                    meshCreator.gearOuterRadius, meshCreator.gearSides, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Line:
            return(LineMesh.AddLine(meshCreator.transform.position, meshCreator.linePoints.ToArray(), meshCreator.lineWidth,
                                    meshCreator.lineUseDoubleCollider, Space.World, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.TriangulatedMesh:
            return(TriangulatedMesh.Add(meshCreator.transform.position, meshCreator.triangulatedPoints.ToArray(),
                                        meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.SplineShape:
            return(SplineShapeMesh.AddSplineShape(meshCreator.transform.position, meshCreator.splinePoints.ToArray(), meshCreator.splineResolution,
                                                  minArea, Space.World, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.SplineCurve:
            return(SplineCurveMesh.AddSplineCurve(meshCreator.transform.position, meshCreator.splineCurvePoints.ToArray(),
                                                  meshCreator.splineResolution, meshCreator.splineCurveWidth, meshCreator.splineCurveUseDoubleCollider, minArea,
                                                  Space.World, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.SplineConvexShape:
            return(ConvexSplineMesh.AddConvexSpline(meshCreator.transform.position, meshCreator.convexSplinePoints.ToArray(),
                                                    meshCreator.splineResolution, minArea, Space.World, meshCreator.material, meshCreator.attachRigidbody));

        default:
            throw new System.ArgumentOutOfRangeException();
        }
    }
Exemple #3
0
        // TODO: somehow we have orphan vertices
        public MeshTemplate()
        {
            vertexData = new VertexDataComponent()
            {
                saveColor = false
            };
            lineData = new LineDataComponent()
            {
                vertexData = vertexData
            };
            polyData = new VertexListHashDataComponent()
            {
                vertexData = vertexData
            };
            polyData.AddObserver(this);
            faceMesh = new FaceMesh()
            {
                vertexData = vertexData
            };
            lineMesh = new LineMesh()
            {
                vertexData = vertexData
            };
            pointMesh = new PointMesh()
            {
                vertexData = vertexData
            };
            var tracker = new PointCollectionTracker <VertexData>(vertexData, x => x.position);

            Register(vertexData, lineData, polyData, faceMesh, lineMesh, pointMesh);
            // setup ui
            // TODO: these all need to be in reversible actions
            var selector = new Selector <VertexData>(new CameraSelectionProvider <VertexData>(tracker),
                                                     x => { x.color = Color.Orange; RecalculateEverything(); },
                                                     x => { x.color = Color.Black; RecalculateEverything(); }
                                                     );

            Register(selector);
            CameraMouseTracker dragMouseTracker = new CameraMouseTracker()
            {
                stepSize = 0.25f
            };

            // TODO: maybe make event handlers so you can do += stuff...
            dragMouseTracker.OnStepDiff = x => { foreach (var s in selector.selected)
                                                 {
                                                     s.position += x;
                                                 }
                                                 RecalculateEverything(); };
            StateSwitcher switcher = new StateSwitcher(this);

            switcher.AddKeyFocus(Trigger.G, dragMouseTracker, () =>
            {
                // translate vertices
                Vector3 selectedSum = Vector3.Zero;
                foreach (var s in selector.selected)
                {
                    selectedSum += s.position;
                }
                dragMouseTracker.worldOrigin = selectedSum / selector.selected.Count;
                dragMouseTracker.mouseOrigin = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
                dragMouseTracker.oldOffset   = null;
            }, true);
            switcher.AddKeyFocus(Trigger.E, dragMouseTracker, () =>
            {
                // extrude
                Vector3 selectedSum = Vector3.Zero;
                foreach (var s in selector.selected)
                {
                    selectedSum += s.position;
                }
                dragMouseTracker.worldOrigin = selectedSum / selector.selected.Count;
                dragMouseTracker.mouseOrigin = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
                dragMouseTracker.oldOffset   = null;
                var selectedPolys            = GetSelectedPolys(selector);
                var clonedPolys = ClonePolys(selectedPolys);
                foreach (var p in clonedPolys)
                {
                    polyData.Add(p);
                }
                SetSelected(selector, clonedPolys);
                var perim1 = GetPerimeterPieces(selectedPolys);
                var perim2 = GetPerimeterPieces(clonedPolys);
                for (int i = 0; i < perim1.Count; i++)
                {
                    polyData.Add(new VertexData[] { perim1[i][1], perim2[i][1], perim2[i][0], perim1[i][0] });
                }
                foreach (var p in selectedPolys)
                {
                    polyData.Remove(p);
                }
            }, true);
            switcher.AddKeyFocus(Trigger.ShiftA, dragMouseTracker, () =>
            {
                // add a new unit plane and drag
                var v1 = new VertexData(new Vector3(0, 0, 0), Color.Black);
                var v2 = new VertexData(new Vector3(1, 0, 0), Color.Black);
                var v3 = new VertexData(new Vector3(1, 0, 1), Color.Black);
                var v4 = new VertexData(new Vector3(0, 0, 1), Color.Black);
                vertexData.AddRange(new[] { v1, v2, v3, v4 });
                var newPoly = new VertexData[] { v1, v2, v3, v4 };
                polyData.Add(newPoly);
                SetSelected(selector, new List <VertexData[]>()
                {
                    newPoly
                });
                dragMouseTracker.worldOrigin = new Vector3(0.5f, 0, 0.5f);
                dragMouseTracker.mouseOrigin = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
                dragMouseTracker.oldOffset   = null;
                var selectedPolys            = GetSelectedPolys(selector);
            }, true);
            Register(switcher);
            RegisterListener(new InputListener(Trigger.Delete, x =>
            {
                var selectedPolys = GetSelectedPolys(selector);
                foreach (var p in selectedPolys)
                {
                    polyData.Remove(p);
                }
            }));
            RegisterListener(new InputListener(Trigger.F, x =>
            {
                var selectedLines           = GetSelectedLines(selector);
                VertexData[] newPoly        = new VertexData[selector.selected.Count];
                newPoly[0]                  = selectedLines[0][1];
                newPoly[1]                  = selectedLines[0][0];
                List <VertexData> remaining = selector.selected.ToList();
                remaining.Remove(newPoly[0]);
                remaining.Remove(newPoly[1]);
                for (int i = 2; i < newPoly.Length; i++)
                {
                    VertexData best  = null;
                    double bestValue = -100;
                    foreach (var r in remaining)
                    {
                        Vector3 v1 = newPoly[i - 1].position - newPoly[i - 2].position;
                        Vector3 v2 = r.position - newPoly[i - 1].position;
                        v1.Normalize();
                        v2.Normalize();
                        double thisValue = Vector3.Dot(v1, v2);
                        if (thisValue > bestValue)
                        {
                            bestValue = thisValue;
                            best      = r;
                        }
                    }
                    remaining.Remove(best);
                    newPoly[i] = best;
                }
                polyData.Add(newPoly);
            }));
            Register(new PlaneGrid());
        }
Exemple #4
0
    //-----------------------------
    private void PlayGraph()
    {
        GComponent obj = _demoObjects["Graph"];

        Shape shape;

        shape = obj.GetChild("pie").asGraph.shape;
        EllipseMesh ellipse = shape.graphics.GetMeshFactory <EllipseMesh>();

        ellipse.startDegree = 30;
        ellipse.endDegreee  = 300;
        shape.graphics.SetMeshDirty();

        shape = obj.GetChild("trapezoid").asGraph.shape;
        PolygonMesh trapezoid = shape.graphics.GetMeshFactory <PolygonMesh>();

        trapezoid.usePercentPositions = true;
        trapezoid.points.Clear();
        trapezoid.points.Add(new Vector2(0.3f, 0));
        trapezoid.points.Add(new Vector2(0.7f, 0));
        trapezoid.points.Add(new Vector2(1f, 1f));
        trapezoid.points.Add(new Vector2(0f, 1f));
        shape.graphics.SetMeshDirty();

        shape = obj.GetChild("polygon").asGraph.shape;
        shape.DrawPolygon(new Vector2[] {
            new Vector2(20, 30),
            new Vector2(80, 40),
            new Vector2(80, 15),
            new Vector2(140, 50),
            new Vector2(80, 85),
            new Vector2(80, 60),
            new Vector2(20, 70)
        }, shape.color);

        shape = obj.GetChild("polygon2").asGraph.shape;
        shape.DrawRegularPolygon(5, 2, Color.yellow, Color.black, shape.color, -18, null);

        shape = obj.GetChild("radial").asGraph.shape;
        shape.DrawRegularPolygon(6, 2, shape.color, new Color32(0xFF, 0x99, 0x00, 128), shape.color, 0, new float[] { 0.6f, 0.8f, 0.6f, 0.8f, 0.6f, 0.5f });

        shape = obj.GetChild("line").asGraph.shape;
        LineMesh line = shape.graphics.GetMeshFactory <LineMesh>();

        line.lineWidthCurve = AnimationCurve.Linear(0, 25, 1, 10);
        line.roundEdge      = true;
        line.gradient       = lineGradient;
        line.path.Create(new GPathPoint[] {
            new GPathPoint(new Vector3(0, 120, 0)),
            new GPathPoint(new Vector3(20, 120, 0)),
            new GPathPoint(new Vector3(100, 100, 0)),
            new GPathPoint(new Vector3(180, 30, 0)),
            new GPathPoint(new Vector3(100, 0, 0)),
            new GPathPoint(new Vector3(20, 30, 0)),
            new GPathPoint(new Vector3(100, 100, 0)),
            new GPathPoint(new Vector3(180, 120, 0)),
            new GPathPoint(new Vector3(200, 120, 0)),
        });
        shape.graphics.SetMeshDirty();
        GTween.To(0, 1, 5).SetEase(EaseType.Linear).SetTarget(shape.graphics).OnUpdate((GTweener t) =>
        {
            ((NGraphics)t.target).GetMeshFactory <LineMesh>().fillEnd = t.value.x;
            ((NGraphics)t.target).SetMeshDirty();
        });

        shape = obj.GetChild("line2").asGraph.shape;
        LineMesh line2 = shape.graphics.GetMeshFactory <LineMesh>();

        line2.lineWidth = 3;
        line2.roundEdge = true;
        line2.path.Create(new GPathPoint[] {
            new GPathPoint(new Vector3(0, 120, 0), GPathPoint.CurveType.Straight),
            new GPathPoint(new Vector3(60, 30, 0), GPathPoint.CurveType.Straight),
            new GPathPoint(new Vector3(80, 90, 0), GPathPoint.CurveType.Straight),
            new GPathPoint(new Vector3(140, 30, 0), GPathPoint.CurveType.Straight),
            new GPathPoint(new Vector3(160, 90, 0), GPathPoint.CurveType.Straight),
            new GPathPoint(new Vector3(220, 30, 0), GPathPoint.CurveType.Straight)
        });
        shape.graphics.SetMeshDirty();

        GObject  image = obj.GetChild("line3");
        LineMesh line3 = image.displayObject.graphics.GetMeshFactory <LineMesh>();

        line3.lineWidth = 30;
        line3.roundEdge = false;
        line3.path.Create(new GPathPoint[] {
            new GPathPoint(new Vector3(0, 30, 0), new Vector3(50, -30), new Vector3(150, -50)),
            new GPathPoint(new Vector3(200, 30, 0), new Vector3(300, 130)),
            new GPathPoint(new Vector3(400, 30, 0))
        });
        image.displayObject.graphics.SetMeshDirty();
    }
Exemple #5
0
 void CreatLineMesh(Vector3 startPoint, Vector3 endPoint)
 {
     GetMeshComponent().mesh = LineMesh.CreateLine(startPoint, endPoint, Color.red);
 }
 public void Draw(GraphicsDevice device, CommonShaderParameters parameters)
 {
     LineMesh.Render(device, parameters, World);
 }
    //ラインを作成
    private LineMeshData CreateLine(LineMesh lm)
    {
        Vector3[] vert   = lm.vertices;
        Color[]   colorE = lm.colorOfEdge;
        Color[]   colorV = lm.colorOfVertex;
        int[]     ind    = lm.indices;

        //ちゃんと正しくデータが入っているかチェック
        if (vert == null)
        {
            return(new LineMeshData());
        }
        int count = vert.Length;

        if (count == 0)
        {
            return(new LineMeshData());
        }

        bool isCorrectContents = true;

        if (colorE != null)
        {
            isCorrectContents &= vert.Length == colorE.Length;
        }
        else
        {
            colorE = new Color[count];
            for (int i = 0; i < count; i++)
            {
                colorE [i] = DefaultColor;
            }
        }
        if (colorV != null)
        {
            isCorrectContents &= vert.Length == colorV.Length;
        }
        else
        {
            colorV = new Color[count];
            for (int i = 0; i < count; i++)
            {
                colorV [i] = DefaultColor;
            }
        }

        if (!isCorrectContents)
        {
            Debug.Assert(false, "ラインデータが異常です");
            return(new LineMeshData());
        }

        //メッシュを作成する
        //	エッジメッシュを作成
        List <LineMeshData> meshList = new List <LineMeshData> ();

        for (int i = 0; i < ind.Length; i += 2)
        {
            int i0 = ind [i];
            int i1 = ind [i + 1];
            meshList.Add(CreateEdge(vert [i0], vert [i1], colorE[i0], colorE[i1], lm.width, lm.normalVector));
        }
        //	バーテックスメッシュを作成
        for (int i = 0; i < vert.Length; i++)
        {
            meshList.Add(CreateVertex(vert[i], colorV[i], lm.vertexSize, lm.normalVector));
        }
        //	メッシュを統合
        return(LineMeshData.Combine(meshList));
    }