示例#1
0
        public DbgPrimGizmoTranslateSquare(MsbEditor.Gizmos.Axis axis)
        {
            if (GeometryData != null)
            {
                SetBuffers(GeometryData.GeomBuffer);
            }
            else
            {
                Vector3 a, b, c, d;
                switch (axis)
                {
                case MsbEditor.Gizmos.Axis.PosX:
                    a = new Vector3(0.0f, StartOffset, StartOffset);
                    b = new Vector3(0.0f, StartOffset + Length, StartOffset);
                    c = new Vector3(0.0f, StartOffset, StartOffset + Length);
                    d = new Vector3(0.0f, StartOffset + Length, StartOffset + Length);
                    break;

                case MsbEditor.Gizmos.Axis.PosY:
                    a = new Vector3(StartOffset, 0.0f, StartOffset);
                    b = new Vector3(StartOffset + Length, 0.0f, StartOffset);
                    c = new Vector3(StartOffset, 0.0f, StartOffset + Length);
                    d = new Vector3(StartOffset + Length, 0.0f, StartOffset + Length);
                    break;

                case MsbEditor.Gizmos.Axis.PosZ:
                    a = new Vector3(StartOffset, StartOffset, 0.0f);
                    b = new Vector3(StartOffset + Length, StartOffset, 0.0f);
                    c = new Vector3(StartOffset, StartOffset + Length, 0.0f);
                    d = new Vector3(StartOffset + Length, StartOffset + Length, 0.0f);
                    break;

                default:
                    throw new ArgumentException("Select valid axis");
                }

                var color = Color.FromArgb(0x86, 0xC8, 0x15);
                AddQuad(a, b, d, c, color);
                AddColQuad(Tris, a, b, d, c);

                GeometryData = new DbgPrimGeometryData()
                {
                    GeomBuffer = GeometryBuffer
                };

                Renderer.AddBackgroundUploadTask((d, cl) =>
                {
                    UpdatePerFrameResources(d, cl, null);
                });
            }
        }
