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

Update examples: add controller option #358

Merged
merged 51 commits into from
Aug 25, 2022
Merged

Conversation

kylebakerio
Copy link
Member

  • added controller option!
  • also, support controller model (and button model) animations!
  • more semantic use of NAF createdByMe() to remove need for class
  • clean up this.Y[this.Z] pattern by more correctly utilizing A-Frame prototype pattern
  • support for live-switching between models
  • support for many other controller models (not only vive, but also older models as well)

see live updated demo: https://naf-wip.glitch.me/tracked-controllers.html

@kylebakerio kylebakerio changed the title Update examples: support controller meshes Update examples: add controller option Aug 15, 2022
@kylebakerio
Copy link
Member Author

Through working on the quest 2 controller in parallel, I have realized that only some model changes are handled in updateModel(), but others are handled earlier that I'm missing and skipping replay on, in onButtonChange(). I am considering updating the code to be grabbing those events further up and relaying them, so that button movements are also handled, instead of just button mesh colorations.

Another option is to offer a pull request upstream to modify those controller components so that they truly do allow separate manipualtion of the controller without emitting an event. It could be doable without creating any breaking changes, just separation of concerns. But that's more work, anotehr pull request on another project, etc.

Kind of annoying. The architecture and flow of the events for controllers is more than a bit awkward.

@kylebakerio
Copy link
Member Author

This is particularly relevant for the quest 2 controllers, which I will be making a pull request to core for to enable full joystick and trigger button representation. I'd like those to be visible over the wire, and with the current design, that stuff would be missed.

I'll come back with more updates soon, need to run some experiments on that.

… EXPERIMENTAL QUEST 2 CONTROLLER MODEL COMPONENT THAT SHOULD BE REMOVED. Also has some logs that will be removed. Pushing up to do a live play test with on actual quest.
@kylebakerio
Copy link
Member Author

Alright, so:

  1. I expanded the method I've used to grab joystick movements, mesh colors, and button mesh rotation/position updates.
  2. I've tested it with the new not-released quest2 model component that support moving buttons; also, the vive controls component supports moving buttons, and that worked as well
  3. Also tested with a few other models of older oculus controllers (to be clear: all except for quest 2 were only tested with emulated chrome extension)
  4. This all works, correctly, in my experiments, for all the models I have tested recently (you can test the latest, including with experimental quest2 support, here).
  5. However, knowing everything I know, if I were starting at the beginning again, I think I'd be tempted to just intercept and rebroadcast simplified versions of the actual base events from the tracked-webxr-controls component itself, for the cleanest implementation.
  6. That said, there are some optimization benefits gained from doing it this way, so I'm not really motivated to rewrite this into that form--this seems to work quite well.

@@ -0,0 +1,507 @@
/* global AFRAME, THREE */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I added this file only so that I could test with it on glitch: https://naf-wip.glitch.me/tracked-controllers.html

it is removed in a later commit

renderer="antialias: true;
colorManagement: true;
sortObjects: true;
physicallyCorrectLights: true;"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these make seeing the controller buttons much easier, they are really hard to see without this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

@@ -5,6 +5,8 @@
<meta name="description" content="Tracked Controllers — Networked-Aframe" />

<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
<!-- <script src="/js/meta-touch-controls.js"></script> -->
<!-- TODO: REMOVE ME!!! TESTING PURPOSES ONLY, REMOVE BEFORE MERGE -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove those commented lines now.

this.el.components[this.data.controllerComponent].remove();
} catch(e) {
console.error("NAF: possible problem while updating handModelStyle to controller", e)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This try catch can be removed completely right? removeAttribute below is already doing the job.

}
},

remove() {
this.el.removeObject3D('mesh');
this.el.removeObject3D(this.str.mesh);
this.removeEventListeners();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you want this.removeEventListeners(); here? It seems wrong. this.removeEventListeners(); is already in pause() for local player symmetrically with the this.addEventListeners() for the local player in play()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that's correct. I hadn't touched A-Frame almost at all since last fall until the past month or so. Not sure if I forgot or never knew, but I've either learned or re-learned from you about the removeAttribute calling remove which calls pause pattern. when I started I assumed it was just incomplete. makes sense, though.

thanks for the review, I think everything I wrote would have worked fine either way, but I definitiely gained knowledge about writing better a-frame code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your patience. I'm glad you learned some things from this review.

I also relearned yesterday that when adding a component, it runs init and then update!, then play.
See https://github.com/aframevr/aframe/blob/795edfd65841d54aa2b186a02f660ffee606b50c/src/core/component.js#L306-L336
I had a code in update that was replacing an outfit material for an avatar, and I saw it did the logic twice.
My code was this:

schema: {
    outfit: { default: "" },
},
update: function (oldData) {
    if (!oldData) return; // Normally always a {} if it's an object based component when adding the component locally, but can be undefined some times when NAF is creating it.
 
    if (oldData.outfit !== data.outfit) {
      this.loadOutfit();
    }
}

To fix the issue I just added an extra condition:

update: function (oldData) {
    if (!oldData) return; // Normally always a {} if it's an object based component when adding the component locally, but can be undefined some times when NAF is creating it.
 
    if (oldData.outfit && oldData.outfit !== data.outfit) {
      this.loadOutfit();
    }
}

That works because I know I'm setting the outfit when creating the component, I don't want a naked avatar. :)

@vincentfretin vincentfretin merged commit de5eec9 into master Aug 25, 2022
@vincentfretin
Copy link
Member

I tested it on my Quest 1, it's working.
controller_quest1

@vincentfretin vincentfretin deleted the update-examples branch August 26, 2022 09:28
@kylebakerio
Copy link
Member Author

kylebakerio commented Aug 26, 2022

My latest update for the oculus-touch-controls (in aframe core, not here) should also fix the quest 1 (and all non-quest-2 oculus controllers, I think) controllers having the 'all buttons light up when you touch one button' issue, and that'll instantly start working with this component at that time if/when it gets merged in.

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

Successfully merging this pull request may close these issues.

None yet

2 participants