stephengold / libbulletjme Goto Github PK
View Code? Open in Web Editor NEWA JNI interface to Bullet Physics and V-HACD
Home Page: https://stephengold.github.io/Libbulletjme/lbj-en/English/overview.html
License: Other
A JNI interface to Bullet Physics and V-HACD
Home Page: https://stephengold.github.io/Libbulletjme/lbj-en/English/overview.html
License: Other
As noted at the JME Forum, a contact test involving a GImpact shape always fails. This is because btGImpactCollisionAlgorithm::registerAlgorithm()
never registers a closest-point algorithm. (It only registers contact-point algorithms.)
Hello, I am student and I want to use this for my project
I was looking for Physics engine I can use with java, and this is the perfect, it's being maintained
However there was one thing I want to mention about this project, AFAIK, compile
in build.gradle is now deprecated and should be replaced with implementation
This is the source for this:https://stackoverflow.com/questions/44493378/whats-the-difference-between-implementation-api-and-compile-in-gradle#44493379
I have tried to refresh my project after adding the physics engine, but it could not find method compile
and was not able to compile it.
Had to replace compile
to implementation
for that, and now I can compile it.
Could you change it to implementation
if there's no need to keep it compile
?
Similar to #9 , I am using Libbulletjme for use in a Minecraft plugin, which requires double-precision in world positions, since coordinates can go up to 30 million on the X/Z axes. I see there has already been work done to get/set double-precision physics positions and rotations on PhysicsRigidBody
instances, however I also use PhysicsGhostObject
s, which from what I can see don't support the *Dp
methods.
Could double-precision get/set support be added for object types apart from RigidBody
(specifically GhostObject
s and SoftBody
s), and if possible a double-precision variant of get/set Transform methods (at least for the position component)? I make extensive use of Transforms rather than pure vectors, and double-precision utils for those would be very useful.
Hello,
I'm trying to integrate this API into an LWJGL3 project. With LWJGL3, we often use JOML, which is an extremely powerful math API. Unfortunately, they also use the same naming scheme (Vector3f, etc). My plan was to make a wrapper class for your Vector class to hide this similarity, but you guys have made your math classes final, which is a tad inconvenient. Is there any way you can consider this change in future iterations? For now I'll pull the project myself and make the changes.
Thank you!
For some reason with the latest version I am getting this Exception:
Exception in thread "main" java.lang.NoClassDefFoundError: com/simsilica/mathd/Matrix3d
at com.jme3.bullet.util.NativeLibrary.countThreads(Native Method)
at com.jme3.bullet.PhysicsSpace.<init>(PhysicsSpace.java:229)
at com.jme3.bullet.PhysicsSpace.<init>(PhysicsSpace.java:199)
Hi,
I have begun using (and adapting) Libbulletjme to the GAMA simulation platform (http://gama_platform.org), in order to replace the ageing JBullet implementation we were using. Thank you for the wonderful job you've been doing and for producing a version of the library usable by non-JME users/developers.
I have however a question (or request) : in the previous version of Bullet (and JBullet), the motion state of rigid bodies was receiving setTransform(...) whenever the body was changing its location or orientation in space. This allowed me to notify the corresponding agents in the simulation world of the changes.
I havent been able to find a similar entry point in your library. Does it mean it does not exist (anymore) in Bullet and that the only solution is to browse through all rigid bodies every step to read their motion state ? Or is there some smarter way to implement such a "listener" ?
Thanks in advance !
public class BulletTestSoftBodyProblem
{
public static void main(String[] args)
{
PhysicsSoftSpace space = new PhysicsSoftSpace(new Vector3f(-10f, -10f, -10f), new Vector3f(10f, 10f, 10f), PhysicsSpace.BroadphaseType.DBVT);
PhysicsRigidBody floor = new PhysicsRigidBody(new PlaneCollisionShape(new Plane(Vector3f.UNIT_Y, 0f)), 0f);
floor.setPhysicsLocation(new Vector3f(0, 0, 0));
space.addCollisionObject(floor);
PhysicsRigidBody rbody = new PhysicsRigidBody(new BoxCollisionShape(0.2f), 1f);
rbody.setPhysicsLocation(new Vector3f(+1, 1, 0));
space.addCollisionObject(rbody);
PhysicsSoftBody sbody = new PhysicsSoftBody(); // <--- here !!
NativeSoftBodyUtil.appendFromNativeMesh(mesh(), sbody);
sbody.setPhysicsLocation(new Vector3f(-1, 1, 0));
space.addCollisionObject(sbody);
for (int i = 0; i < 1000; i++)
{
try { space.update(0.03f, 0); Thread.sleep(10); } catch (Exception _) {}
Vector3f rpos = rbody.getPhysicsLocation(null); // rigid body position
Vector3f spos = sbody.getPhysicsLocation(null); // soft body position
System.out.println("[Rigid Cube] " + rpos + " vs " + "[Soft Cube] " + spos);
}
}
static IndexedMesh mesh()
{
float[]vrt = cube_vert;
int[][]ind = cube_indi;
List VRT = new ArrayList();
for (int i = 0; i < vrt.length; i+=3)
{
VRT.add(new Vector3f((float)vrt[i], (float)vrt[i+1], (float)vrt[i+2]));
}
List IND = new ArrayList();
for (int i = 0; i < ind.length; i++)
{
int i0 = ind[i][0];
int i1 = ind[i][1];
int i2 = ind[i][2];
IND.add(i0);
IND.add(i1);
IND.add(i2);
}
Vector3f[]vvv = new Vector3f[VRT.size()];
for (int i = 0; i < vvv.length; i++) vvv[i] = (Vector3f) VRT.get(i);
int []iii = new int[IND.size()];
for (int i = 0; i < iii.length; i++) iii[i] = (Integer) IND.get(i);
IndexedMesh im = new IndexedMesh(vvv, iii);
return im;
}
static float[]cube_vert = null; // cube vertex array
static int[][]cube_indi = null; // cube vertex indices
static
{
float s = 0.2f;
float[]v0 = new float[] { -s, +s, +s };
float[]v1 = new float[] { +s, +s, +s };
float[]v2 = new float[] { +s, -s, +s };
float[]v3 = new float[] { -s, -s, +s };
float[]v4 = new float[] { -s, +s, -s };
float[]v5 = new float[] { +s, +s, -s };
float[]v6 = new float[] { +s, -s, -s };
float[]v7 = new float[] { -s, -s, -s };
float[][]vv = new float[][] { v0, v1, v2, v3, v4, v5, v6, v7 };
cube_vert = new float[8*3];
for (int i = 0; i < 8; i++)
{
cube_vert[i*3+0] = vv[i][0];
cube_vert[i*3+1] = vv[i][1];
cube_vert[i*3+2] = vv[i][2];
}
int []p0 = new int[] {0, 1, 2 };
int []p1 = new int[] {0, 2, 3 };
int []p2 = new int[] {4, 7, 6 };
int []p3 = new int[] {4, 6, 5 };
int []p4 = new int[] {0, 4, 5 };
int []p5 = new int[] {0, 5, 1 };
int []p6 = new int[] {3, 2, 6 };
int []p7 = new int[] {3, 6, 7 };
int []p8 = new int[] {1, 5, 6 };
int []p9 = new int[] {1, 6, 2 };
int []p10= new int[] {0, 3, 7 };
int []p11= new int[] {0, 7, 4 };
int[][]pp = new int[][] { p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11 };
cube_indi = pp;
}
result
.
.
.
[Rigid Cube] (1.0278512, -0.017536394, 0.25851533) vs [Soft Cube] (-2.5757184, -565.5575, -0.2820301)
[Rigid Cube] (1.0277523, -0.017890645, 0.25878102) vs [Soft Cube] (-2.57684, -568.72144, -0.28341308)
[Rigid Cube] (1.0278698, -0.016414547, 0.25919935) vs [Soft Cube] (-2.5779958, -571.8943, -0.28479832)
[Rigid Cube] (1.0281138, -0.015941579, 0.25943175) vs [Soft Cube] (-2.5791693, -575.07605, -0.28621972)
[Rigid Cube] (1.0285553, -0.017206488, 0.25978068) vs [Soft Cube] (-2.58034, -578.2667, -0.28759184)
[Rigid Cube] (1.02916, -0.017807819, 0.25984636) vs [Soft Cube] (-2.5815368, -581.4661, -0.2889949)
[Rigid Cube] (1.0297773, -0.016683284, 0.25992036) vs [Soft Cube] (-2.582777, -584.67456, -0.29037392)
.
.
.
It would be nice to expose isInside()
in the Java API, but first I'd need to implement it in C++ for all collision shapes. Although it's declared as part of btPolyhedralConvexShape
,isInside()
isn't yet implemented for btConvexHullShape
or btBU_Simplex1to4
.
For inexact shapes, the Java version should automatically take the shape's margin into account.
I decided to use double precision of this library, but it seems like they don't exist in maven yet. Could you upload them to maven?
Hello, I want to add a collision flag to my PhysicsRigidBody but I can't beacause the method setCollisionFlag is protected, same for setActivationState.
Many fields of btContactSolverInfo
aren't yet exposed by SolverInfo
, including:
m_erp
: error reduction for non-contact constraintsm_erp2
: error reduction for contact constraintsTODO: Investigate to find out which fields are actually useful!
Hi, When I using the library, the following crashes periodically for no reason:
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f08cad49b2a, pid=237, tid=428
#
# JRE version: OpenJDK Runtime Environment Temurin-17.0.5+8 (17.0.5+8) (build 17.0.5+8)
# Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.5+8 (17.0.5+8, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# C [libbulletjme_v17.2.0_linux64_release_sp.so+0x2d8b2a] btRaycastVehicle::updateFriction(float)+0xc2a
#
# Core dump will be written. Default location: /data/core
#
# An error report file with more information is saved as:
# /data/hs_err_pid237.log
#
# If you would like to submit a bug report, please visit:
# https://github.com/adoptium/adoptium-support/issues
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
Most likely the problem is in my code, maybe I don’t close something, but how can I understand where? It just writes it and nothing else. Please help me to guess what could be causing the problem.
I saw strange character behaviors while writing tutorials for LBJ. Most of the time PhysicsCharacter.onGround()
returns the correct value, but occasionally it returns true when the character is unsupported.
This allows jumping to unlimited height in tests such as HelloWalk
, TestPhysicsCharacter
, and TestQ3
.
It might be related the character's vertical velocity being nearly zero.
Hi,
Is there a way to be notified when one (sub)step of the PhysicsSpace update() has been achieved ? Is there an equivalent to InternalTickCallback
(found in previous Bullet and JBullet versions) ?
Thanks in advance !
I need to get the normal of a triangle in a MeshCollisionShape using the partIndex() and triangleIndex() from the sweep test result but I don't see any way to do it without using reflection and getting the CompoundMesh directly, the normal from the sweep test result is not accurate as you can see here: https://pybullet.org/Bullet/phpBB3/viewtopic.php?t=3538
M1 support should be available in gradle since version 7.
Bullet should compile and work, since it is already compatible with linux arm64, my understanding is that the build script needs to be modified to include a target for
architecture 'aarch64'
operatingSystem 'osx'
I don't know how to do it, but if someone does i can test.
Hello stephengold. :-)
I am trying to implement a legdoll using excellent 'Libbulletjme' project,
(ex, https://github.com/kripken/bullet/blob/master/Demos/GenericJointDemo/Ragdoll.cpp)
It does not appear to have the following features. (like a btRigidBodyConstructionInfo, shape->calculateLocalInertia function etc ...)
I am wondering if it is possible to apply in the current situation, or if you can support this function in the future.
have a nice day, stephengold ~
in the library tutorials on automated decomposition (https://stephengold.github.io/Libbulletjme/lbj-en/English/shape.html#_automated_decomposition) there is a class called CollisionShapeFactory being used in the example but it does not seem to exist in the library.
I'm still fairly new to libbulletjme, and when I was playing around with the CollisionListeners, I discovered a fairly strange behavior when combining them with ignore lists of colliding bodies.
I attached a MWE below, where I drop two boxes (located above each other) on a third one that serves as a static floor. When a collision between the two dropped boxes is detected, I add box B to the ignore list of box A. I would normally expect the boxes to initially collide, and then drop through each other. Instead, the boxes collide, but then the upper one just hovers in the air and actually even rises a tiny bit, instead of falling down to the floor. This issue doesn't occur if you either...
a) change the initial position of the boxes, so that they're not dropped from perfectly above each other. If I set the starting position of box B to (0.25, 1, 0.25) instead of (0, 1, 0), it seems to work just fine, and box B ends up on the floor.
b) reset the position of box B when the CollisionListener is called. Interestingly, it depends on where you place box B after the collision. If you reset the position it to (0, 0, 0), box B floats in mid-air. If you reset it to (1, 0, 0), it immediately falls down (and through box A, as expected). If you reset it to (0.5, 0, 0), it stays afloat for a few timesteps, then drops down.
I'm pretty confused by this behaviour, and suspect that it isn't intentional.
The minimum working example:
public class CubesListenerMWE {
public static void main(String[] args) throws IOException {
File workingDirectory = new File("./lib").getCanonicalFile();
NativeLibraryLoader.loadLibbulletjme(true, workingDirectory, "Release", "Sp");
PhysicsSpace.BroadphaseType bPhase = PhysicsSpace.BroadphaseType.DBVT;
PhysicsSpace space = new PhysicsSpace(bPhase);
/*
* Add "floor" Box
*/
Vector3f floorDimensions = new Vector3f(3f, 0.05f, 3f);
Vector3f floorPos = new Vector3f(0f, -1.005f, 0f);
CollisionShape floorShape = new BoxCollisionShape(floorDimensions);
PhysicsRigidBody floor = new PhysicsRigidBody(floorShape, PhysicsBody.massForStatic);
floor.setPhysicsLocation(floorPos);
space.addCollisionObject(floor);
/*
* Add first dropped Box
*/
Vector3f boxADimensions = new Vector3f(0.3f, 0.3f, 0.3f);
Vector3f boxAPos = new Vector3f(0, 0, 0);
CollisionShape boxAShape = new BoxCollisionShape(boxADimensions);
PhysicsRigidBody boxA = new PhysicsRigidBody(boxAShape, 1f);
boxA.setPhysicsLocation(boxAPos);
space.addCollisionObject(boxA);
/*
* Add second dropped Box
*/
Vector3f boxBDimensions = new Vector3f(0.3f, 0.3f, 0.3f);
Vector3f boxBPos = new Vector3f(0, 1, 0);
CollisionShape boxBShape = new BoxCollisionShape(boxBDimensions);
PhysicsRigidBody boxB = new PhysicsRigidBody(boxBShape, 1f);
boxB.setPhysicsLocation(boxBPos);
space.addCollisionObject(boxB);
/*
* Add collision Listener
*/
space.addCollisionListener(event -> {
PhysicsRigidBody a = (PhysicsRigidBody) event.getObjectA();
PhysicsRigidBody b = (PhysicsRigidBody) event.getObjectB();
if (a.getMass() * b.getMass() != 0) { // Only applies for the two dropped boxes
a.addToIgnoreList(b);
// b.setPhysicsLocation(new Vector3f(0, 0, 0)); // To reset position after CollisionListener is called
}
});
/*
* Loop simulation
*/
Vector3f boxPos = new Vector3f();
for (int i = 0; i < 300; i++) {
space.update(0.01f, 0);
space.distributeEvents();
System.out.println(boxB.getPhysicsLocation(boxPos));
}
}
}
On a semi-related note: Is there a way to intercept a collision between two objects before the response is applied? With the code above, there's always an initial collision, and only afterwards, box B is added to the ignore list of box A. Could you also, for example, detect the collision, then add B to A's ignore list before the collision response happens, and then continue the simulation, so that B effectively just drops right through A? I could obviously do the whole ignore list stuff right at the start, but what if I for some reason only want to or can decide whether I'd like to have a collision between two objects when it actually happens?
Hi! I'm just discovering this library since I'm trying to stop using libGDX's Bullet bindings (no need for details here but libGDX makes a bunch of questionable choices that I want to avoid).
I have a question, why isn't this project setup in Maven like say, LWJGL in respect to the native parts?
Look at this for instance https://repo1.maven.org/maven2/org/lwjgl/lwjgl/3.2.3/
In there you can see LWJGL provides not only the Java .jar/doc/src, but also variants for every platform LWJGL supports. So all you need in your POM to include the native parts of the specific version you're using, is just adding an additional dependency with the matching classifier (say, natives-linux in my case since I'm running amd64 linux).
Of course I see that you have quite a bunch of variants for the native libraries (f32, f64, single threaded, multi threaded, debug, etc) so it may be a lot of work, but it'd be cool to have at least the basics up there so the initial setup for trying out the library doesn't requires you to manually import the specific so/dll/dylib you're going to use.
I'm guessing the "basics" would be what you recommend in the readme, single threaded single precision. This can be simplified, I believe I saw some other library that had a natives .jar for each platform, and they just bundled all the architectures they supported for that platform in the same .jar (say, arm32, arm64, x86 and x86_64 inside the linux natives jar, x86 and x86_64 in the windows natives jar, etc). It makes each native .jar fatter the more architectures you support for that platform but it prevents you from having a bajillion variants in Maven, if that's a concern at all.
Just a general question, I have no stake in this nor real world use case for this since I'm barely dipping my toes at this moment.
Hello, I have question about setting min/max size when creating physics space
AFAIK, it is not required to set max size when creating discrete dynamics world with dbvt, but I need to provide it when using this library
Does the input size important even If I use dbvt? and Can I set it really big values without worrying about performance?
My plan is to use this library in minecraft mod, and I originally used Jbullet from 10 years ago.
I have switched from original Jbullet to this library after I realized I need double precision
I need to make bullet physics work on any coordinates in any minecraft world.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.