Use Jmonkey as a processing unit to detect collisions

Hello monkeys from all around the world !

I’m here today to ask you a design question for an application that I’m currently doing at my work. It’s something where I need your point of view as a monkey to tell me if what I’m thinking is feasible, and if of course, you have any other ideas not only related to jmonkey.


Well I’ll try to explain it in simple terms ( and be concise too),

  • In the client application (in the browser) I use AngularDart in addition to ThreeJS to display a 3D model and give the user an interface to manipulate the 3D model and do things with it.
  • The client application is connected to a SpringBoot API that do things for him (connected to client using Swagger).
  • The 3D content is only a part of a greater file that contains a lot of information so I use the API convert this file into 3D datga that can be displayed into the browser using ThreeJS.
  • I also use the API to fetch the informations…

(Enough with this crappy things !)

Where do I need JMonkey ?

I need to implement an API endpoint that detect if there is any collisions (or intersection) between the objects of the file. The idea is that I only use JMonkey as a utility framework to parse an do things with my objects. But to detect a collision I need to create a BulletAppState to access the PhysicsSpace and trigger the BulletAppState loop as well as creating a physics listener…

It’s fine when you want to do real time rendering but in my case it doesnt really help that much.

So I decided to look into the CollisionShape witch I though had an intersect function to detect collisions between two collision shape which is then redirected to the physics listener of the objects et voilà ! … But In fact… JMonkey use bullet as a facade and put a native call to bullet only where it’s needed. I’m not experienced enough with bullet to know what’s happening behind the scene, I’m only guessing.

What I’m dreaming of :

{ "object_1" : ["object_3","object_4"],
"object_2" : ["object_4"],
 "object_3" : ["object_1"],
    public Map<String, List<String>> detectCollisions(){
        //Crazy process to convert the 3D object into a blend file
        Node model = (Node) assetManager.loadModel("model.blend", inputStream);
        for(Spatial s1 : model.getChildren()){
            CollisionShape shape1 = CollisionShapeFactory.createMeshShape(s1);
            for(Spatial s2 : model.getChildren()){
               CollisionShape shape2 = CollisionShapeFactory.createMeshShape(s2);
                if(s1 != s2){
                   //Where are you baby :( 
                   bool result = shape1.intersect(shape2);

I’m stuck… And I don’t know how to proceed with JMonkey… Do you have any ideas on what to do ? What should I use ?

  • Use a part of a java physics engine ?
  • Create a native call to Bullet ?
  • Create my own intersect function on top of JMonkey ?
  • Use an other engine,framework specialized into physics processing ?

Thanks you for reading this post !

JME is not providing anything for you in any of these cases, really. You are better off going directly to bullet or some other library.

Even then, collision detection in the general case is a pretty huge topic and every implementation will make trade-offs. Do you need to sweep? Do you need the intersection points or just to know true/false?

What is the real goal?

All of these will matter in determining the solution. I for one am curious what the heck you would need to do this sort of collision detection for where you wouldn’t want to spatially index the stuff first.

Since you seems interested in the subject I’ll be more precise. The file in input is a description of a building that I split into a 3D file (*.dae, with topological informations) and the informations that I translate into a semantic database. I send the 3D file to the client on the browser and display it.

Imagine now that some objects overlap on the 3D model, it means that there is a problem in the building description. I can highlight the result of the API on the client to show where the object is overlapping.

  • I think a true/false is fine, since I just want to show it on the client.
  • Even though at some point I might need some sort on indications on the location of the collision.

(Looking into Bullet source code to understand how they do intersections might be fun :smiley: )

Mmmm what do you mean by that ? Could you be more precise ?