Jump to content
  • entries
    51
  • comments
    106
  • views
    27,845

Custom Shapes for MDLs in Leadwerks 4


reepblue

3,368 views

 Share

There has been some discussion regarding on how to set collision shapes for your models. For 95% of models, you should be building shapes with the Model Viewer as described here. In some cases, the model artist might want a custom shape to be made. In this post, I'll be going over how I import models into Leadwerks, and building custom shapes.

A few notes first. I use Blender; Blender 2.79b to be exact. I haven't get got the hang of 2.80 and until the new engine's art pipeline is fully online, I don't see a use for it. Leadwerks 4 uses Blinn-Phong rendering so the PBR stuff makes no sense for Leadwerks 4. So for this, I'll be posting screenshots from 2.79b. I should also mentioned that a feature I use in my process isn't present in the Linux build of the editor, which is the collapse tool. (Tools->Collapse). Doing the collapsing via a terminal will cause the models to crash the editor. This seems to be a known bug, as you don't see that feature in the Linux editor.

Lets say you created a tube model such as this one and you want the player and objects to go into the tube:

image.png.00fff9f9046eea6ff6b06c967fd785c7.png

If you tried to make a shape doing the Concave settings, not only it'll be really slow to generate, but the results will not be good. We could make a shape based on the wire frame, but this is a high poly model. What we need to do is make a new mesh, import both models  to the editor, collapse them both, build the shapes for both, and delete the low poly model while making the high poly read the low poly's generated shape.

 

First to get it out of the way, apply the scale and rotation of the model. This will make Y forward and the scale will be (1,1,1) when you import it into Leadwerks.

image.png.c0aa009033b9d5b95d48f187bb9779de.png

 

Next we need a low poly model.

image.png.b57e9c95d96c2d960d3f0a87ebc01bf3.png

This is the same proportions as our high poly. Apply the scale and rotation as the same as the high poly. I also set the max draw time to solid, but this is optional.

image.png.56529bf49581988f6902d4c733087745.png

Next, name your High poly and the low poly you're going to be using for the shape appropriately.

image.png.5e0d319c9e6b07e25966c6ffc7bad225.png

Now lets, export each object as a FBX. For this my high poly is going out as tube.fbx, and my low poly shape is going out as tubeshape.fbx. Here are my export settings:

mdlexport.PNG.77056260d8c71cbcdf76279a67bedf52.PNG

If you saved the files in a Leadwerks project while the editor was opened, the editor would have auto convert the files to the .mdl file format. Open the high poly model (tube.fbx) and first collapse it and give it any shape. (Give it a box shape to save time.) you need to assign a shape to the high poly so the mdl file is linked to a phys file. Do the same with the low poly, but you're gonna set the shape as poly mesh.

image.png.770e8677575ac0349292809329845b68.png

image.png.c7a0526b661368a5bbe1d2dc14379141.png

Close the model viewer, and then go into the directory where the models are placed. We are now going to delete the box shape of our high poly, and trick it into loading the low poly shape by renaming the shape file of the low poly to be what the previous shape of the high poly was. In other words, we are making tubeshape.phy into tube.phy.

Before:

image.png.bf66743c493d19d285b3d3e5a8b234fd.png

After:

image.png.8eb3788405c60c62581fc9b25dbdf40f.png

Notice the time stamp and the size of tubeshape.phy from before being the same as tube.phy in the after screen cap. This should be your end result.

image.png.0b61b17c4a9904f6ca24f176b6aa7d36.png

Notice that the shape isn't sold but now a tube. Objects can go into the tube with no issues. Now, there is another way that uses limb names to generate physics automatically. However, there are a lot of issues I came across using this method such as the shape not being parented to the model when the model moved via physics or a joint. With this way, you have a custom shape, the model is optimized because it doesn't have any children nodes, and everything is clean and tidy!

image.png.cf64a36673fcabc41b95a788415600c1.png

 

  • Like 6
 Share

5 Comments


Recommended Comments

2 minutes ago, gamecreator said:

It seems to do something similar but gives different results than the options in the model editor.  I'm a little confused.  ?

That seems to be a legacy feature before the model viewer could generate shapes. Don't use that.

  • Confused 1
Link to comment

Hmmm.  Here's what generate convex hull creates for a test scene:

convexhull_generate.jpg.ff2a1f57cd332aade4e394dad345963d.jpg

And here's what convex hull in the model editor creates:

convexhull_editor.jpg.b29da3fafed1379593e2f2b1b930238c.jpg

Edit: it seems like that for the model editor, Josh removed the consideration for multiple children and treats the entire model as one.

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...