Example #1
0
        // ------------------------------------------------------------------------
        // end: line


        // box
        // ------------------------------------------------------------------------

        public static void DrawBox(Vector3 center, Quaternion rotation, Vector3 dimensions, Color color, Style style = Style.FlatShaded)
        {
            if (dimensions.x < MathUtil.Epsilon || dimensions.y < MathUtil.Epsilon || dimensions.z < MathUtil.Epsilon)
            {
                return;
            }

            Mesh mesh = null;

            switch (style)
            {
            case Style.Wireframe:
                mesh = PrimitiveMeshFactory.BoxWireframe();
                break;

            case Style.FlatShaded:
            case Style.SmoothShaded:
                mesh = PrimitiveMeshFactory.BoxFlatShaded();
                break;
            }
            if (mesh == null)
            {
                return;
            }

            Gizmos.color = color;
            if (style == Style.Wireframe)
            {
                Gizmos.DrawWireMesh(mesh, center, rotation, dimensions);
            }
            else
            {
                Gizmos.DrawMesh(mesh, center, rotation, dimensions);
            }
        }
Example #2
0
        // ------------------------------------------------------------------------
        // end: sphere


        // capsule
        // ------------------------------------------------------------------------

        public static void DrawCapsule(Vector3 center, Quaternion rotation, float height, float radius, int latSegmentsPerCap, int longSegmentsPerCap, Color color, Style style = Style.SmoothShaded)
        {
            if (height < MathUtil.Epsilon || radius < MathUtil.Epsilon)
            {
                return;
            }

            Mesh meshCaps  = null;
            Mesh meshSides = null;

            switch (style)
            {
            case Style.Wireframe:
                meshCaps  = PrimitiveMeshFactory.CapsuleWireframe(latSegmentsPerCap, longSegmentsPerCap, true, true, false);
                meshSides = PrimitiveMeshFactory.CapsuleWireframe(latSegmentsPerCap, longSegmentsPerCap, false, false, true);
                break;

            case Style.FlatShaded:
                meshCaps  = PrimitiveMeshFactory.CapsuleFlatShaded(latSegmentsPerCap, longSegmentsPerCap, true, true, false);
                meshSides = PrimitiveMeshFactory.CapsuleFlatShaded(latSegmentsPerCap, longSegmentsPerCap, false, false, true);
                break;

            case Style.SmoothShaded:
                meshCaps  = PrimitiveMeshFactory.CapsuleSmoothShaded(latSegmentsPerCap, longSegmentsPerCap, true, true, false);
                meshSides = PrimitiveMeshFactory.CapsuleSmoothShaded(latSegmentsPerCap, longSegmentsPerCap, false, false, true);
                break;
            }
            if (meshCaps == null || meshSides == null)
            {
                return;
            }

            Vector3 axisY           = rotation * Vector3.up;
            Vector3 topCapOffset    = 0.5f * (height - radius) * axisY;
            Vector3 topCapCenter    = center + topCapOffset;
            Vector3 bottomCapCenter = center - topCapOffset;

            Quaternion bottomCapRotation = Quaternion.AngleAxis(180.0f, axisY) * rotation;

            Gizmos.color = color;
            if (style == Style.Wireframe)
            {
                Gizmos.DrawWireMesh(meshCaps, topCapCenter, rotation, new Vector3(radius, radius, radius));
                Gizmos.DrawWireMesh(meshCaps, bottomCapCenter, bottomCapRotation, new Vector3(-radius, -radius, radius));
                Gizmos.DrawWireMesh(meshSides, center, rotation, new Vector3(radius, height, radius));
            }
            else
            {
                Gizmos.DrawMesh(meshCaps, topCapCenter, rotation, new Vector3(radius, radius, radius));
                Gizmos.DrawMesh(meshCaps, bottomCapCenter, bottomCapRotation, new Vector3(-radius, -radius, radius));
                Gizmos.DrawMesh(meshSides, center, rotation, new Vector3(radius, height, radius));
            }
        }
Example #3
0
        // ------------------------------------------------------------------------
        // end: line

        // rect
        // ------------------------------------------------------------------------

        // draw a rectangle on the XZ plane centered at origin in object space, dimensions = (X dimension, Z dimension)
        public static void DrawRect(Vector3 center, Quaternion rotation, Vector2 dimensions, Color color, bool depthTest = true)
        {
            Mesh mesh = PrimitiveMeshFactory.Rect();

            if (mesh == null)
            {
                return;
            }

            Material material = GetMaterial(depthTest);
            MaterialPropertyBlock materialProperties = GetMaterialPropertyBlock();

            materialProperties.SetColor("_Color", color);
            materialProperties.SetVector("_Dimensions", new Vector4(dimensions.x, 0.0f, dimensions.y, 0.0f));

            Graphics.DrawMesh(mesh, center, rotation, material, 0, null, 0, materialProperties, false, false, false);
        }
