Jump to content

Colliders in Ultra Engine


Josh

3,310 views

 Share

Attention: The addition of our custom model file format has changed the way this system works. Colliders are now saved into the Ultra MDL file.

I haven't been blogging much because I am making so much progress that there would be too much to cover. In this article I will talk about one little system I spent the last week on and show the improvements I have made to the workflow over Leadwerks.

In the asset editor, when the root of a model is selected, a "Collider" field appears in the physics properties. You can use this to quickly calculate and apply a collider to the model.

image.thumb.jpeg.dfb588a2391ba3c40a345955b401bd9a.jpeg

The convex hull collider includes an option for tolerance. You can adjust this to get a more or less precise convex hull around the model:

image.thumb.gif.3930737397bba368278ed60725903eee.gif

There is also an "optimize" option for the mesh collider. When this is activated it will attempt to merge adjacent coplanar polygons into a single face, and can result in fewer seams on colliding faces.

Two new shapes are included, the capsule and the chamfer cylinder, so now all the shapes supported by Newton Dynamics are available. (The chamfer cylinder is good for vehicle tires.)

image.jpeg.33bb742b7fabc2a9899335922e9f994e.jpeg image.jpeg.e569adfd0a4c6cbd50fd41dcc91d944a.jpeg

Unlike Leadwerks, you no longer need to specify the axis cylindrical shapes are oriented around. The editor will calculate which bounding box axes are most like each other, and use the third axis to orient the shape. This works for long skinny objects:

image.thumb.jpeg.64fda76f0ca50ee9f97194f774837f5b.jpeg

And it also works for short fat objects:

image.thumb.jpeg.e48c770c650c9ae7fa405153e8caa423.jpeg

It will even detect which direction a cone should be facing, by calculating the total distance from the shape the model vertices are with each direction, and selecting the orientation with the smallest error value. (A single cone is probably not the best choice of shape for this model, but the point is that it correctly guesses which direction the cone should point based on the model vertices.)

image.thumb.jpeg.6f1ddb4a704e35dd45358a3307374203.jpeg

For more advanced geometry, the convex decomposition tool is available in the Utilities panel. This exposes all the parameters available in V-HACD 4.0 and processes the task on a separate thread so you can continue to use the editor as the task runs in the background. It usually only takes a few seconds to compete, but it is nice to not have your workflow interrupted:

image.thumb.jpeg.70c868009518c34f54436c9ed3e7a4e9.jpeg

You can export colliders as model files, so it's also possible to just use this to generate convex hulls and export them to .obj. (I could get a better fitting shape if I spent more time adjusting the settings, but I just quickly made this shape with very low settings in order to get this screenshot.)

image.thumb.jpeg.897b562ae7186c01adf023147c4ae95c.jpeg

The new .collider file format, like everything else in Ultra, is JSON-based. Simple shapes can be stored in pure ASCII text, so they can be edited by hand if needed:

{
	"collider": {
		"parts": [
			{
				"offset": [
					0.0024815797805786133,
					-0.18715500831604004,
					-1.055002212524414e-05
				],
				"rotation": [
					0.0,
					0.0,
					0.0
				],
				"shape": "BOX",
				"size": [
					1.8899539709091187,
					2.0,
					1.8019688129425049
				]
			}
		]
	}
}

More complex shapes like convex hulls and meshes use binary data appended to the end of the file to store their contents, so that they load quickly in the engine:

