grire974 Posted October 22, 2015 Share Posted October 22, 2015 Hi All, I'm working on something I'd like for my project; specifically I want to nest one mesh inside another and have collision detection (e.g. like the dice in a dome in the trouble board game http://www.boardgamescritic.com/wp-content/uploads/2010/10/trouble-board-game-board.jpg ). I've read all the physics related tutorials for cannon and Oimo, seemed to get further (not far) with Oimo; so sticking with that so far. Have also looked at all of the relevant demos I could find. I have a playground which illustrates the efforts I've made so far: http://www.babylonjs-playground.com/#1SZYKZ#2 As you'll see; gravity affects the cube. However I'd like the cube to stop when it collides with the sphere; so it never leaves the sphere. I'd like the sphere to remain static (or at least not move) which is why i've set its mass to 0 per the tutorials. Eventually if I shake the sphere, the cube would bounce around inside the sphere (first things first). Any advice would be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
Temechon Posted October 23, 2015 Share Posted October 23, 2015 i don't think physics works inside another mesh...If I were you, I would remove the physics state on the sphere, and create 5 planes around the sphere, and set these planes invisible. This way, the shaking thing will be very easy to do grire974 1 Quote Link to comment Share on other sites More sharing options...
Convergence Posted October 23, 2015 Share Posted October 23, 2015 How about invert normals on the container? I would assume the physics engine obeys the normals. grire974 1 Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 23, 2015 Share Posted October 23, 2015 As far as I know, the engines don't even use the normals. Interesting enough, the native collision system of Babylon DOES. So you might be more succesful with moveWithCollisions after inverting normals. grire974 1 Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 23, 2015 Share Posted October 23, 2015 After a quick check - This will work with a sky-box cube, but won't work with a singe sphere. I try playing with it, but seems like the object first wants to "get out" of the bounding sphere. grire974 1 Quote Link to comment Share on other sites More sharing options...
iiceman Posted October 23, 2015 Share Posted October 23, 2015 Hmm.. you can keep it in the sphere with moveWithCollisions if you sue a hollow sphere: http://www.babylonjs-playground.com/#1UQFFF ... but doesn't look like it will achieve the desired end result.. would be cooler with physics. What about building a fake sphere out of physics planes that form a sphere like shape. Then hide the planes and just show the sphere mesh. Collisions bounce of the (hidden) planes and for the user it looks like it bounces of the sphere? grire974 1 Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 23, 2015 Share Posted October 23, 2015 yeah, I actually thought the same :-) Simple boxes around the sphere. Should be very interesting to see :-) grire974 1 Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted October 23, 2015 Share Posted October 23, 2015 Or simply like this : http://www.babylonjs-playground.com/#1UQFFF#1Wouldn't that be ok ? grire974 and Temechon 2 Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted October 23, 2015 Share Posted October 23, 2015 ehhrm... I'll just be leaving now... :lol: grire974 1 Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 23, 2015 Share Posted October 23, 2015 That's good enough, but you will have to make the cube move. Enjoy your weekend! grire974 1 Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 23, 2015 Share Posted October 23, 2015 Oh, that was fun :-) http://www.babylonjs-playground.com/#1SZYKZ#5 Click on the canvas to see the nice physics effect. adam and grire974 2 Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted October 23, 2015 Share Posted October 23, 2015 On some parts of the sphere, your invisible planes are not paralell to sphere surface (so in some cases the dice rebounds strangely, and sometimes it goes out of the sphere) Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 23, 2015 Share Posted October 23, 2015 Oh wait, it seems like I saved some test phase.Ahhh....repairing :-) Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 23, 2015 Share Posted October 23, 2015 So, Oimo is to blame, I need to see why it is changing the rotation after setting it correctly... Here - http://www.babylonjs-playground.com/#1SZYKZ#6 EDIT - Problem found, Oimo plugin updated, this hack is not needed starting next update! iiceman 1 Quote Link to comment Share on other sites More sharing options...
iiceman Posted October 23, 2015 Share Posted October 23, 2015 http://www.babylonjs-playground.com/#1SZYKZ#7 Very cool and fun to play around with. Sometimes the slip trough if the cubes are too small somehow. Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 23, 2015 Share Posted October 23, 2015 Mkae everything bigger :-) http://www.babylonjs-playground.com/#1SZYKZ#8 Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted October 23, 2015 Share Posted October 23, 2015 And now it's time for lottery draw :lol: Quote Link to comment Share on other sites More sharing options...
iiceman Posted October 23, 2015 Share Posted October 23, 2015 http://www.babylonjs-playground.com/#1SZYKZ#10 Can we make a snow globe? Quote Link to comment Share on other sites More sharing options...
grire974 Posted October 23, 2015 Author Share Posted October 23, 2015 WOW! I think this is the most response I've ever had from a post on any discussion forum EVER (tried to like everyone's posts - but apparently I'm being too positive). Thanks all - @iiceman Interesting you say that; my end goal is to actually build a snow globe for my company's christmas mail out this year; thought I'd start with something simple and then move into a solid particle system; but I probably should have mentioned my end goal rather than comparing it to the trouble board game. @RaananW - I'll give you the solved vote as this gives me a lot to consider + answers my initial question; even though it doesn't look like it can power a snow globe (which stupidly I didn't mention). Will keep playing with this and post back if I come up with any enhancements. Thanks again! @Vousk-prod ; lol Vousk-prod. 1 Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted October 23, 2015 Share Posted October 23, 2015 Could SPS be used for this snow case with physics enabled ? (@jerome ?) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 23, 2015 Share Posted October 23, 2015 No SPS generates only one mesh Quote Link to comment Share on other sites More sharing options...
jerome Posted October 23, 2015 Share Posted October 23, 2015 Yep, only one mesh You can access to every particle and its own position, rotation, scale (even its previous and next neighbour in the particles array) within the global mesh... but it's only a mesh.So you need to compute your own physics if you want to apply it to the SPS particles. Quote Link to comment Share on other sites More sharing options...
grire974 Posted January 23, 2016 Author Share Posted January 23, 2016 Hi All, Just to follow up with my final outcome; I did get something kinda working. The tangental plane idea is a good one; however as noted - its a leaky collider (esp if you want small snow flake sized physics particles); I ended up getting something working more reliable by setting overlapping tangental spheres - which wasn't leaky at all. Outer cube colliders also work; but its the whole square peg round hole thing; just make sure the edges of your cubes are overlapping. The main problem for me in the end was performance; my mac pro tower started to chug with more than 100 snow flakes; which even then looked sparse. Here's a quick and dirty example of it working though (sorry code is not clean whatsoever): http://proofing.tbadigital.com/xmas2015/model.html In the end - the thoughtfulness of the solution was lost on my colleagues who just wanted more snow; so this is what we finished with (#copout) (and no - I didn't write the poem if that's what you're wondering : http://xmas.tbadigital.com/ Thanks for all of your help! jerome, iiceman and RaananW 3 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 24, 2016 Share Posted January 24, 2016 So cute!!! grire974 1 Quote Link to comment Share on other sites More sharing options...
RaananW Posted January 25, 2016 Share Posted January 25, 2016 Just wanted to share a nice experiment: http://www.babylonjs-playground.com/#1SZYKZ#13 This is what you can achieve using the newly added MeshImpostor (using cannon.js) - a doublesided sphere uses the mesh impostor and can now contain other spheres inside of it. Expect some more physics surprises in 2.4 iiceman, jerome and GameMonetize 3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.