summaryrefslogtreecommitdiff
path: root/public/js/schemas.js
blob: e32a202429b373ce61a78a86abb4881126beda9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* global AFRAME, NAF */
// Hand models are served from here rather than cdn.aframe.io.
AFRAME.components['networked-hand-controls'].Component.prototype.MODEL_BASE = 'assets/hands/';

// What gets synced for each networked template. The templates live in the page
// body, which isn't parsed yet when this runs, so register lazily on first use
// (see networked-aframe issue #267).
(function () {
  const vector = (precision) => NAF.utils.vectorRequiresUpdate(precision);

  const schemas = {
    '#rig-template': [
      { component: 'position', requiresNetworkUpdate: vector(0.001) },
      { component: 'rotation', requiresNetworkUpdate: vector(0.5) },
      'player-info',
    ],
    '#head-template': [
      { component: 'position', requiresNetworkUpdate: vector(0.001) },
      { component: 'rotation', requiresNetworkUpdate: vector(0.5) },
    ],
  };

  const original = NAF.schemas.getComponents.bind(NAF.schemas);
  NAF.schemas.getComponents = (template) => {
    for (const [name, components] of Object.entries(schemas)) {
      if (!NAF.schemas.hasTemplate(name)) {
        NAF.schemas.add({ template: name, components });
      }
    }
    return original(template);
  };
})();