Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
diarmidmackenzie opened this issue Mar 2, 2021 · 16 comments
Open

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

diarmidmackenzie opened this issue Mar 2, 2021 · 16 comments

Comments

@diarmidmackenzie
Copy link
Member

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: n5ro/aframe-physics-system#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.
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
Copy link
Member Author

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

@wmurphyrd
Copy link
Member

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

@RGFTheCoder
Copy link

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
Copy link
Member Author

@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
Copy link
Member Author

@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
Copy link
Member Author

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.

#208

@AnaCoda
Copy link

AnaCoda commented Dec 6, 2021

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
Copy link
Member Author

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
Copy link

AnaCoda commented Dec 8, 2021

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
Copy link
Member Author

(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
Copy link

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
Copy link

DDIncNick commented May 9, 2022

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
Copy link
Member Author

@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: n5ro/aframe-physics-system#187 (comment))

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

@klyap
Copy link

klyap commented Feb 11, 2023

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
Copy link
Member Author

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

c-frame/aframe-physics-system#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...
#208

@wmurphyrd
Copy link
Member

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants