Here are some images of what I’ve been doing:
It shows the container model in Blender, as well as some cubes I made to act as collision shapes, then there’s a picture of the container’s convex hull debug draw, and then the custom cubes debug draw.
I had originally just used the Blender UI to get the width/height/depth and x/y/z values for the cubes I made, but I wanted something a little more automatic, so I threw together some python that generated some xml from obj files:
obj = read_wavefront(args.file)
for key, value in obj.items():
print(f'Processing {key}')
v = value['v']
data = {
'MinX': 99999,
'MinY': 99999,
'MinZ': 99999,
'MaxX': -99999,
'MaxY': -99999,
'MaxZ': -99999,
}
for vertex in v:
if vertex[0] < data['MinX']: data['MinX'] = vertex[0]
if vertex[1] < data['MinY']: data['MinY'] = vertex[1]
if vertex[2] < data['MinZ']: data['MinZ'] = vertex[2]
if vertex[0] > data['MaxX']: data['MaxX'] = vertex[0]
if vertex[1] > data['MaxY']: data['MaxY'] = vertex[1]
if vertex[2] > data['MaxZ']: data['MaxZ'] = vertex[2]
width = data['MaxX'] - data['MinX']
height = data['MaxY'] - data['MinY']
depth = data['MaxZ'] - data['MinZ']
x = data['MinX'] + width / 2.0
y = data['MinY'] + height / 2.0
z = data['MinZ'] + depth / 2.0
x = -x
print(f'<box width="{width:.2f}" height="{height:.2f}" depth="{depth:.2f}" x="{x:.2f}" y="{y:.2f}" z="{z:.2f}" />')
which generated this xml file for me:
<?xml version="1.0"?>
<shapes>
<box width="0.30" height="0.50" depth="0.70" x="-1.25" y="2.27" z="1.87" />
<box width="2.13" height="2.38" depth="5.94" x="0.01" y="1.20" z="-0.01" />
</shapes>
which I then load via:
XMLElement root = file->GetRoot();
if (root.GetName() != "shapes")
return;
for (XMLElement element = root.GetChild("box"); element.NotNull(); element = element.GetNext("box"))
{
auto shape = node->CreateComponent<CollisionShape>();
shape->SetBox({ element.GetFloat("width"), element.GetFloat("height") , element.GetFloat("depth") }, { element.GetFloat("x"), element.GetFloat("y"), element.GetFloat("z") });
}
Convex hulls are a good alternative when I don’t need something specific, but I like being able to add specific CollisionShape component configurations graphically.
All in all I’m super happy with what I can do now using Blender and Urho3D.