{"action":"created","issue":{"url":"https://api.github.com/repos/mosra/magnum-integration/issues/20","repository_url":"https://api.github.com/repos/mosra/magnum-integration","labels_url":"https://api.github.com/repos/mosra/magnum-integration/issues/20/labels{/name}","comments_url":"https://api.github.com/repos/mosra/magnum-integration/issues/20/comments","events_url":"https://api.github.com/repos/mosra/magnum-integration/issues/20/events","html_url":"https://github.com/mosra/magnum-integration/issues/20","id":176843111,"number":20,"title":"BulletIntegration: conversion of Magnum mesh data into Bullet collision mesh [snippet]","user":{"login":"mosra","id":344828,"avatar_url":"https://avatars0.githubusercontent.com/u/344828?v=3","gravatar_id":"","url":"https://api.github.com/users/mosra","html_url":"https://github.com/mosra","followers_url":"https://api.github.com/users/mosra/followers","following_url":"https://api.github.com/users/mosra/following{/other_user}","gists_url":"https://api.github.com/users/mosra/gists{/gist_id}","starred_url":"https://api.github.com/users/mosra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mosra/subscriptions","organizations_url":"https://api.github.com/users/mosra/orgs","repos_url":"https://api.github.com/users/mosra/repos","events_url":"https://api.github.com/users/mosra/events{/privacy}","received_events_url":"https://api.github.com/users/mosra/received_events","type":"User","site_admin":false},"labels":[{"id":441635403,"url":"https://api.github.com/repos/mosra/magnum-integration/labels/improvement","name":"improvement","color":"0e8a16","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-14T08:15:22Z","updated_at":"2017-03-20T23:09:46Z","closed_at":null,"body":"As @Squareys mentioned in #19, here's his code snippet for creating Bullet collision mesh directly from Magnum mesh data, licensed under CC0: https://groups.google.com/forum/#!topic/magnum-engine/V3iL35umkwU\n\n> ``` cpp\n> /* source mesh, a valid pointer to data which needs to persist\n>  * for the resulting shape to stay valid */\n> MeshData3D* mesh = /* ... */;\n> /* resulting shape */\n> btCollisionShape* shape = nullptr;\n> \n> /* this code only works for Triangles only meshes */\n> if (mesh->primitive() == MeshPrimitive::Triangles) {\n>   /* create a bullet indexed mesh from our mesh data */\n>   btIndexedMesh bulletMesh;\n>   bulletMesh.m_numTriangles = mesh->indices().size()/3;\n>   bulletMesh.m_triangleIndexBase = (const unsigned char *)mesh->indices().data();\n>   bulletMesh.m_triangleIndexStride = 3 * sizeof(UnsignedInt);\n>   bulletMesh.m_numVertices = mesh->positions(0).size();\n>   bulletMesh.m_vertexBase = (const unsigned char *)mesh->positions(0).data();\n>   bulletMesh.m_vertexStride = sizeof(Vector3);\n>   bulletMesh.m_indexType = PHY_INTEGER;\n>   bulletMesh.m_vertexType = PHY_FLOAT;\n> \n>   btTriangleIndexVertexArray *pTriMesh = new btTriangleIndexVertexArray();\n>   pTriMesh->addIndexedMesh(bulletMesh, PHY_INTEGER);\n> \n>   shape = new btBvhTriangleMeshShape(pTriMesh, true, true);\n> } else {\n>   Error() << \"Unsupported mesh primitive type while converting Magnum mesh to Bullet mesh.\";\n> }\n> ```\n> \n> Since btConvexHullShape is more efficient with smaller meshes (see http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Shapes#Meshes) here is another code snippet which you can replace the contents of the if block with:\n> \n> ``` cpp\n> shape = new btConvexHullShape((const btScalar *)mesh->positions(0).data(), mesh->positions(0).size(), sizeof(Vector3));       \n> ```\n> \n> Note that it is recommended to use meshes of less than around 100 vertices for bullet convex hulls (see the link above). Also, convex hulls are, obviously, convex. They might not be suited for you individual collision mesh. (Also note, that I didn't test that line very much)\n\nJust putting it here since the Google Groups forum seems to be quite abandoned now (which I completely understand, the UI is horrible). I think this snippet may even be useful and general enough to include directly in the Bullet Integration library.\n"},"comment":{"url":"https://api.github.com/repos/mosra/magnum-integration/issues/comments/287926527","html_url":"https://github.com/mosra/magnum-integration/issues/20#issuecomment-287926527","issue_url":"https://api.github.com/repos/mosra/magnum-integration/issues/20","id":287926527,"user":{"login":"mosra","id":344828,"avatar_url":"https://avatars0.githubusercontent.com/u/344828?v=3","gravatar_id":"","url":"https://api.github.com/users/mosra","html_url":"https://github.com/mosra","followers_url":"https://api.github.com/users/mosra/followers","following_url":"https://api.github.com/users/mosra/following{/other_user}","gists_url":"https://api.github.com/users/mosra/gists{/gist_id}","starred_url":"https://api.github.com/users/mosra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mosra/subscriptions","organizations_url":"https://api.github.com/users/mosra/orgs","repos_url":"https://api.github.com/users/mosra/repos","events_url":"https://api.github.com/users/mosra/events{/privacy}","received_events_url":"https://api.github.com/users/mosra/received_events","type":"User","site_admin":false},"created_at":"2017-03-20T23:09:46Z","updated_at":"2017-03-20T23:09:46Z","body":"Yup, why not? :)"}}
{"actor":{"display_login":"mosra"}}