public DbgPrimWireRay(Transform location, Vector3 start, Vector3 end, Color color)
        {
            NameColor = color;


            if (GeometryData != null)
            {
                SetBuffers(GeometryData.GeomBuffer);
            }
            else
            {
                // 3 Letters of below names:
                // [T]op/[B]ottom, [F]ront/[B]ack, [L]eft/[R]ight

                // Top Face
                AddLine(start, end, color);

                //FinalizeBuffers(true);

                GeometryData = new DbgPrimGeometryData()
                {
                    GeomBuffer = GeometryBuffer
                };
            }
        }
        public DbgPrimWireArrow(string name, Transform location, Color color)
        {
            Category = DbgPrimCategory.HkxBone;

            NameColor = color;
            Name      = name;

            if (GeometryData != null)
            {
                SetBuffers(GeometryData.GeomBuffer);
            }
            else
            {
                Vector3 GetPoint(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);

                    return(new Vector3(x * radius, y * radius, depth));
                }

                AddLine(Vector3.Zero, Vector3.UnitY * OrientingSpinesLength);
                AddLine(Vector3.Zero, -Vector3.UnitX * OrientingSpinesLength * 0.5f);

                Vector3 tip = Vector3.UnitZ;

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

                    AddLine(ptBase, ptTipStartInner, color);
                    AddLine(ptTipStartInner, ptTipStartOuter, color);
                    AddLine(ptTipStartOuter, tip, color);

                    // Connect this vertical spline to the previous one with horizontal lines.
                    if (i > 0)
                    {
                        var prevPtBase          = GetPoint(i - 1, StemRadius, 0);
                        var prevPtTipStartInner = GetPoint(i - 1, StemRadius, 1 - TipLength);
                        var prevPtTipStartOuter = GetPoint(i - 1, TipRadius, 1 - TipLength);

                        AddLine(prevPtBase, ptBase, color);
                        AddLine(prevPtTipStartInner, ptTipStartInner, color);
                        AddLine(prevPtTipStartOuter, ptTipStartOuter, color);
                    }
                }

                //FinalizeBuffers(true);

                GeometryData = new DbgPrimGeometryData()
                {
                    GeomBuffer = GeometryBuffer
                };
            }
        }
示例#3
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);
                });
            }
        }
        public DbgPrimWireBone(string name, Transform location, Color color)
        {
            NameColor = color;
            Name      = name;

            if (GeometryData != null)
            {
                SetBuffers(GeometryData.GeomBuffer);
            }
            else
            {
                Vector3 pt_start     = Vector3.Zero;
                Vector3 pt_cardinal1 = Vector3.UnitY * ThicknessRatio + Vector3.UnitX * ThicknessRatio;
                Vector3 pt_cardinal2 = Vector3.UnitZ * ThicknessRatio + Vector3.UnitX * ThicknessRatio;
                Vector3 pt_cardinal3 = -Vector3.UnitY * ThicknessRatio + Vector3.UnitX * ThicknessRatio;
                Vector3 pt_cardinal4 = -Vector3.UnitZ * ThicknessRatio + Vector3.UnitX * ThicknessRatio;
                Vector3 pt_tip       = Vector3.UnitX;

                //Start to cardinals
                AddLine(pt_start, pt_cardinal1);
                AddLine(pt_start, pt_cardinal2);
                AddLine(pt_start, pt_cardinal3);
                AddLine(pt_start, pt_cardinal4);

                //Cardinals to end
                AddLine(pt_cardinal1, pt_tip);
                AddLine(pt_cardinal2, pt_tip);
                AddLine(pt_cardinal3, pt_tip);
                AddLine(pt_cardinal4, pt_tip);

                //Connecting the cardinals
                AddLine(pt_cardinal1, pt_cardinal2);
                AddLine(pt_cardinal2, pt_cardinal3);
                AddLine(pt_cardinal3, pt_cardinal4);
                AddLine(pt_cardinal4, pt_cardinal1);

                //FinalizeBuffers(true);

                GeometryData = new DbgPrimGeometryData()
                {
                    GeomBuffer = GeometryBuffer
                };
            }
        }
            public DbgPrimWireCapsule_Middle()
            {
                if (GeometryData != null)
                {
                    SetBuffers(GeometryData.GeomBuffer);
                }
                else
                {
                    for (int i = 0; i < Segments; i++)
                    {
                        float   horizontalAngle = (1.0f * i / Segments) * Utils.Pi * 2.0f;
                        Vector3 a = new Vector3((float)Math.Cos(horizontalAngle), 0, (float)Math.Sin(horizontalAngle));
                        Vector3 b = new Vector3(a.X, 1, a.Z);
                        AddLine(a, b, Color.White);
                    }

                    //FinalizeBuffers(true);

                    GeometryData = new DbgPrimGeometryData()
                    {
                        GeomBuffer = GeometryBuffer
                    };
                }
            }
