From 76fe2ee93fa0e04b13033baac186226f194eb6b8 Mon Sep 17 00:00:00 2001 From: Greg Fodor <gfodor@gmail.com> Date: Tue, 13 Nov 2018 17:42:40 +0000 Subject: [PATCH] Add scale option to gltf model plus --- src/components/gltf-model-plus.js | 14 ++++++++------ src/components/media-loader.js | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/components/gltf-model-plus.js b/src/components/gltf-model-plus.js index a83bd35e1..dfba4d8dc 100644 --- a/src/components/gltf-model-plus.js +++ b/src/components/gltf-model-plus.js @@ -87,7 +87,7 @@ function cloneGltf(gltf) { /// or templates associated with any of their nodes.) /// /// Returns the A-Frame entity associated with the given node, if one was constructed. -const inflateEntities = function(node, templates, isRoot) { +const inflateEntities = function(node, templates, isRoot, scale) { // inflate subtrees first so that we can determine whether or not this node needs to be inflated const childEntities = []; const children = node.children.slice(0); // setObject3D mutates the node's parent, so we have to copy @@ -136,10 +136,11 @@ const inflateEntities = function(node, templates, isRoot) { z: node.rotation.z * THREE.Math.RAD2DEG }); el.setAttribute("scale", { - x: node.scale.x, - y: node.scale.y, - z: node.scale.z + x: node.scale.x * (scale !== undefined ? scale : 1), + y: node.scale.y * (scale !== undefined ? scale : 1), + z: node.scale.z * (scale !== undefined ? scale : 1) }); + node.matrixAutoUpdate = false; node.matrix.identity(); @@ -284,7 +285,8 @@ AFRAME.registerComponent("gltf-model-plus", { src: { type: "string" }, contentType: { type: "string" }, useCache: { default: true }, - inflate: { default: false } + inflate: { default: false }, + scale: { type: "number", default: 1 } }, init() { @@ -354,7 +356,7 @@ AFRAME.registerComponent("gltf-model-plus", { } let object3DToSet = this.model; - if (this.data.inflate && (this.inflatedEl = inflateEntities(this.model, this.templates, true))) { + if (this.data.inflate && (this.inflatedEl = inflateEntities(this.model, this.templates, true, this.data.scale))) { this.el.appendChild(this.inflatedEl); object3DToSet = this.inflatedEl.object3D; // TODO: Still don't fully understand the lifecycle here and how it differs between browsers, we should dig in more diff --git a/src/components/media-loader.js b/src/components/media-loader.js index 121bc46ad..24e1b4e59 100644 --- a/src/components/media-loader.js +++ b/src/components/media-loader.js @@ -195,7 +195,8 @@ AFRAME.registerComponent("media-loader", { this.el.setAttribute("gltf-model-plus", { src: accessibleUrl, contentType: contentType, - inflate: true + inflate: true, + scale: 0.0001 }); } else { throw new Error(`Unsupported content type: ${contentType}`); -- GitLab