c-frame / aframe-super-hands-component

👐All-in-one natural hand controller, pointer, and gaze interaction library for A-Frame
https://c-frame.github.io/aframe-super-hands-component/examples/
MIT License
355 stars 72 forks source link

Let's make super-hands work with Ammo.js physics engine #196

Open diarmidmackenzie opened 3 years ago

diarmidmackenzie commented 3 years ago

aframe-physics-system offers 2 different physics engines: CANNON.js and Ammo.js.

Currently super-hands only works with the CANNON.js engine.

It would be great if super-hands could work with the Ammo.js engine as well. This is particularly important as of A-Frame 1.2.0, because the CANNON.js version of aframe-physics-system is broken, and it's not clear that's going to be fixed soon.

See: https://github.com/n5ro/aframe-physics-system/issues/187

In any case, Ammo.js seems to be more mature & performant than CANNON,js, being a javascript port of the extremely widely used Bullet physics engine, so it would be good to support it in any case.

The set of changes required to get basic function with Ammo.js working seems to be fairly small. I have made a set of changes here, which appears to be most of what is required. https://github.com/wmurphyrd/aframe-super-hands-component/compare/master...diarmidmackenzie:master

@wmurphyrd - would you be willing to work with me to get this set of changes folded into this repo as a PR?

diarmidmackenzie commented 3 years ago

Here's a link directly to the forked repo with the changes in it. https://github.com/diarmidmackenzie/aframe-super-hands-component

wmurphyrd commented 3 years ago

@diarmidmackenzie yes this sounds awesome!! I'll take a look soon

RGFTheCoder commented 3 years ago

Trying to grab an object (w/ 2 hands) immediately freezes the tab for me Trying with one doesn't move the object. Maybe the object's type should be kinematic when grabbed?

diarmidmackenzie commented 3 years ago

@RGFTheCoder was this using the latest code here: https://github.com/diarmidmackenzie/aframe-super-hands-component ?

Live version here: https://terrific-minute.surge.sh/examples/physics/index-ammo.html

If so, can you tell me what VR system you were testing on?

diarmidmackenzie commented 3 years ago

@RGFTheCoder - also just wanted to respnd to your point about changing the object type to kinematic. That is not necessary.

The hand itself is a kinematic object, and then we then define a constraint between the grabbed object and the hand. That's enough to get the grabbed object moving as required.

I've tested that solution extensively and it's working well. The problems you are seeing, I suspect, will either be that you are using a different level of code, or something to do with the specific controllers or VR headset you are using. (e.g. maybe the code is failing to detect the "grip" button on your controller?).

diarmidmackenzie commented 2 years ago

It's been a while, didn't see a further update on this. Just coming back to this now & have submitted a PR with these changes.

https://github.com/wmurphyrd/aframe-super-hands-component/pull/208

AnaCoda commented 2 years ago

Thanks for your work! However, the example you provided at https://terrific-minute.surge.sh/examples/physics/index-ammo.html does not seem to be working for me... the non-ammo physics demo lets me grab the blocks but I can't seem to move them with the ammo demo. Is it working for you? I'm testing with the Mozilla WebXR extension set to Oculus Quest

diarmidmackenzie commented 2 years ago

Hi, yes that link still works for me.

This is on Oculus Quest 2 using Oculus Browser. I use the grip button to grab the blocks. Note the caveat in the background about maybe having to press grip twice the first time.

FYI, there's also a version now published on github pages (easier for me to track what code is deployed than with surge, though I believe this is exactly the same code). https://diarmidmackenzie.github.io/aframe-super-hands-component/examples/physics/index-ammo.html

I haven't tested in your setup. If you are working on desktop, you might like to see if this works for you... https://diarmidmackenzie.github.io/aframe-super-hands-component/examples/physics/index-ammo-keys.html

Press 1 to select x-axis movement, then hold - (minus) until the left sphere intersects the blue block. Press 7, to select grip, then press =/+ key 3 times, and you should see the block being grabbed Press 2 to select y-axis movement, the hold =/+ key to lift the block into the air.

These key pressses are simulating the exact same input into the software as you'd get from the Oculus Quest 2 controller.

