#Reducing the complexity of colliders

1 messages · Page 1 of 1 (latest)

harsh imp
#

Hello Needle,

I was recently using colliders on complex objects, so I used the convex property.
However I was using low poly versions of my objects, in order to gain visual precision I've used the same objects recently (with 10x more vertices). Three js handles it well but less quickly, because the colliders have also become more complex, which slows down the application. Is it possible to reduce the complexity of the colliders generated?

finite locustBOT
wind meteor
#

You can use MeshColliders and assign your low poly mesh that you used before.

harsh imp
#

I found another solution :

if(this.userSimplifier && geometry.isBufferGeometry) {
        // Calcul du nombre de vertices à conserver
        const count = Math.floor(geometry.attributes.position.count * this.simplifierIndice);
    
        // Création d'une nouvelle BufferGeometry
        const newGeometry = new THREE.BufferGeometry();
    
        // Supposons que vous réduisez le nombre de vertices en conservant uniquement une portion de l'array original
        const positions = geometry.attributes.position.array.slice(0, count * 3); // Multipliez par 3 car chaque vertex a 3 composants (x, y, z)
        newGeometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(positions), 3));
    
        // Notez que cela ne prend pas en compte les indices des faces, les normales, les UVs, etc.
        // Vous devrez ajuster ou reconstruire ces attributs si nécessaire
    
        // Utilisation de la géométrie simplifiée pour le collider
        collider.convex = true;
        collider.sharedMesh = new THREE.Mesh(newGeometry, new THREE.MeshBasicMaterial());
    } else {
        collider.convex = true;
        collider.sharedMesh = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial());
    }
#

But it generates me a warning

wind meteor
#

What does this do? it look to me as if it is just creating a new mesh and not changing anything and not simplifying the mesh in any way

harsh imp
#

Oh yes, I found this solution on internet but it simplified the collider but there is not reason for that
Will look at it

#

Ok, in fact I get only a shard of the original mesh by using const count = Math.floor(geometry.attributes.position.count * this.simplifierIndice);

wind meteor
wind meteor
harsh imp
#

Yes you right

#

But it simplifieds the mesh, seems like

#

I will try to load simplified version of the mesh to prevent it but if I could simplify the same objet directly by code it could be better, because I need less object loading

wind meteor
harsh imp
#

In fact I load my objects from urls, knowing that my objects that aren't low poly are easier for me to obtain directly from a compressed glb file.
My low poly files are at another url, in a different form, so I have to load them in addition to the file I'm currently using.

#

I will work on a script to add directly in the same file the low polies version of each mesh

harsh imp
#

I try to but this is difficult to use another mesh to be used as collider shareMesh for a main mesh x)

If there is a possibility to decrease the convex collider complexity I take it