From 4a196795473e810d8a32cbd76edc1e6e49b9fa4c Mon Sep 17 00:00:00 2001 From: netpro2k Date: Mon, 18 Apr 2022 17:10:17 -0700 Subject: [PATCH 001/153] Experimental JSX entity templating --- src/utils/jsx-entity.js | 127 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/utils/jsx-entity.js diff --git a/src/utils/jsx-entity.js b/src/utils/jsx-entity.js new file mode 100644 index 0000000000..bd744decdc --- /dev/null +++ b/src/utils/jsx-entity.js @@ -0,0 +1,127 @@ +function parseChildren(children) { + const components = {}; + const childEntities = []; + children.forEach(function(c) { + if (c === undefined) { + console.warn("found undefined node", c); + } else if (typeof c === "string") { + console.warn("found text node", c); + } else if (c.name) { + components[c.name] = c.props; + } else { + childEntities.push(c); + } + }); + return { childEntities, components }; +} + +export function createElementEntity(tag, attrs, ...children) { + if (typeof tag === "function") return tag(attrs); + if (tag === "a-entity") { + const aframeAttrs = {}; + const { childEntities, components } = parseChildren(children); + Object.assign(components, attrs); + if (attrs.className) { + aframeAttrs.className = attrs.className; + delete components.className; + } + if (attrs.id) { + aframeAttrs.id = attrs.id; + delete components.id; + } + if (attrs.mixin) { + aframeAttrs.mixin = attrs.mixin; + delete components.mixin; + } + Object.keys(components).forEach(function(componentName) { + if (components[componentName] === true) components[componentName] = ""; + }); + return { + attrs: aframeAttrs, + components, + children: childEntities + }; + } else if (tag === "entity") { + const { childEntities, components } = parseChildren(children); + return { + attrs, + components, + children: childEntities + }; + } else { + return { + name: tag, + props: attrs + }; + } +} + +export function renderAsAframeEntity(entity) { + const el = document.createElement("a-entity"); + if (entity.attrs.className) { + el.className = entity.attrs.className; + } + if (entity.attrs.id) { + el.id = entity.attrs.id; + } + if (entity.attrs.position) { + el.object3D.position.copy(entity.attrs.position); + } + if (entity.attrs.rotation) { + el.object3D.rotation.copy(entity.attrs.rotation); + } + if (entity.attrs.scale) { + el.object3D.scale.copy(entity.attrs.scale); + } + if (entity.attrs.visible !== undefined) { + el.object3D.visible = entity.attrs.visible; + } + Object.keys(entity.components).forEach(name => el.setAttribute(name, entity.components[name])); + entity.children.forEach(child => el.appendChild(renderAsAframeEntity(child))); + return el; +} + +function reduceNodes([siblingIndicies, prevNodes], entity) { + const [childIndicies, nodes] = entity.children.reduce(reduceNodes, [[], prevNodes]); + return [ + [...siblingIndicies, nodes.length], + [ + ...nodes, + { + name: entity.attrs.id, + position: entity.attrs.position, + scale: entity.attrs.scale, + rotation: entity.attrs.rotation, + extensions: Object.keys(entity.components).length && { + MOZ_hubs_components: entity.components + }, + children: childIndicies + } + ] + ]; +} + +export function renderAsGLTF(rootEntity) { + const nodes = reduceNodes([[], []], rootEntity)[1]; + return { + asset: { + generator: "Hubs JSX", + version: "2.0" + }, + extensionsUsed: ["MOZ_hubs_components"], + nodes, + scene: nodes.length + }; +} + +/** @jsx createElementEntity */ +const gltfTest = ( + + + + + + + + +); From 26a565b39821d6fd32584b79fdd110440b64e425 Mon Sep 17 00:00:00 2001 From: netpro2k Date: Mon, 18 Apr 2022 17:11:48 -0700 Subject: [PATCH 002/153] Try doing interactable-camera outside of hub.html --- src/hub.html | 121 ----------- src/network-schemas.js | 22 +- src/network-schemas/interactable-camera.js | 232 +++++++++++++++++++++ src/scene-entry-manager.js | 3 +- 4 files changed, 236 insertions(+), 142 deletions(-) create mode 100644 src/network-schemas/interactable-camera.js diff --git a/src/hub.html b/src/hub.html index d85b036b40..0703c50b4f 100644 --- a/src/hub.html +++ b/src/hub.html @@ -615,127 +615,6 @@ - -