-
Notifications
You must be signed in to change notification settings - Fork 137
Spring constraint with ammo driver not working #171
Comments
@kfarr Thanks so much for compiling all your research on this. Very happy to take a look into this, @Micah1 @MignonBelongie please could I ask one of you to assign this to me 😊 I'll update with any of my findings as soon as I have them, and hopefully a resolution very shortly. |
@kfarr should the green boxes ammo body be type dynamic? I don't see a type specified, like this: "ammo-body="type: static" ammo-shape> |
The intention is for those bodies to be dynamic unless specified. I believe |
@kfarr thanks so much for your patience on this issue 😊 So I have a working example for spring physics with the Ammo driver. I remixed your glitch example and simplified the scene https://aframe-ammo-spring-galadirith.glitch.me/ It was really useful research that you did, and as you highlighted, the spring physics for the Ammo drive simply wasn't implemented. To get this very specific example working I replaced
with constraint.enableSpring(1, true)
constraint.setStiffness(1, 25.0)
constraint.setDamping(1, 0.02)
const upper = new Ammo.btVector3(0.0, 1000.0, 0.0);
const lower = new Ammo.btVector3(0.0, -1000.0, 0.0);
constraint.setLinearUpperLimit(upper);
constraint.setLinearLowerLimit(lower)
Ammo.destroy(upper);
Ammo.destroy(lower); So this is all very specific to this case, but we can generalise this to use the components properties, and also expose the properties that are not part of the schema right now. Important things were adding in the limits to make sure the simulation didn't hit any bounds. I couldn't find any info on the defaults of these limits. It's possible there are no defaults and they always need to be set. The units that Ammo uses seem a little weird to me. There is an issue on this in the Bullet repo bulletphysics/bullet3#345. I say weird, I haven't dealt with spring physics much, so maybe this is normal 😊 There is another peculiarity with the demo, the abrupt stop at the end. Ammo is configured to stop simulating when velocities drop below a certain threshold. I have some snippets somewhere that allow you to reconfigure the simulation, so that you don't get these abrupt stops in the simulation. I can't find these right now, but I'll continue looking tomorrow and post back when I have them 😊 So I think this get's us most of the way, actually getting a spring to work with the Ammo driver 🎉 Now it's a matter of coding this up so it can be generally used in |
Great progress! Looking very good! Yes this looks like it would be possible to generalize to expose in the component as attributes. Perhaps the sleeping issue can be solved by modifying activation state setting on the dynamic body? Also I noticed in this comment that we might want to use spring2 since the "the older variant will be deprecated" |
@kfarr great find, I should have checked the Ammo driver docs, it's the Thanks so much for pointing out that depreciation comment, seems like that would be a good thing to try to migrate towards. For the MozillaReality build it looks like There is still some weird behaviour in the spring. Setting the |
@kfarr I've updated the build for The spring physics now look much better. I'm not sure if If it's useful I'm currently using the following modification to the window.constraint = constraint = new Ammo.btGeneric6DofSpring2Constraint(body, targetBody, bodyTransform, targetTransform, 0);
for (var i in [0,1,2,3,4,5]) {
constraint.enableSpring(i, true);
constraint.setStiffness(i, 10.0);
constraint.setDamping(i, 0.75);
}
const upper = new Ammo.btVector3(-1, -1, -1);
const lower = new Ammo.btVector3(1, 1, 1);
constraint.setLinearUpperLimit(upper);
constraint.setLinearLowerLimit(lower);
constraint.setEquilibriumPoint(1, 0.0);
Ammo.destroy(upper);
Ammo.destroy(lower); I'm much happier now with these results, and now I feel comfortable implementing a general interface as it appears that I'll also attach the Attachments |
This is great! Makes sense that another version of bullet was required from my research earlier and to stick with the most recent 2.x release, thank you for taking on that effort. I think it would probably be most appropriate for this repo to host the ammo.js build. Could be in /dist/ (similar to the idea of having the js build in there too) or /lib/. |
Issue: wish to use a spring constraint with ammo driver
Demo - Working in cannon:
https://aframe-ammo-spring.glitch.me/spring-cannon.html
Demo - Not working in Ammo (after translating syntax):
https://aframe-ammo-spring.glitch.me/spring-ammo.html
Possible causes:
spring
constrainttype
does not seem to be implemented inammo-constraint
component. See:aframe-physics-system/src/components/ammo-constraint.js
Line 99 in 60b907f
You can see the actual C++ bullet code here:
https://github.com/kripken/ammo.js/blob/00506d296df957d80bd192d27ff8a3ef2aa9f176/bullet/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp#L49
It seems that calling "enableSpring" is required but isn't called in the
ammo-constraint
component for thespring
type
.I tried adding this myself, but
constraint.enableSpring()
doesn't appear to work (or change the behavior of the scene). I also tried enabling 6 times, one for each axis, per the above C++ source code and this bullet documentation:Also the other parameters of the spring should be included but I could not verify the following code works:
Also those component properties (
stiffness
,damping
andrestLength
) should be added to theammo-constraint
schema.Debugging possible issues:
The text was updated successfully, but these errors were encountered: