{"id":5746,"date":"2023-08-05T00:00:28","date_gmt":"2023-08-04T23:00:28","guid":{"rendered":"https:\/\/www.katsbits.com\/codex\/?p=5746"},"modified":"2023-09-07T15:48:32","modified_gmt":"2023-09-07T14:48:32","slug":"collision-meshes","status":"publish","type":"post","link":"https:\/\/www.katsbits.com\/codex\/collision-meshes\/","title":{"rendered":"Collision Meshes for Game Assets (Godot, Unity, Unreal&#8230;)"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a15d7329befb\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a15d7329befb\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.katsbits.com\/codex\/collision-meshes\/#convex-vs-concave\" >Convex vs. Concave<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.katsbits.com\/codex\/collision-meshes\/#blender-bounds\" >Blender Bounds<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.katsbits.com\/codex\/collision-meshes\/#primitive-shapes\" >Primitive Shapes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.katsbits.com\/codex\/collision-meshes\/#compound-shapes\" >Compound Shapes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.katsbits.com\/codex\/collision-meshes\/#complex-meshes\" >Complex Meshes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.katsbits.com\/codex\/collision-meshes\/#export-collision\" >Export Collision<\/a><\/li><\/ul><\/nav><\/div>\n<p>With the continual development of Godot, Unity, Unreal et al, 3D assets no longer need to explicitly include <b>collision meshes<\/b> or hulls as part of a given objects package as they tend to be, depending on the type of object or user interactions needed in a given situation, auto-generated by proprietary physics and collision solutions. With that said, manually creating collisions meshes or hulls is still useful, even when using modern game development tools.<\/p>\n<blockquote style=\"background-color: #fc0; color: #000;\"><p><b>Important<\/b>: due to the number of collision types most modern game engines\/development suites have available, there isn&#8217;t a succinct uniform way to export assets with collision such that they are automatically recognised and assigned the appropriate collision type upon import (a number of &#8216;tags&#8217; can be used but this doesn&#8217;t guaranty correct conversion). This means exporting collision meshes (hulls) from Blender is largely organisational, so collision can be clearly seen and then appropriately edited as required once imported into the game-editing suite of choice.<\/p><\/blockquote>\n<h3><span class=\"ez-toc-section\" id=\"convex-vs-concave\"><\/span>Convex vs. Concave<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The simplest way to visualise a collision hull is to view an objects <b>bounding box<\/b>. In Blender enabling <b>Bounds<\/b> [1] displays a wireframe around a selection that represents the objects total volume, essentially the amount of primitive space it occupies. In its simplest form collision is typically a <b>convex<\/b> cuboid or rectilinear shape of some kind (default <b>Box<\/b>). In other words, for the shape to considered a valid convex form there should be no indentations, undercuts, holes or other types of &#8216;<i>negative<\/i>&#8216;, or <b>concave<\/b>, structures &#8211; collision is, or should be, a primitive made from axial, aligned surfaces. Similarly, this is also true of collision meshes used for games, they too should be convex structures that have no &#8216;negative&#8217; or concave shapes.<\/p>\n<blockquote><p><b>Design note<\/b>: to enable wireframe outline, in <b>Object Properties<\/b> click the <b>Bounds<\/b> checkbox option in the <b>Viewport Display<\/b> subsection to enable and set the type of primitive to use, typically <b>Box<\/b> &#8211; all the primitive shapes used to describe an objects bounds in Blender are convex.<\/p><\/blockquote>\n<p><a href=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-bounds.jpg\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" style=\"width: 100%; height: auto;\" src=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-bounds.jpg\" alt=\"Bounds represent collision\" width=\"900px\" height=\"500px\" border=\"0\" \/><\/a><br \/>\n<i>In Blender, Bounds [1] represents the volume the object occupies, the shape being analogous to a convex collision hull.<\/i><\/p>\n<h3><span class=\"ez-toc-section\" id=\"blender-bounds\"><\/span>Blender Bounds<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>With the above in mind, the shape collision takes depends largely on the objects physical attributes and the role it&#8217;s supposed to perform in-game, walls for example, generally have different collision characteristics to those of usable items, a sword or throwable &#8216;acme bomb&#8217;, both utilise different collision models that accommodates those differing functions. Here then, it might be possible to use the aforementioned <b>Bounds<\/b> setting in Blender to determine an appropriate shape a given object might use for its collision mesh.<\/p>\n<blockquote><p><b>Design note<\/b>: modern game development suites are better able to utilise curved and\/or organic forms but due care may still be applicable when using more complex shapes for collision meshes and hulls.<\/p><\/blockquote>\n<p><a href=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-shapes.jpg\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" style=\"width: 100%; height: auto;\" src=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-shapes.jpg\" alt=\"Basic Collision shapes\" width=\"900px\" height=\"500px\" border=\"0\" \/><\/a><br \/>\n<i>The different types of primitive shapes used for <b>Bounds<\/b> in Blender that can also be used to assess collision mesh shapes.<\/i><\/p>\n<h3><span class=\"ez-toc-section\" id=\"primitive-shapes\"><\/span>Primitive Shapes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Looking at the available Bounds shapes then, it&#8217;s possible to use those as the basis to determine collisions meshes that cover most circumstances. For example, the acme bomb shown is ostensibly a <i>sphere<\/i> with a <i>cylinder<\/i> sticking out the top but, depending on the integration needed from the object in-game its collision could just as easily be a box.<\/p>\n<blockquote style=\"background-color: #fc0; color: #000;\"><p><b>Important<\/b>: as collision implies physics, complex shapes will use more resources than simpler ones. In practice this might mean there being multiple versions of the same object, each catering to different requirements; the collision hull for a &#8216;spawn item&#8217; or &#8216;pick-up&#8217; does not need to be complex because the object doesn&#8217;t invoke complex interactions with the world or player other than being a placement or positional &#8216;marker&#8217;, whereas a usable weapon might, as that may need to bounce off walls, floors, be held in the hand and\/or thrown.<\/p><\/blockquote>\n<p><a href=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-types.jpg\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" style=\"width: 100%; height: auto;\" src=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-types.jpg\" alt=\"Types of Collision\" width=\"900px\" height=\"500px\" border=\"0\" \/><\/a><br \/>\n<i>The different types of collision an object might use; a simple &#8216;box&#8217;, a &#8216;compound&#8217; object made from different shapes, and a &#8216;complex&#8217; shell that more accurately fits the items form and function.<\/i><\/p>\n<h3><span class=\"ez-toc-section\" id=\"compound-shapes\"><\/span>Compound Shapes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>As a general rule of thumb collision hulls need to conform to one, or both, of the following rules, they must be;<\/p>\n<ul>\n<li>convex shapes.<\/li>\n<li>uniform and solid.<\/li>\n<\/ul>\n<p>However, a collision hulls final form <i>can<\/i> appear concave [1] in part of whole so long as they are themselves;<\/p>\n<ul>\n<li>an object made from other convex shapes (compound object).<\/li>\n<li>each convex shape is closed or solid (no &#8216;leaks&#8217;).<\/li>\n<\/ul>\n<p>What this means in practice is that each mesh forming part of a compound collision hull, should themselves be &#8216;valid&#8217; as individual objects, that is, be convex and have no gaps, voids or open (sur)faces.<\/p>\n<blockquote style=\"background-color: #fc0; color: #000;\"><p><b>Important<\/b>: check engine documentation to confirm compound objects can be used for collision.<\/p><\/blockquote>\n<blockquote><p><b>Design note<\/b>: a &#8216;closed&#8217; or &#8216;solid&#8217; mesh would be one where, were it to be filled with liquid, won&#8217;t &#8216;leak&#8217; or &#8216;spill&#8217; its contents regardless as to what&#8217;s done with the object.<\/p><\/blockquote>\n<p><a href=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-concave-form.jpg\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" style=\"width: 100%; height: auto;\" src=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-concave-form.jpg\" alt=\"Concave forms for collision\" width=\"900px\" height=\"500px\" border=\"0\" \/><\/a><br \/>\n<i>The overall form of a collision hull can have concave elements [1] (image: left) so long as it&#8217;s a compound object formed from other valid convex objects (image: right).<\/i><\/p>\n<h3><span class=\"ez-toc-section\" id=\"complex-meshes\"><\/span>Complex Meshes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A complex mesh is generally going to be more accurately shaped to fit the game-object, subject to the requirements discussed above; convex (sur)faces and be a closed mesh. However, because surfaces have to be convex this can mean a certain degree of compromise has to be had to meet the aforementioned requirements. In practice this might mean collision hulls not being quite as accurate as needed while generally being more efficient than other approaches.<\/p>\n<blockquote><p><b>Design note<\/b>: generally speaking most auto-generated solutions to collision hulls will be similar to manually created complex meshes.<\/p><\/blockquote>\n<p><a href=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-complex.jpg\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" style=\"width: 100%; height: auto;\" src=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-complex.jpg\" alt=\"Complex collision meshes\" width=\"900px\" height=\"500px\" border=\"0\" \/><\/a><br \/>\n<i>Complex collision hulls generally match the shape of an object more closely (image: left) but will be subject to the same requires as other approaches; be convex and\/or closed meshes.<\/i><\/p>\n<h3><span class=\"ez-toc-section\" id=\"export-collision\"><\/span>Export Collision<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Generally speaking collision meshes can be exported as part of the same file as the game asset they provide collision surfaces for, as part of the same unified mesh, and essentially identified based on material assignment [2], or as a sub-mesh [3] with their own material assignment. How this is done exactly, will depend on the engine tech used and how they define collision objects and\/or materials; separate object set-ups might require meshes be identified with a tag, pre or postfix that&#8217;s recognised during import, e.g. &#8220;<i>_col<\/i>&#8220;, or similarly for materials.<\/p>\n<blockquote><p><b>Design note<\/b>: collision is generally not visible in-game so UV maps and materials are not strictly necessary, however, they may need to be assigned for completeness and prevent possible mesh\/compiling errors.<\/p><\/blockquote>\n<p><a href=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-joined.jpg\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" style=\"width: 100%; height: auto;\" src=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-joined.jpg\" alt=\"Joined collision\" width=\"900px\" height=\"500px\" border=\"0\" \/><\/a><br \/>\n<a href=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-separate.jpg\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" style=\"width: 100%; height: auto;\" src=\"https:\/\/www.katsbits.com\/images\/tutorials\/collision\/collision-separate.jpg\" alt=\"Separate collision\" width=\"900px\" height=\"500px\" border=\"0\" \/><\/a><br \/>\n<i>Collision hulls will generally be joined to a game object forming a single object (image: top) [2], or be included as a separate sub-mesh (image bottom) [3]. In either instance the label attributed to the mesh or material is used to identify objects or surfaces as collision.<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":7356,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,803,230,831,993],"tags":[995,990,994,800,991,992,996,799,997],"class_list":["post-5746","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blender","category-godot","category-tutorials","category-unity","category-unreal","tag-closed-mesh","tag-collision","tag-compound-object","tag-godot","tag-hulls","tag-primitives","tag-solid-mesh","tag-unity","tag-unreal"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.katsbits.com\/codex\/wp-json\/wp\/v2\/posts\/5746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.katsbits.com\/codex\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.katsbits.com\/codex\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.katsbits.com\/codex\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.katsbits.com\/codex\/wp-json\/wp\/v2\/comments?post=5746"}],"version-history":[{"count":46,"href":"https:\/\/www.katsbits.com\/codex\/wp-json\/wp\/v2\/posts\/5746\/revisions"}],"predecessor-version":[{"id":7367,"href":"https:\/\/www.katsbits.com\/codex\/wp-json\/wp\/v2\/posts\/5746\/revisions\/7367"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.katsbits.com\/codex\/wp-json\/wp\/v2\/media\/7356"}],"wp:attachment":[{"href":"https:\/\/www.katsbits.com\/codex\/wp-json\/wp\/v2\/media?parent=5746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.katsbits.com\/codex\/wp-json\/wp\/v2\/categories?post=5746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.katsbits.com\/codex\/wp-json\/wp\/v2\/tags?post=5746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}