{
	"collider": {
		"parts": [
			{
				"data": 0,
				"shape": "CONVEXHULL",
				"vertices": 61
			}
		]
	}
}�n2��<�5jk��#�I3��ch�������=b[��I<��~dID�` �[�\{4���A���?XO3���>��վ�v!���f���	?]����I�!�����V >�?���mdGt9a��@���X?W��0o��e�-�D��hP?>����>��׾���@��=TU?��ž�{����w�� ���G��3��ޑ?>V?c�����;���6s�/?&�=����?qe?j��N���[#b��bݽ(��>��Ǿ�ڽ�E��MV�ַؽ��8<�G������D?BYT?I���@"N?6?�";-�$?��콜�";��t>8�"t";�z��3�0���";����ݐ�)�%=}P?��0?���=/�E?BYT?'>�=�E��MV����={;
?"����>�־��c
�>��?qe?�$>�ӽ��P��@>��,?�j|=�2�>[o/���PC��>��?>V?Z�>�������Қ�>��h���@�>��ECO2��.�>T��[Ay]�>L��=TU?w4�>���>�쾛?#o��e�-�r?�����U?�"?.�v>��!?�R?�zv����>�@?(�0S
�>.(?�n_C�?�|-?d�[��}?��4?��>��վ��6?2M4��*?�>?P��=_s��F?V ���ྲAm?�#�I3Lr?�����

Leadwerks .phy collider files can also be loaded.

Notice in the shots above, in the drop-down menu there is also a "Browse" option, so you can create a collider file with a low-resolution model and then load the resulting collider to use with a high-resolution model.

I think this design strikes the right balance to let you do simple things quickly, but still allow for more advanced options when you need them. In the future I would like to add an additional in-depth collider editing utility that would allow you to select each sub-object, select model polygons and generate shapes just from those polys, and other advanced features.

The pick mode feature has been revised. The original design was based on Blitz3D, which did not support collision primitives at all. Instead of specifying a sphere or other shape for picking, you can now just tell the entity to use the collider for picking. (PICK_SPHERE is removed.)

On an unrelated note, I had to adjust the camera range based on the distance from the model being viewed, in order to make very small objects visible. This allows extreme close-up shots like in the blog header image that you probably aren't used to seeing except in VR. It's kind of interesting.

  • Like 1
  • Upvote 1
 Share

12 Comments


Recommended Comments

Please add a OBJ to Collider feature so I can pre-make my colliders in blender without doing the work arounds I had to do with Leadwerks. It's really helpful for tubes and my button base model.

Everything else looks good though. 

Link to comment

You can open an OBJ file in the asset editor and create a convex hull from that, then save it to the file you want.

Link to comment
5 minutes ago, Josh said:

You can open an OBJ file in the asset editor and create a convex hull from that, then save it to the file you want.

I prefer that step is skipped. Also a "Load/Set Collider" option is missing. I don't want to rename/replace files because it seems like I'm "hacking" the system. 

Link to comment

There is a "browse" option in the collider drop-down, but you raise a good point. The current design follows how mesh materials and material textures work. With those items, there are multiple files that might be applied to one asset in one window. However, with colliders there is only one collider per model. So that might be a justification why a menu item for the window is the better option.

I'm dragging my feet on your request to load colliders directly from models because:

  • Colliders loaded from models could be a Newton tree collision (mesh) or convex hull(s).
  • Convex hulls have a tolerance value to control exactly how precise/detailed the hull is.
  • Collision trees have an optimize parameter to control whether adjacent faces get merged.

These options are all available in the current interface. In order to support them in a model loading step, I would need to duplicate all this functionality in a new interface. It is strange to implement the same feature twice.

Link to comment

Wait, could it be possible to have this done as an editor addon? As an end user, I could probably write this if I know the needed functions are exposed.

I need it to do the following.

  1. Load a model (OBJ, MDL, etc) from anywhere on the computer.
  2. Set a "Target Model" for the new collider to be applied to.
  3. Generate a collider from the polymesh. 
  4. Save the collider to the disk and set the target model to it.
  5. Disregard the OBJ. 

It's a little hacky, but it's much better than generating a throw way collider, importing a model just for the collider, and then renaming files so the game model loads the manual made collider. I only would need this for tubes and such. I also would need to know if I have the ability to edit the model file itself and not the current instance. 

Link to comment

Well, yeah, you can do pretty much anything as an extension. :)

So you are saying that if I was to choose one way to do this, you are usually loading mesh colliders (static), not convex hulls? 

Link to comment
10 minutes ago, Josh said:

So you are saying that if I was to choose one way to do this, you are usually loading mesh colliders (static), not convex hulls? 

I mean, I mostly need this to make concave collision meshes for things like door frames, tubes, and things like my button base model which are normally static objects. The convex hulls make what should be simple busy. 

image.thumb.png.9d395cd9d360ad3725f90a055699ef55.png

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...