Example #4
0
        public static void DrawCapsule2D(Vector3 center, float rotationDeg, float height, float radius, int capSegments, Color color, bool depthTest = true)
        {
            Mesh mesh = PrimitiveMeshFactory.Capsule2D(capSegments);

            if (mesh == null)
            {
                return;
            }

            Material material = GetMaterial(depthTest);
            MaterialPropertyBlock materialProperties = GetMaterialPropertyBlock();

            materialProperties.SetColor("_Color", color);
            materialProperties.SetVector("_Dimensions", new Vector4(radius, radius, radius, height));

            Graphics.DrawMesh(mesh, center, Quaternion.AngleAxis(rotationDeg, Vector3.forward), material, 0, null, 0, materialProperties, false, false, false);
        }
Example #5
0
        // ------------------------------------------------------------------------
        // end: sphere


        // capsule
        // ------------------------------------------------------------------------

        public static void DrawCapsule(Vector3 center, Quaternion rotation, float height, float radius, int latSegmentsPerCap, int longSegmentsPerCap, Color color, bool depthTest = true)
        {
            Mesh mesh = PrimitiveMeshFactory.Capsule(latSegmentsPerCap, longSegmentsPerCap);

            if (mesh == null)
            {
                return;
            }

            Material material = GetMaterial(depthTest);
            MaterialPropertyBlock materialProperties = GetMaterialPropertyBlock();

            materialProperties.SetColor("_Color", color);
            materialProperties.SetVector("_Dimensions", new Vector4(radius, radius, radius, height));

            Graphics.DrawMesh(mesh, center, rotation, material, 0, null, 0, materialProperties, false, false, false);
        }
Example #6
0
        public static void DrawLineStrip(Vector3[] aVert, Color color, bool depthTest = true)
        {
            Mesh mesh = PrimitiveMeshFactory.LineStrip(aVert);

            if (mesh == null)
            {
                return;
            }

            Material material = GetMaterial(Style.Wireframe, depthTest, false);
            MaterialPropertyBlock materialProperties = GetMaterialPropertyBlock();

            materialProperties.SetColor("_Color", color);
            materialProperties.SetVector("_Dimensions", new Vector4(1.0f, 1.0f, 1.0f, 0.0f));
            materialProperties.SetFloat("_ZBias", s_wireframeZBias);

            Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, material, 0, null, 0, materialProperties, false, false, false);
        }
Example #7
0
        // ------------------------------------------------------------------------
        // end: capsule


        // cone
        // ------------------------------------------------------------------------

        public static void DrawCone(Vector3 baseCenter, Quaternion rotation, float height, float radius, int numSegments, Color color, bool depthTest = true, Style style = Style.Wireframe)
        {
            if (height < MathUtil.Epsilon || radius < MathUtil.Epsilon)
            {
                return;
            }

            Mesh mesh = null;

            switch (style)
            {
            case Style.Wireframe:
                mesh = PrimitiveMeshFactory.ConeWireframe(numSegments);
                break;

            case Style.SolidColor:
                mesh = PrimitiveMeshFactory.ConeSolidColor(numSegments);
                break;

            case Style.FlatShaded:
                mesh = PrimitiveMeshFactory.ConeFlatShaded(numSegments);
                break;

            case Style.SmoothShaded:
                mesh = PrimitiveMeshFactory.ConeSmoothShaded(numSegments);
                break;
            }
            if (mesh == null)
            {
                return;
            }

            Material material = GetMaterial(style, depthTest, false);
            MaterialPropertyBlock materialProperties = GetMaterialPropertyBlock();

            materialProperties.SetColor("_Color", color);
            materialProperties.SetVector("_Dimensions", new Vector4(radius, height, radius, 0.0f));
            materialProperties.SetFloat("_ZBias", (style == Style.Wireframe) ? s_wireframeZBias : 0.0f);

            Graphics.DrawMesh(mesh, baseCenter, rotation, material, 0, null, 0, materialProperties, false, false, false);
        }
