diff options
Diffstat (limited to 'public/js/schemas.js')
| -rw-r--r-- | public/js/schemas.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/public/js/schemas.js b/public/js/schemas.js new file mode 100644 index 0000000..e32a202 --- /dev/null +++ b/public/js/schemas.js @@ -0,0 +1,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); + }; +})(); |