trans-literal Posted October 29, 2021 Share Posted October 29, 2021 (edited) UNIGINE 2.14.1 Community Windows 10, DX11 World::getIntersection method execution takes much longer than expected when entering relatively complex mesh bounding box. Create default C++ project named 'getIntersection_lag_on_collision' Get attached test project 'getIntersection_lag_on_collision' Merge Build Open editor to sync world data Run, notice lag-spike when nearly fell on the ground getIntersection_lag_on_collision.zip Edited October 29, 2021 by trans-literal Link to comment
silent Posted November 1, 2021 Share Posted November 1, 2021 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! 1 How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
trans-literal Posted November 1, 2021 Author Share Posted November 1, 2021 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
silent Posted November 1, 2021 Share Posted November 1, 2021 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: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Recommended Posts