diff --git a/src/scene-entry-manager.js b/src/scene-entry-manager.js index 284cc30f1ba8551971720de4b4318aaaecd2a3ba..91020989d677053bfe7cd450a14d8619975b0100 100644 --- a/src/scene-entry-manager.js +++ b/src/scene-entry-manager.js @@ -214,8 +214,30 @@ export default class SceneEntryManager { }); this.scene.addEventListener("object_pinned", e => { - console.log("pinned"); - console.log(e); + // Construct a GLTF node from this entity + const el = e.detail.el; + const object3D = el.object3D; + const components = el.components; + const networkId = components.networked.data.networkId; + + const gltfComponents = {}; + const gltfNode = { name: networkId, extensions: { HUBS_components: gltfComponents } }; + + // Adapted from three.js GLTFExporter + const equalArray = (x, y) => x.length === y.length && x.every((v, i) => v === y[i]); + const rotation = object3D.quaternion.toArray(); + const position = object3D.position.toArray(); + const scale = object3D.scale.toArray(); + + if (!equalArray(rotation, [0, 0, 0, 1])) gltfNode.rotation = rotation; + if (!equalArray(position, [0, 0, 0])) gltfNode.translation = position; + if (!equalArray(scale, [1, 1, 1])) gltfNode.scale = scale; + + if (components["media-loader"]) { + gltfComponents.media = { src: components["media-loader"].data.src, networkId }; + } + + console.log(gltfNode); }); this.scene.addEventListener("object_spawned", e => {