AnaCoda commented 2 years ago

Nevermind, seems alright when I test it with the actual Oculus Quest 2 and I got it to work on my own project. Is there any way to make objects follow the ammo-constraints? I have a pendulum weight (sphere) attached to a 'rope' (cylinder) and I don't want the sphere to move away from the hinge constraint I have between them, but while I'm grabbing, it just follows the hand. Thanks so much for your help!

diarmidmackenzie commented 2 years ago

(deleted last comment, because it was wrong).

I thought that one constraint might be replacing the other, but the super-hands constraints shouldn't collide with anything else.

The super-hands code sets a name of ammo-constraint__ + a random number, which should almost never collide with anything.

const newConId = Math.random().toString(36).substr(2, 9);
      this.el.setAttribute(this.data.constraintComponentName + '__' + newConId, {

If your constraint component was just called ammo-constraint, it might be worth giving it a unique name, e.g.

ammo-constraint__hinge1

That might help ensure it doesn't get overwritten by any other constraints?

Beyond that I think I'd need some sample code to figure out what is going on. Could you create a glitch showing the problem?

DDIncNick commented 2 years ago

I can't seem to figure out what is going on with my code, I have taking your example you remade from the original example, I have even gone as far as copying the mixins, entities, and the ground from the page instead of just typing them to avoid errors. The only difference from your scene and mine is that I have a rig with movement controls and a couple of lights in the scene. As well as I am using A-Frame 1.3.0 (But I am currently switched to 1.2.0 and still nothing). If you happen to have a second would you be able to look at this?

https://glitch.com/edit/#!/aframe-super-hands-not-working

DDIncNick commented 2 years ago

Also there are one error, I am getting a three.js error saying Three.Geometry isn't a constructor when trying to set the geometry of the cube mixin. Seems to be because they deprecated Three.Geometry and replaced it with BufferGeometry?

diarmidmackenzie commented 2 years ago

@DDincBrent - in what sense is this "not working"?

I just tried your page on Oculus Quest 2, and it seemed to basically work. There were a few weird glitches where pick-up didn't seem completely reliable (I didn't try to troubleshoot these), but I was able to pick up blocks, move them around, release them etc.

I'm wondering what VR hardware you are using? I've only tested with Oculus Quest 2 so far (that's all I have available).

The THREE.Geometry error will be due to using a component that still uses THREE.Geometry, deprecated since A-Frame 1.2.0 I think. I didn't see that error, so no idea why you were seeing it. If you do see it, the fix will be to upgrade whatever component references THREE.Geometry to a more recent version that uses THREE.BufferGeometry.

or... just include this in the head of your HTML file... (credit: https://github.com/n5ro/aframe-physics-system/issues/187#issuecomment-957038514)

<script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js@r134/examples/js/deprecated/Geometry.js"></script>
klyap commented 1 year ago

Just wanted to bump on this cuz I also would love Ammo support with super-hands!

I just tested https://glitch.com/edit/#!/aframe-super-hands-not-working on Quest 2 browser and indeed it didn't work (hands couldn't pick things up and getting AmmoModule is not a function error).

However, it works when I update the Ammo lib source to <script src="https://cdn.jsdelivr.net/gh/MozillaReality/ammo.js@8bbc0ea/builds/ammo.wasm.js"></script> instead of <script src="https://mixedreality.mozilla.org/ammo.js/builds/ammo.wasm.js"></script>

The code I tested: https://glitch.com/edit/#!/fifth-simple-technician

diarmidmackenzie commented 1 year ago

Yes, this is because Mozilla pulled the published version of their Ammo library:

https://github.com/c-frame/aframe-physics-system/pull/30

In terms of getting this merged, don't know what @wmurphyrd's thoughts on this are? I ran into difficulties running the machanima tests, and never got a resolution to that... https://github.com/c-frame/aframe-super-hands-component/pull/208

wmurphyrd commented 1 year ago

@diarmidmackenzie Oh sorry bud I never saw that you had updated the PR. Sorry the machina tests are nonfunctional until someone revives the defunct motion capture components. Just unit tests are all that matters for now