UPBGE / upbge

UPBGE, the best integrated game engine in Blender
https://upbge.org
Other
1.45k stars 180 forks source link

overlap function for BVHtree not working in BGE #786

Closed RomStef closed 6 years ago

RomStef commented 6 years ago

as i said in the title , when i call the overlap function of BVHtree for testing overlapped faces between two different BVHtree the programm says the object has no attribute 'overlap'

lordloki commented 6 years ago

Could you attach a little example?

panzergame commented 6 years ago

I could not reproduce this bug on linux with:

mesh = …
mesh.constructBvh().overlap(mesh.constructBvh())
RomStef commented 6 years ago

with no example , i have try just like the mathutils BVHtree :

""" import bge import mathutils

Objects

water = bge.logic.getCurrentController().owner terrain = bge.logic.getCurrentScene().objects['terrain']

Meshes

waterMesh = water.meshes[0] terrainMesh = terrain.meshes[0]

BVHtrees

waterBVHTree = waterMesh.constructBvh terrainBVHTree = terrainMesh.constructBvh

Test overlapped faces

overlappedFacesList = terrainBVHTree.overlap(waterBVHTree) overlappedFacesList.sort()

print(overlappedFacesList) """

where water and terrain are two intersected planes

RomStef commented 6 years ago

i have missed the brackets , sorry

RomStef commented 6 years ago

Sorry, i have to return on this issue because the overlap function work but don't return any value. here an example : [Uploading test_bvh_overlap.zip…]()

panzergame commented 6 years ago

@RomStef : the file link seems incorrect.

RomStef commented 6 years ago

test_bvh_overlap.zip

panzergame commented 6 years ago

The BVH is construct from the mesh and can't include the object transformation because meshes are shared. In your example file, the water plane have a transformation and without it it doesn't intersect the ground. Applying the location on the plane mesh is fixing the issue.

Though a lot of people will encounter this issue, @RomStef, @BluePrintRandom: Do you think interesting to pass a matrix to constructBvh to represent the object transformation ?

panzergame commented 6 years ago

@RomStef, @BluePrintRandom ?

BluePrintRandom commented 6 years ago

Maybe a bool, world or local?

when the tree is built, decide on world or local?

alternatively we just localize the transform of the input to object space.

local = object.worldOrientation.inverted()* ( point - object.worldPosition)

panzergame commented 6 years ago

The mesh can't get a world transform as it is shared across objects, I will make PR tonight for passing a matrix.

vlad0337187 commented 5 years ago

Strange, but in my case, seems, player and some cubes intersect always, regardless they don't actually intersect.

Example: https://www.youtube.com/watch?v=4Lsk84Gb9TY

Here you see, that BVHTree always says that there are some intersected faces, but if you'll look to coordinates, than you'll see that they'll be the same only when I jumped on one of that blocks.

Can somebody tell me, what I'm doing wrong ?)

BluePrintRandom commented 5 years ago

Are you transforming the bvhtree to the correct world space?

On Thu, Nov 29, 2018, 6:58 PM Vladislav <notifications@github.com wrote:

Strange, but in my case, seems, player and some cubes intersect always, regardless they don't actually intersect.

Example: https://www.youtube.com/watch?v=4Lsk84Gb9TY

Here you see, that BVHTree always says that there are some intersected faces, but if you'll look to coordinates, than you'll see that they'll be the same only when I jumped on one of that blocks.

Can somebody tell me, what I'm doing wrong ?)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/UPBGE/blender/issues/786#issuecomment-443073995, or mute the thread https://github.com/notifications/unsubscribe-auth/AG25Wcq73llyhW68EiViKk2fBLFWZPsnks5u0J7ngaJpZM4V4bTa .

vlad0337187 commented 5 years ago

@BluePrintRandom , ah, no. Thanks ) I missed that, I thought, that it was fixed in PR to account that transfor automatically =)