// ------------------------------------------------------------------------ // 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)); } }
// ------------------------------------------------------------------------ // end: sphere // capsule // ------------------------------------------------------------------------ public static void DrawCapsule(Vector3 center, Quaternion rotation, float height, float radius, int latSegmentsPerCap, int longSegmentsPerCap, 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.CapsuleWireframe(latSegmentsPerCap, longSegmentsPerCap, true, true, false); break; case Style.SolidColor: mesh = PrimitiveMeshFactory.CapsuleSolidColor(latSegmentsPerCap, longSegmentsPerCap, true, true, false); break; case Style.FlatShaded: mesh = PrimitiveMeshFactory.CapsuleFlatShaded(latSegmentsPerCap, longSegmentsPerCap, true, true, false); break; case Style.SmoothShaded: mesh = PrimitiveMeshFactory.CapsuleSmoothShaded(latSegmentsPerCap, longSegmentsPerCap, true, true, false); 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, rotation, material, 0, null, 0, materialProperties, false, false, false); }