示例#6
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);
            });
        }
示例#7
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);
                });
            }
        }
        public DbgPrimSolidArrow()
        {
            //BackfaceCulling = false;

            Category = DbgPrimCategory.HkxBone;

            if (GeometryData != null)
            {
                SetBuffers(GeometryData.GeomBuffer);
            }
            else
            {
                Vector3 GetPoint(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);

                    return(new Vector3(x * radius, y * radius, depth));
                }

                Vector3 tip = Vector3.UnitZ;

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

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

                    //Face: Part of Bottom
                    AddTri(Vector3.Zero, prevPtBase, ptBase, Color.Green);
                }

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

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

                    // Face: Base to Tip Inner
                    AddQuad(prevPtBase, prevPtTipStartInner, ptTipStartInner, ptBase, Color.Green);
                }

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

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

                    // Face: Tip Start Inner to Tip Start Outer
                    AddQuad(prevPtTipStartInner, prevPtTipStartOuter, ptTipStartOuter, ptTipStartInner, Color.Green);
                }

                for (int i = 1; i <= Segments; i++)
                {
                    var ptTipStartOuter     = GetPoint(i, TipRadius, 1 - TipLength);
                    var prevPtTipStartOuter = GetPoint(i - 1, TipRadius, 1 - TipLength);

                    // Face: Tip Start to Tip
                    AddTri(prevPtTipStartOuter, tip, ptTipStartOuter, Color.Green);
                }

                //FinalizeBuffers(true);

                GeometryData = new DbgPrimGeometryData()
                {
                    GeomBuffer = GeometryBuffer
                };
            }
        }
            public DbgPrimWireCapsule_End()
            {
                //if (!(Segments >= 4))
                //    throw new ArgumentException($"Number of segments must be >= 4", nameof(Segments));

                if (GeometryData != null)
                {
                    SetBuffers(GeometryData.GeomBuffer);
                }
                else
                {
                    var topPoint    = Vector3.UnitY * 1;
                    var bottomPoint = -Vector3.UnitY * 1;
                    var points      = new Vector3[Segments, Segments];

                    int verticalSegments = Segments / 2;

                    for (int i = 0; i <= verticalSegments; i++)
                    {
                        for (int j = 0; j < Segments; j++)
                        {
                            float horizontalAngle = (1.0f * j / Segments) * Utils.Pi * 2.0f;
                            float verticalAngle   = ((1.0f * (i) / (verticalSegments)) * Utils.PiOver2);
                            float altitude        = (float)Math.Sin(verticalAngle);
                            float horizontalDist  = (float)Math.Cos(verticalAngle);
                            points[i, j] = new Vector3((float)Math.Cos(horizontalAngle) * horizontalDist, altitude, (float)Math.Sin(horizontalAngle) * horizontalDist) * 1;
                        }
                    }

                    for (int i = 0; i <= verticalSegments; i++)
                    {
                        for (int j = 0; j < Segments; j++)
                        {
                            //// On the bottom, we must connect each to the bottom point
                            //if (i == 0)
                            //{
                            //    AddLine(points[i, j], bottomPoint, Color.White);
                            //}

                            // On the top, we must connect each point to the top
                            // Note: this isn't "else if" because with 2 segments,
                            // these are both true for the only ring
                            if (i == Segments - 1)
                            {
                                AddLine(points[i, j], topPoint, Color.White);
                            }

                            // Make vertical lines that connect from this
                            // horizontal ring to the one above
                            // Since we are connecting
                            // (current) -> (the one above current)
                            // we dont need to do this for the very last one.
                            if (i < Segments - 1)
                            {
                                AddLine(points[i, j], points[i + 1, j], Color.White);
                            }


                            // Make lines that connect points horizontally
                            //---- if we reach end, we must wrap around,
                            //---- otherwise, simply make line to next one
                            if (j == Segments - 1)
                            {
                                AddLine(points[i, j], points[i, 0], Color.White);
                            }
                            else
                            {
                                AddLine(points[i, j], points[i, j + 1], Color.White);
                            }
                        }
                    }

                    //FinalizeBuffers(true);

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