Example #8
0
        public static void DrawCapsule2D(Vector3 center, float rotationDeg, float height, float radius, int capSegments, Color color, bool depthTest = true, Style style = Style.Wireframe)
        {
            if (height < MathUtil.Epsilon || radius < MathUtil.Epsilon)
            {
                return;
            }

            Mesh mesh = null;

            switch (style)
            {
            case Style.Wireframe:
                mesh = PrimitiveMeshFactory.Capsule2DWireframe(capSegments);
                break;

            case Style.SolidColor:
                mesh = PrimitiveMeshFactory.Capsule2DSolidColor(capSegments);
                break;

            case Style.FlatShaded:
            case Style.SmoothShaded:
                mesh = PrimitiveMeshFactory.Capsule2DFlatShaded(capSegments);
                break;
            }
            if (mesh == null)
            {
                return;
            }

            Material material = GetMaterial(style, depthTest, true);
            MaterialPropertyBlock materialProperties = GetMaterialPropertyBlock();

            materialProperties.SetColor("_Color", color);
            materialProperties.SetVector("_Dimensions", new Vector4(radius, radius, radius, height));
            materialProperties.SetFloat("_ZBias", (style == Style.Wireframe) ? s_wireframeZBias : 0.0f);

            Graphics.DrawMesh(mesh, center, Quaternion.AngleAxis(rotationDeg, Vector3.forward), material, 0, null, 0, materialProperties, false, false, false);
        }
Example #9
0
        // ------------------------------------------------------------------------
        // end: box


        // rect
        // ------------------------------------------------------------------------

        // draw a rectangle on the XZ plane centered at origin in object space, dimensions = (X dimension, Z dimension)
        public static void DrawRect(Vector3 center, Quaternion rotation, Vector2 dimensions, Color color, bool depthTest = true, Style style = Style.Wireframe)
        {
            if (dimensions.x < MathUtil.Epsilon || dimensions.y < MathUtil.Epsilon)
            {
                return;
            }

            Mesh mesh = null;

            switch (style)
            {
            case Style.Wireframe:
                mesh = PrimitiveMeshFactory.RectWireframe();
                break;

            case Style.SolidColor:
                mesh = PrimitiveMeshFactory.RectSolidColor();
                break;

            case Style.FlatShaded:
            case Style.SmoothShaded:
                mesh = PrimitiveMeshFactory.RectFlatShaded();
                break;
            }
            if (mesh == null)
            {
                return;
            }

            Material material = GetMaterial(style, depthTest, false);
            MaterialPropertyBlock materialProperties = GetMaterialPropertyBlock();

            materialProperties.SetColor("_Color", color);
            materialProperties.SetVector("_Dimensions", new Vector4(dimensions.x, 1.0f, dimensions.y, 0.0f));
            materialProperties.SetFloat("_ZBias", (style == Style.Wireframe) ? s_wireframeZBias : 0.0f);

            Graphics.DrawMesh(mesh, center, rotation, material, 0, null, 0, materialProperties, false, false, false);
        }
Example #10
0
        // ------------------------------------------------------------------------
        // end: capsule


        // cone
        // ------------------------------------------------------------------------

        public static void DrawCone(Vector3 baseCenter, Quaternion rotation, float height, float radius, int numSegments, Color color, Style style = Style.FlatShaded)
        {
            if (height < MathUtil.Epsilon || radius < MathUtil.Epsilon)
            {
                return;
            }

            Mesh mesh = null;

            switch (style)
            {
            case Style.Wireframe:
                mesh = PrimitiveMeshFactory.ConeWireframe(numSegments);
                break;

            case Style.FlatShaded:
                mesh = PrimitiveMeshFactory.ConeFlatShaded(numSegments);
                break;

            case Style.SmoothShaded:
                mesh = PrimitiveMeshFactory.ConeSmoothShaded(numSegments);
                break;
            }
            if (mesh == null)
            {
                return;
            }

            Gizmos.color = color;
            if (style == Style.Wireframe)
            {
                Gizmos.DrawWireMesh(mesh, baseCenter, rotation, new Vector3(radius, height, radius));
            }
            else
            {
                Gizmos.DrawMesh(mesh, baseCenter, rotation, new Vector3(radius, height, radius));
            }
        }
Example #11
0
        // ------------------------------------------------------------------------
        // end: cylinder


        // sphere
        // ------------------------------------------------------------------------

        public static void DrawSphere(Vector3 center, Quaternion rotation, float radius, int latSegments, int longSegments, Color color, Style style = Style.SmoothShaded)
        {
            if (radius < MathUtil.Epsilon)
            {
                return;
            }

            Mesh mesh = null;

            switch (style)
            {
            case Style.Wireframe:
                mesh = PrimitiveMeshFactory.SphereWireframe(latSegments, longSegments);
                break;

            case Style.FlatShaded:
                mesh = PrimitiveMeshFactory.SphereFlatShaded(latSegments, longSegments);
                break;

            case Style.SmoothShaded:
                mesh = PrimitiveMeshFactory.SphereSmoothShaded(latSegments, longSegments);
                break;
            }
            if (mesh == null)
            {
                return;
            }

            Gizmos.color = color;
            if (style == Style.Wireframe)
            {
                Gizmos.DrawWireMesh(mesh, center, rotation, new Vector3(radius, radius, radius));
            }
            else
            {
                Gizmos.DrawMesh(mesh, center, rotation, new Vector3(radius, radius, radius));
            }
        }