Jump to content

World::getIntersection lag-spike


photo

Recommended Posts

UNIGINE 2.14.1 Community
Windows 10, DX11

World::getIntersection method execution takes much longer than expected when entering relatively complex mesh bounding box.

  1. Create default C++ project named 'getIntersection_lag_on_collision'
  2. Get attached test project 'getIntersection_lag_on_collision'
  3. Merge
  4. Build
  5. Open editor to sync world data
  6. Run, notice lag-spike when nearly fell on the ground

 

getIntersection_lag_on_collision.zip

Edited by trans-literal
Link to comment

trans-literal

To be able to do mesh intersections objects should be placed to the separate spatial tree first. With async nodes loading it's not really possible to tell if the specific object is ready for the intersection or not.

When calling getIntersection() from the main thread you initiate the force load of the intersected objects to the separate spatial tree and you can see the spike at this exact moment.

To avoid this you can do intersection warm-up in init() before the first actual getIntersection() call:

Vector<NodePtr> nodes;
World::getNodesByType(Node::OBJECT_MESH_STATIC, nodes);
for (auto& it : nodes)
{
	ObjectMeshStaticPtr mesh = checked_ptr_cast<ObjectMeshStatic>(it);
	if (mesh)
	{
		ObjectIntersectionPtr oi = ObjectIntersection::create();
		auto bs = mesh->getWorldBoundSphere();
		for (int i = 0; i < mesh->getNumSurfaces(); i++)
		{
			mesh->getIntersection(Unigine::Math::Vec3(-bs.getRadius() * 2.0), Unigine::Math::Vec3(bs.getRadius() * 2.0), oi, i);
		}
	}
}

 

Alternatively you can simply use physics shapes instead (that are currently being ignored in your sample):

const auto intersection = Unigine::PhysicsIntersection::create();
	Physics::getIntersection(
		ray.first, ray.second, ray_m,
		{ root }, intersection);

Thanks!

  • Thanks 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
10 minutes ago, silent said:

To avoid this you can do intersection warm-up in init() before the first actual getIntersection() call:

Would it be safe to force spatial tree filling around player as async call in case of a big scene?

 

15 minutes ago, silent said:

Alternatively you can simply use physics shapes instead

Have not seen this yet, thanks!

Link to comment
Quote

 Would it be safe to force spatial tree filling around player as async call in case of a big scene?

If you really need triangles mesh intersection you can try to call createNodes() in separate thread, but if you will do the mesh intersection from main thread before it finishes you will anyway get a spike. To get a final mesh you can use getMeshStatic().

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
×
×
  • Create New...