示例#2
0
        public DbgPrimGizmoRotateRing(MsbEditor.Gizmos.Axis axis)
        {
            if (GeometryData != null)
            {
                SetBuffers(GeometryData.GeomBuffer);
            }
            else
            {
                Vector3 GetPoint(MsbEditor.Gizmos.Axis axis, int segmentIndex, float radius, float depth)
                {
                    float horizontalAngle = (1.0f * segmentIndex / Segments) * Utils.Pi * 2.0f;
                    float x = (float)Math.Cos(horizontalAngle);
                    float y = (float)Math.Sin(horizontalAngle);

                    if (axis == MsbEditor.Gizmos.Axis.PosZ)
                    {
                        return(new Vector3(x * radius, y * radius, depth));
                    }
                    if (axis == MsbEditor.Gizmos.Axis.PosX)
                    {
                        return(new Vector3(depth, x * radius, y * radius));
                    }
                    return(new Vector3(x * radius, depth, y * radius));
                }

                // Algorithm from
                // http://apparat-engine.blogspot.com/2013/04/procedural-meshes-torus.html
                void Ring(MsbEditor.Gizmos.Axis axis, Color color)
                {
                    var collist = Tris;

                    List <Vector3> vertices         = new List <Vector3>((RingCount + 1) * (SideCount + 1));
                    List <Vector3> colvertices      = new List <Vector3>((RingCount + 1) * (SideCount + 1));
                    float          theta            = 0.0f;
                    float          phi              = 0.0f;
                    float          verticalStride   = (float)(Math.PI * 2.0) / (float)RingCount;
                    float          horizontalStride = (float)(Math.PI * 2.0f) / (float)SideCount;

                    for (int i = 0; i < RingCount + 1; i++)
                    {
                        theta = verticalStride * i;
                        for (int j = 0; j < SideCount + 1; j++)
                        {
                            phi = horizontalStride * j;
                            float cosphi   = (float)Math.Cos(phi);
                            float sinphi   = (float)Math.Sin(phi);
                            float costheta = (float)Math.Cos(theta);
                            float sintheta = (float)Math.Sin(theta);
                            float a        = costheta * (Radius + RingRadius * cosphi);
                            float b        = sintheta * (Radius + RingRadius * cosphi);
                            float c        = RingRadius * sinphi;
                            float ca       = costheta * (Radius + RingRadius * 7.0f * cosphi);
                            float cb       = sintheta * (Radius + RingRadius * 7.0f * cosphi);
                            float cc       = RingRadius * 7.0f * sinphi;

                            if (axis == MsbEditor.Gizmos.Axis.PosX)
                            {
                                vertices.Add(new Vector3(c, a, b));
                                colvertices.Add(new Vector3(cc, ca, cb));
                            }
                            if (axis == MsbEditor.Gizmos.Axis.PosY)
                            {
                                vertices.Add(new Vector3(a, c, b));
                                colvertices.Add(new Vector3(ca, cc, cb));
                            }
                            if (axis == MsbEditor.Gizmos.Axis.PosZ)
                            {
                                vertices.Add(new Vector3(a, b, c));
                                colvertices.Add(new Vector3(ca, cb, cc));
                            }
                        }
                    }

                    for (int i = 0; i < RingCount; i++)
                    {
                        for (int j = 0; j < SideCount; j++)
                        {
                            int a = (j + i * (SideCount + 1));
                            int b = ((j + 1) + i * (SideCount + 1));
                            int c = (j + (i + 1) * (SideCount + 1));
                            int d = ((j + 1) + (i + 1) * (SideCount + 1));
                            //AddQuad(vertices[a], vertices[b], vertices[c], vertices[d], color);
                            AddTri(vertices[a], vertices[b], vertices[c], color);
                            AddTri(vertices[b], vertices[d], vertices[c], color);
                            AddColTri(collist, colvertices[a], colvertices[b], colvertices[c]);
                            AddColTri(collist, colvertices[b], colvertices[d], colvertices[c]);
                        }
                    }
                }

                Ring(axis, Color.FromArgb(0x86, 0xC8, 0x15));

                //FinalizeBuffers(true);

                GeometryData = new DbgPrimGeometryData()
                {
                    GeomBuffer = GeometryBuffer,
                };
            }

            Scene.Renderer.AddBackgroundUploadTask((d, cl) =>
            {
                UpdatePerFrameResources(d, cl, null);
            });
        }
