From 8051d3ab36f93000ad1635304f2425e3fe0909fe Mon Sep 17 00:00:00 2001 From: Greg Fodor <gfodor@gmail.com> Date: Tue, 23 Oct 2018 04:29:20 +0000 Subject: [PATCH] GLTF conversion --- src/scene-entry-manager.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/scene-entry-manager.js b/src/scene-entry-manager.js index 284cc30f1..91020989d 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 => { -- GitLab