lo-th / phy

Physics for three. Game engine
https://lo-th.github.io/phy/
MIT License
514 stars 42 forks source link

Problems with InstancedMesh after phy.remove #26

Open fatbatman opened 9 months ago

fatbatman commented 9 months ago

Create some objects that make use of InstancedMesh

        let test = []
        for(let i=0; i < 100; i++) { 
            test.push(phy.add( { type: 'cylinder', size:[1,1], instance:'someObj', mesh:aMesh, pos:[0,i,0]} ))
        }

Then remove some.

        setTimeout( () => {
            for(let i=0; i < 100; i+=2) { 
                phy.remove(test[i].name)
            }            
        }, 2000)

The mesh of the removed objects remains in view.

I've also seen an issue where the remaining instances then flicker in and out of view.

lo-th commented 7 months ago

i will look but i+=2 seems wrong ?

fatbatman commented 7 months ago

It's meant to illustrate there is an issue if you remove some of them, not just the first or last added.

lo-th commented 7 months ago

i see yes, i have to find better method without id because normally three instance is not made for add and remove instance

lo-th commented 7 months ago

ok remove on instance should be fixed.

fatbatman commented 7 months ago

I'm still seeing problems when I use instance.
I end up with lots of meshes floating in the scene that are no longer being moved by physics.
Other that flash in and out of visibility. I see this with Havok and Physx.

lo-th commented 7 months ago

do you readd object on same instrance ? is maybe a problem of name

fatbatman commented 7 months ago

I see that's the problem, I wasn't giving them a name.
If I give them a unique name it works fine.

The only reason I'd say this is still a bug is because it works correctly when instance is not specified.

fatbatman commented 7 months ago

I've just noticed that if I also add other objects that have a different mesh and are not using an instance, these flicker and disappear / swap places.