From 77890e4075d021209d6a2c9bb7b840ad159085f2 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 9 Oct 2014 11:33:31 -0700 Subject: [PATCH] Add automatic resizing to natural dimensions in newEditEntities.js --- examples/newEditEntities.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/examples/newEditEntities.js b/examples/newEditEntities.js index a223813347..8e82e2e2b1 100644 --- a/examples/newEditEntities.js +++ b/examples/newEditEntities.js @@ -163,6 +163,9 @@ var toolBar = (function () { Overlays.editOverlay(loadFileMenuItem, { visible: active }); } + var RESIZE_INTERVAL = 50; + var RESIZE_TIMEOUT = 20000; + var RESIZE_MAX_CHECKS = RESIZE_TIMEOUT / RESIZE_INTERVAL; function addModel(url) { var position; @@ -176,6 +179,27 @@ var toolBar = (function () { modelURL: url }); print("Model added: " + url); + + var checkCount = 0; + function resize() { + var entityProperties = Entities.getEntityProperties(entityId); + var naturalDimensions = entityProperties.naturalDimensions; + + checkCount++; + + if (naturalDimensions.x == 0 && naturalDimensions.y == 0 && naturalDimensions.z == 0) { + if (checkCount < RESIZE_MAX_CHECKS) { + Script.setTimeout(resize, RESIZE_INTERVAL); + } else { + print("Resize failed: timed out waiting for model (" + url + ") to load"); + } + } else { + entityProperties.dimensions = naturalDimensions; + Entities.editEntity(entityId, entityProperties); + } + } + + Script.setTimeout(resize, RESIZE_INTERVAL); } else { print("Can't add model: Model would be out of bounds."); }