示例#3
0
        public DbgPrimGizmoTranslateArrow(MsbEditor.Gizmos.Axis axis)
        {
            if (GeometryData != null)
            {
                SetBuffers(GeometryData.GeomBuffer);
            }
            else
            {
                Vector3 GetPoint(MsbEditor.Gizmos.Axis axis, int segmentIndex, float radius, float depth)
                {
                    float horizontalAngle = (1.0f * segmentIndex / Segments) * Utils.Pi * 2.0f;
                    float x = (float)Math.Cos(horizontalAngle);
                    float y = (float)Math.Sin(horizontalAngle);

                    if (axis == MsbEditor.Gizmos.Axis.PosZ)
                    {
                        return(new Vector3(x * radius, y * radius, depth));
                    }
                    if (axis == MsbEditor.Gizmos.Axis.PosX)
                    {
                        return(new Vector3(depth, x * radius, y * radius));
                    }
                    return(new Vector3(x * radius, depth, y * radius));
                }

                void Arrow(MsbEditor.Gizmos.Axis axis, Color color)
                {
                    Vector3 tip = Vector3.Zero;

                    if (axis == MsbEditor.Gizmos.Axis.PosX)
                    {
                        tip = Vector3.UnitX * TotalLength;
                    }
                    if (axis == MsbEditor.Gizmos.Axis.PosY)
                    {
                        tip = Vector3.UnitY * TotalLength;
                    }
                    if (axis == MsbEditor.Gizmos.Axis.PosZ)
                    {
                        tip = Vector3.UnitZ * TotalLength;
                    }

                    for (int i = 1; i <= Segments; i++)
                    {
                        var ptBase = GetPoint(axis, i, StemRadius, 0);

                        var prevPtBase = GetPoint(axis, i - 1, StemRadius, 0);

                        //Face: Part of Bottom
                        AddTri(Vector3.Zero, prevPtBase, ptBase, color);
                        AddColTri(Tris, Vector3.Zero, prevPtBase, ptBase);
                    }

                    for (int i = 1; i <= Segments; i++)
                    {
                        var ptBase             = GetPoint(axis, i, StemRadius, 0);
                        var ptTipStartInner    = GetPoint(axis, i, StemRadius, TotalLength - TipLength);
                        var ptBaseCol          = GetPoint(axis, i, TipRadius * 1.25f, 0);
                        var ptTipStartInnerCol = GetPoint(axis, i, TipRadius * 1.25f, TotalLength - TipLength);

                        var prevPtBase             = GetPoint(axis, i - 1, StemRadius, 0);
                        var prevPtTipStartInner    = GetPoint(axis, i - 1, StemRadius, TotalLength - TipLength);
                        var prevPtBaseCol          = GetPoint(axis, i - 1, TipRadius * 1.25f, 0);
                        var prevPtTipStartInnerCol = GetPoint(axis, i - 1, TipRadius * 1.25f, TotalLength - TipLength);

                        // Face: Base to Tip Inner
                        AddQuad(prevPtBase, prevPtTipStartInner, ptTipStartInner, ptBase, color);
                        AddColQuad(Tris, prevPtBaseCol, prevPtTipStartInnerCol, ptTipStartInnerCol, ptBaseCol);
                    }

                    for (int i = 1; i <= Segments; i++)
                    {
                        var ptTipStartInner = GetPoint(axis, i, StemRadius, TotalLength - TipLength);
                        var ptTipStartOuter = GetPoint(axis, i, TipRadius, TotalLength - TipLength);

                        var prevPtTipStartInner = GetPoint(axis, i - 1, StemRadius, TotalLength - TipLength);
                        var prevPtTipStartOuter = GetPoint(axis, i - 1, TipRadius, TotalLength - TipLength);

                        // Face: Tip Start Inner to Tip Start Outer
                        AddQuad(prevPtTipStartInner, prevPtTipStartOuter, ptTipStartOuter, ptTipStartInner, color);
                        AddColQuad(Tris, prevPtTipStartInner, prevPtTipStartOuter, ptTipStartOuter, ptTipStartInner);
                    }

                    for (int i = 1; i <= Segments; i++)
                    {
                        var ptTipStartOuter        = GetPoint(axis, i, TipRadius, TotalLength - TipLength);
                        var prevPtTipStartOuter    = GetPoint(axis, i - 1, TipRadius, TotalLength - TipLength);
                        var ptTipStartOuterCol     = GetPoint(axis, i, TipRadius * 1.25f, TotalLength - TipLength);
                        var prevPtTipStartOuterCol = GetPoint(axis, i - 1, TipRadius * 1.25f, TotalLength - TipLength);

                        // Face: Tip Start to Tip
                        AddTri(prevPtTipStartOuter, tip, ptTipStartOuter, color);
                        AddColTri(Tris, prevPtTipStartOuterCol, tip * 1.10f, ptTipStartOuterCol);
                    }
                }

                //Arrow(MsbEditor.Gizmos.Axis.PosX, Color.FromArgb(0xF3, 0x36, 0x53));
                //Arrow(MsbEditor.Gizmos.Axis.PosZ, Color.FromArgb(0x38, 0x90, 0xED));
                //Arrow(MsbEditor.Gizmos.Axis.PosY, Color.FromArgb(0x86, 0xC8, 0x15));
                Arrow(axis, Color.FromArgb(0x86, 0xC8, 0x15));
                //FinalizeBuffers(true);

                GeometryData = new DbgPrimGeometryData()
                {
                    GeomBuffer = GeometryBuffer
                };

                Renderer.AddBackgroundUploadTask((d, cl) =>
                {
                    UpdatePerFrameResources(d, cl, null);
                });
            }
        }