[SOLVED] Optimize mesh collision

Hi, I’m trying to load a complicated mesh and add collision to it. I’m doing it like so:

var url = "./Isle.glb";
app.assets.loadFromUrl(url, "container", function(err, asset) {
    var entity = new pc.Entity();
    entity.addComponent("model", {
        type: "asset",
        asset: asset.resource.model,
        castShadows: true
    });
    entity.addComponent("collision", {
        type: "mesh",
        asset: asset.resource.model
    });
    app.root.addChild(entity);
    entity.setLocalScale(10,10,10);
});

The mesh is a minecraft-style map made up of a lot of voxels. It takes 3~4 seconds to load without collision and makes my phone lag a bit. When I add the collision component, the game simply freezes.

Is there a way to add collision data to the file itself so I don’t have to do it at runtime. Also is there a better way to optimize it?
Thanks.

How many polys is the model? Do you have a runnable version uploaded to take a look at?

Well it is pretty big.
The .glb file is 92 mb.

When I try a smaller model. It loads properly but still lags. This one is 715kb.

If you still want I can upload it to github.

In which case, the collision model should be a simplified version of what players see.

Usually in games, the collision mesh and visual mesh are two separate models with the collision mesh being massively simplified.

What do you mean by lags?

Very low fps

It shouldn’t do, can you post a live example please?

https://gamerwael.github.io/playcanvas-test/

I had a chance to look at this, the issue is that the dynamic rigidbody is a mesh which is very expensive. I recommend using compound collision primitive shapes instead.

1 Like

Thanks a lot. I’ll try that.