three-render-objects
Advanced tools
Comparing version 1.27.4 to 1.27.5
@@ -14,20 +14,11 @@ 'use strict'; | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var TWEEN__default = /*#__PURE__*/_interopDefaultLegacy(TWEEN); | ||
var accessorFn__default = /*#__PURE__*/_interopDefaultLegacy(accessorFn); | ||
var Kapsule__default = /*#__PURE__*/_interopDefaultLegacy(Kapsule); | ||
function styleInject(css, ref) { | ||
if (ref === void 0) ref = {}; | ||
var insertAt = ref.insertAt; | ||
if (!css || typeof document === 'undefined') { | ||
return; | ||
} | ||
var head = document.head || document.getElementsByTagName('head')[0]; | ||
var style = document.createElement('style'); | ||
style.type = 'text/css'; | ||
if (insertAt === 'top') { | ||
@@ -42,3 +33,2 @@ if (head.firstChild) { | ||
} | ||
if (style.styleSheet) { | ||
@@ -65,29 +55,21 @@ style.styleSheet.cssText = css; | ||
} | ||
return obj; | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) return _arrayLikeToArray(arr); | ||
} | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArray(iter) { | ||
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; | ||
if (_i == null) return; | ||
@@ -97,9 +79,6 @@ var _arr = []; | ||
var _d = false; | ||
var _s, _e; | ||
try { | ||
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
@@ -117,6 +96,4 @@ } | ||
} | ||
return _arr; | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
@@ -130,15 +107,10 @@ if (!o) return; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _nonIterableRest() { | ||
@@ -169,3 +141,3 @@ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
}; | ||
var threeRenderObjects = Kapsule__default["default"]({ | ||
var threeRenderObjects = Kapsule({ | ||
props: { | ||
@@ -258,7 +230,5 @@ width: { | ||
}); | ||
if (state.enablePointerInteraction) { | ||
// Update tooltip and trigger onHover events | ||
var topObject = null; | ||
if (state.hoverDuringDrag || !state.isPointerDragging) { | ||
@@ -274,11 +244,9 @@ var intersects = this.intersectingObjects(state.pointerPos.x, state.pointerPos.y).filter(function (d) { | ||
} | ||
if (topObject !== state.hoverObj) { | ||
state.onHover(topObject, state.hoverObj); | ||
state.toolTipElem.innerHTML = topObject ? accessorFn__default["default"](state.tooltipContent)(topObject) || '' : ''; | ||
state.toolTipElem.innerHTML = topObject ? accessorFn(state.tooltipContent)(topObject) || '' : ''; | ||
state.hoverObj = topObject; | ||
} | ||
} | ||
TWEEN__default["default"].update(); // update camera animation tweens | ||
TWEEN.update(); // update camera animation tweens | ||
} | ||
@@ -290,4 +258,4 @@ | ||
var _state$pointerPos = state.pointerPos, | ||
x = _state$pointerPos.x, | ||
y = _state$pointerPos.y; | ||
x = _state$pointerPos.x, | ||
y = _state$pointerPos.y; | ||
return { | ||
@@ -299,4 +267,5 @@ x: x, | ||
cameraPosition: function cameraPosition(state, position, lookAt, transitionDuration) { | ||
var camera = state.camera; // Setter | ||
var camera = state.camera; | ||
// Setter | ||
if (position && state.initialised) { | ||
@@ -309,3 +278,2 @@ var finalPos = position; | ||
}; | ||
if (!transitionDuration) { | ||
@@ -318,19 +286,21 @@ // no animation | ||
var camLookAt = getLookAt(); | ||
new TWEEN__default["default"].Tween(camPos).to(finalPos, transitionDuration).easing(TWEEN__default["default"].Easing.Quadratic.Out).onUpdate(setCameraPos).start(); // Face direction in 1/3rd of time | ||
new TWEEN.Tween(camPos).to(finalPos, transitionDuration).easing(TWEEN.Easing.Quadratic.Out).onUpdate(setCameraPos).start(); | ||
new TWEEN__default["default"].Tween(camLookAt).to(finalLookAt, transitionDuration / 3).easing(TWEEN__default["default"].Easing.Quadratic.Out).onUpdate(setLookAt).start(); | ||
// Face direction in 1/3rd of time | ||
new TWEEN.Tween(camLookAt).to(finalLookAt, transitionDuration / 3).easing(TWEEN.Easing.Quadratic.Out).onUpdate(setLookAt).start(); | ||
} | ||
return this; | ||
} // Getter | ||
} | ||
// Getter | ||
return Object.assign({}, camera.position, { | ||
lookAt: getLookAt() | ||
}); // | ||
}); | ||
// | ||
function setCameraPos(pos) { | ||
var x = pos.x, | ||
y = pos.y, | ||
z = pos.z; | ||
y = pos.y, | ||
z = pos.z; | ||
if (x !== undefined) camera.position.x = x; | ||
@@ -340,6 +310,4 @@ if (y !== undefined) camera.position.y = y; | ||
} | ||
function setLookAt(lookAt) { | ||
var lookAtVect = new three.Vector3(lookAt.x, lookAt.y, lookAt.z); | ||
if (state.controls.target) { | ||
@@ -360,7 +328,5 @@ state.controls.target = lookAtVect; | ||
var padding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10; | ||
for (var _len = arguments.length, bboxArgs = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) { | ||
bboxArgs[_key - 3] = arguments[_key]; | ||
} | ||
return this.fitToBbox(this.getBbox.apply(this, bboxArgs), transitionDuration, padding); | ||
@@ -373,16 +339,14 @@ }, | ||
var camera = state.camera; | ||
if (bbox) { | ||
var center = new three.Vector3(0, 0, 0); // reset camera aim to center | ||
var maxBoxSide = Math.max.apply(Math, _toConsumableArray(Object.entries(bbox).map(function (_ref) { | ||
var _ref2 = _slicedToArray(_ref, 2), | ||
coordType = _ref2[0], | ||
coords = _ref2[1]; | ||
coordType = _ref2[0], | ||
coords = _ref2[1]; | ||
return Math.max.apply(Math, _toConsumableArray(coords.map(function (c) { | ||
return Math.abs(center[coordType] - c); | ||
}))); | ||
}))) * 2; // find distance that fits whole bbox within padded fov | ||
}))) * 2; | ||
// find distance that fits whole bbox within padded fov | ||
var paddedFov = (1 - padding * 2 / state.height) * camera.fov; | ||
@@ -392,3 +356,2 @@ var fitHeightDistance = maxBoxSide / Math.atan(paddedFov * Math.PI / 180); | ||
var distance = Math.max(fitHeightDistance, fitWidthDistance); | ||
if (distance > 0) { | ||
@@ -399,3 +362,2 @@ var newCameraPosition = center.clone().sub(camera.position).normalize().multiplyScalar(-distance); | ||
} | ||
return this; | ||
@@ -412,4 +374,5 @@ }, | ||
return box.expandByObject(obj); | ||
}); // extract global x,y,z min/max | ||
}); | ||
// extract global x,y,z min/max | ||
return Object.assign.apply(Object, _toConsumableArray(['x', 'y', 'z'].map(function (c) { | ||
@@ -422,3 +385,2 @@ return _defineProperty({}, c, [box.min[c], box.max[c]]); | ||
vec.project(this.camera()); // project to the camera plane | ||
return { | ||
@@ -441,3 +403,2 @@ // align relative pos to canvas dimensions | ||
raycaster.params.Line.threshold = state.lineHoverPrecision; // set linePrecision | ||
raycaster.setFromCamera(relCoords, state.camera); | ||
@@ -464,4 +425,4 @@ return raycaster.intersectObjects(state.objects, true); | ||
} // to be deprecated | ||
}, | ||
}, | ||
stateInit: function stateInit() { | ||
@@ -476,18 +437,19 @@ return { | ||
var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
_ref4$controlType = _ref4.controlType, | ||
controlType = _ref4$controlType === void 0 ? 'trackball' : _ref4$controlType, | ||
_ref4$rendererConfig = _ref4.rendererConfig, | ||
rendererConfig = _ref4$rendererConfig === void 0 ? {} : _ref4$rendererConfig, | ||
_ref4$extraRenderers = _ref4.extraRenderers, | ||
extraRenderers = _ref4$extraRenderers === void 0 ? [] : _ref4$extraRenderers, | ||
_ref4$waitForLoadComp = _ref4.waitForLoadComplete, | ||
waitForLoadComplete = _ref4$waitForLoadComp === void 0 ? true : _ref4$waitForLoadComp; | ||
_ref4$controlType = _ref4.controlType, | ||
controlType = _ref4$controlType === void 0 ? 'trackball' : _ref4$controlType, | ||
_ref4$rendererConfig = _ref4.rendererConfig, | ||
rendererConfig = _ref4$rendererConfig === void 0 ? {} : _ref4$rendererConfig, | ||
_ref4$extraRenderers = _ref4.extraRenderers, | ||
extraRenderers = _ref4$extraRenderers === void 0 ? [] : _ref4$extraRenderers, | ||
_ref4$waitForLoadComp = _ref4.waitForLoadComplete, | ||
waitForLoadComplete = _ref4$waitForLoadComp === void 0 ? true : _ref4$waitForLoadComp; | ||
// Wipe DOM | ||
domNode.innerHTML = ''; // Add relative container | ||
domNode.innerHTML = ''; | ||
// Add relative container | ||
domNode.appendChild(state.container = document.createElement('div')); | ||
state.container.className = 'scene-container'; | ||
state.container.style.position = 'relative'; // Add nav info section | ||
state.container.style.position = 'relative'; | ||
// Add nav info section | ||
state.container.appendChild(state.navInfo = document.createElement('div')); | ||
@@ -500,11 +462,12 @@ state.navInfo.className = 'scene-nav-info'; | ||
}[controlType] || ''; | ||
state.navInfo.style.display = state.showNavInfo ? null : 'none'; // Setup tooltip | ||
state.navInfo.style.display = state.showNavInfo ? null : 'none'; | ||
// Setup tooltip | ||
state.toolTipElem = document.createElement('div'); | ||
state.toolTipElem.classList.add('scene-tooltip'); | ||
state.container.appendChild(state.toolTipElem); // Capture pointer coords on move or touchstart | ||
state.container.appendChild(state.toolTipElem); | ||
// Capture pointer coords on move or touchstart | ||
state.pointerPos = new three.Vector2(); | ||
state.pointerPos.x = -2; // Initialize off canvas | ||
state.pointerPos.y = -2; | ||
@@ -514,4 +477,5 @@ ['pointermove', 'pointerdown'].forEach(function (evType) { | ||
// track click state | ||
evType === 'pointerdown' && (state.isPointerPressed = true); // detect point drag | ||
evType === 'pointerdown' && (state.isPointerPressed = true); | ||
// detect point drag | ||
!state.isPointerDragging && ev.type === 'pointermove' && (ev.pressure > 0 || state.isPointerPressed) // ev.pressure always 0 on Safari, so we used the isPointerPressed tracker | ||
@@ -522,3 +486,2 @@ && (ev.pointerType !== 'touch' || ev.movementX === undefined || [ev.movementX, ev.movementY].some(function (m) { | ||
&& (state.isPointerDragging = true); | ||
if (state.enablePointerInteraction) { | ||
@@ -528,15 +491,16 @@ // update the pointer pos | ||
state.pointerPos.x = ev.pageX - offset.left; | ||
state.pointerPos.y = ev.pageY - offset.top; // Move tooltip | ||
state.pointerPos.y = ev.pageY - offset.top; | ||
// Move tooltip | ||
state.toolTipElem.style.top = "".concat(state.pointerPos.y, "px"); | ||
state.toolTipElem.style.left = "".concat(state.pointerPos.x, "px"); // adjust horizontal position to not exceed canvas boundaries | ||
state.toolTipElem.style.transform = "translate(-".concat(state.pointerPos.x / state.width * 100, "%, ").concat( // flip to above if near bottom | ||
state.toolTipElem.style.left = "".concat(state.pointerPos.x, "px"); | ||
// adjust horizontal position to not exceed canvas boundaries | ||
state.toolTipElem.style.transform = "translate(-".concat(state.pointerPos.x / state.width * 100, "%, ").concat( | ||
// flip to above if near bottom | ||
state.height - state.pointerPos.y < 100 ? 'calc(-100% - 8px)' : '21px', ")"); | ||
} | ||
function getOffset(el) { | ||
var rect = el.getBoundingClientRect(), | ||
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft, | ||
scrollTop = window.pageYOffset || document.documentElement.scrollTop; | ||
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft, | ||
scrollTop = window.pageYOffset || document.documentElement.scrollTop; | ||
return { | ||
@@ -550,7 +514,7 @@ top: rect.top + scrollTop, | ||
}); | ||
}); // Handle click events on objs | ||
}); | ||
// Handle click events on objs | ||
state.container.addEventListener('pointerup', function (ev) { | ||
state.isPointerPressed = false; | ||
if (state.isPointerDragging) { | ||
@@ -580,4 +544,5 @@ state.isPointerDragging = false; | ||
if (state.onRightClick) ev.preventDefault(); // prevent default contextmenu behavior and allow pointerup to fire instead | ||
}); // Setup renderer, camera and controls | ||
}); | ||
// Setup renderer, camera and controls | ||
state.renderer = new three.WebGLRenderer(Object.assign({ | ||
@@ -588,5 +553,5 @@ antialias: true, | ||
state.renderer.setPixelRatio(Math.min(2, window.devicePixelRatio)); // clamp device pixel ratio | ||
state.container.appendChild(state.renderer.domElement); | ||
state.container.appendChild(state.renderer.domElement); // Setup extra renderers | ||
// Setup extra renderers | ||
state.extraRenderers = extraRenderers; | ||
@@ -599,8 +564,9 @@ state.extraRenderers.forEach(function (r) { | ||
state.container.appendChild(r.domElement); | ||
}); // configure post-processing composer | ||
}); | ||
// configure post-processing composer | ||
state.postProcessingComposer = new EffectComposer_js.EffectComposer(state.renderer); | ||
state.postProcessingComposer.addPass(new RenderPass_js.RenderPass(state.scene, state.camera)); // render scene as first pass | ||
// configure controls | ||
state.controls = new { | ||
@@ -611,3 +577,2 @@ trackball: TrackballControls_js.TrackballControls, | ||
}[controlType](state.camera, state.renderer.domElement); | ||
if (controlType === 'fly') { | ||
@@ -618,3 +583,2 @@ state.controls.movementSpeed = 300; | ||
} | ||
if (controlType === 'trackball' || controlType === 'orbit') { | ||
@@ -636,3 +600,2 @@ state.controls.minDistance = 0.1; | ||
} | ||
[state.renderer, state.postProcessingComposer].concat(_toConsumableArray(state.extraRenderers)).forEach(function (r) { | ||
@@ -643,4 +606,5 @@ return r.setSize(state.width, state.height); | ||
state.camera.updateProjectionMatrix(); | ||
state.camera.position.z = 1000; // add sky | ||
state.camera.position.z = 1000; | ||
// add sky | ||
state.scene.add(state.skysphere = new three.Mesh()); | ||
@@ -662,3 +626,2 @@ state.skysphere.visible = false; | ||
} | ||
if (changedProps.hasOwnProperty('skyRadius') && state.skyRadius) { | ||
@@ -670,3 +633,2 @@ state.controls.hasOwnProperty('maxDistance') && changedProps.skyRadius && (state.controls.maxDistance = Math.min(state.controls.maxDistance, state.skyRadius)); | ||
} | ||
if (changedProps.hasOwnProperty('backgroundColor')) { | ||
@@ -677,3 +639,2 @@ var alpha = polished.parseToRgb(state.backgroundColor).alpha; | ||
} | ||
if (changedProps.hasOwnProperty('backgroundImageUrl')) { | ||
@@ -690,4 +651,5 @@ if (!state.backgroundImageUrl) { | ||
}); | ||
state.skysphere.visible = true; // triggered when background image finishes loading (asynchronously to allow 1 frame to load texture) | ||
state.skysphere.visible = true; | ||
// triggered when background image finishes loading (asynchronously to allow 1 frame to load texture) | ||
state.onBackgroundImageLoaded && setTimeout(state.onBackgroundImageLoaded); | ||
@@ -698,5 +660,3 @@ !state.loadComplete && finishLoad(); | ||
} | ||
changedProps.hasOwnProperty('showNavInfo') && (state.navInfo.style.display = state.showNavInfo ? null : 'none'); | ||
if (changedProps.hasOwnProperty('objects')) { | ||
@@ -706,8 +666,8 @@ (changedProps.objects || []).forEach(function (obj) { | ||
}); // Clear the place | ||
state.objects.forEach(function (obj) { | ||
return state.scene.add(obj); | ||
}); // Add to scene | ||
} // | ||
} | ||
// | ||
@@ -714,0 +674,0 @@ function finishLoad() { |
@@ -15,11 +15,8 @@ import { WebGLRenderer, Scene, PerspectiveCamera, Raycaster, TextureLoader, Vector2, Vector3, Box3, Color, Mesh, SphereGeometry, MeshBasicMaterial, BackSide, EventDispatcher, MOUSE, Quaternion, Spherical, Clock } from 'three'; | ||
var insertAt = ref.insertAt; | ||
if (!css || typeof document === 'undefined') { | ||
return; | ||
} | ||
var head = document.head || document.getElementsByTagName('head')[0]; | ||
var style = document.createElement('style'); | ||
style.type = 'text/css'; | ||
if (insertAt === 'top') { | ||
@@ -34,3 +31,2 @@ if (head.firstChild) { | ||
} | ||
if (style.styleSheet) { | ||
@@ -57,29 +53,21 @@ style.styleSheet.cssText = css; | ||
} | ||
return obj; | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) return _arrayLikeToArray(arr); | ||
} | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArray(iter) { | ||
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; | ||
if (_i == null) return; | ||
@@ -89,9 +77,6 @@ var _arr = []; | ||
var _d = false; | ||
var _s, _e; | ||
try { | ||
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
@@ -109,6 +94,4 @@ } | ||
} | ||
return _arr; | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
@@ -122,15 +105,10 @@ if (!o) return; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _nonIterableRest() { | ||
@@ -249,7 +227,5 @@ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
}); | ||
if (state.enablePointerInteraction) { | ||
// Update tooltip and trigger onHover events | ||
var topObject = null; | ||
if (state.hoverDuringDrag || !state.isPointerDragging) { | ||
@@ -265,3 +241,2 @@ var intersects = this.intersectingObjects(state.pointerPos.x, state.pointerPos.y).filter(function (d) { | ||
} | ||
if (topObject !== state.hoverObj) { | ||
@@ -273,3 +248,2 @@ state.onHover(topObject, state.hoverObj); | ||
} | ||
TWEEN.update(); // update camera animation tweens | ||
@@ -282,4 +256,4 @@ } | ||
var _state$pointerPos = state.pointerPos, | ||
x = _state$pointerPos.x, | ||
y = _state$pointerPos.y; | ||
x = _state$pointerPos.x, | ||
y = _state$pointerPos.y; | ||
return { | ||
@@ -291,4 +265,5 @@ x: x, | ||
cameraPosition: function cameraPosition(state, position, lookAt, transitionDuration) { | ||
var camera = state.camera; // Setter | ||
var camera = state.camera; | ||
// Setter | ||
if (position && state.initialised) { | ||
@@ -301,3 +276,2 @@ var finalPos = position; | ||
}; | ||
if (!transitionDuration) { | ||
@@ -310,19 +284,21 @@ // no animation | ||
var camLookAt = getLookAt(); | ||
new TWEEN.Tween(camPos).to(finalPos, transitionDuration).easing(TWEEN.Easing.Quadratic.Out).onUpdate(setCameraPos).start(); // Face direction in 1/3rd of time | ||
new TWEEN.Tween(camPos).to(finalPos, transitionDuration).easing(TWEEN.Easing.Quadratic.Out).onUpdate(setCameraPos).start(); | ||
// Face direction in 1/3rd of time | ||
new TWEEN.Tween(camLookAt).to(finalLookAt, transitionDuration / 3).easing(TWEEN.Easing.Quadratic.Out).onUpdate(setLookAt).start(); | ||
} | ||
return this; | ||
} // Getter | ||
} | ||
// Getter | ||
return Object.assign({}, camera.position, { | ||
lookAt: getLookAt() | ||
}); // | ||
}); | ||
// | ||
function setCameraPos(pos) { | ||
var x = pos.x, | ||
y = pos.y, | ||
z = pos.z; | ||
y = pos.y, | ||
z = pos.z; | ||
if (x !== undefined) camera.position.x = x; | ||
@@ -332,6 +308,4 @@ if (y !== undefined) camera.position.y = y; | ||
} | ||
function setLookAt(lookAt) { | ||
var lookAtVect = new three.Vector3(lookAt.x, lookAt.y, lookAt.z); | ||
if (state.controls.target) { | ||
@@ -352,7 +326,5 @@ state.controls.target = lookAtVect; | ||
var padding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10; | ||
for (var _len = arguments.length, bboxArgs = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) { | ||
bboxArgs[_key - 3] = arguments[_key]; | ||
} | ||
return this.fitToBbox(this.getBbox.apply(this, bboxArgs), transitionDuration, padding); | ||
@@ -365,16 +337,14 @@ }, | ||
var camera = state.camera; | ||
if (bbox) { | ||
var center = new three.Vector3(0, 0, 0); // reset camera aim to center | ||
var maxBoxSide = Math.max.apply(Math, _toConsumableArray(Object.entries(bbox).map(function (_ref) { | ||
var _ref2 = _slicedToArray(_ref, 2), | ||
coordType = _ref2[0], | ||
coords = _ref2[1]; | ||
coordType = _ref2[0], | ||
coords = _ref2[1]; | ||
return Math.max.apply(Math, _toConsumableArray(coords.map(function (c) { | ||
return Math.abs(center[coordType] - c); | ||
}))); | ||
}))) * 2; // find distance that fits whole bbox within padded fov | ||
}))) * 2; | ||
// find distance that fits whole bbox within padded fov | ||
var paddedFov = (1 - padding * 2 / state.height) * camera.fov; | ||
@@ -384,3 +354,2 @@ var fitHeightDistance = maxBoxSide / Math.atan(paddedFov * Math.PI / 180); | ||
var distance = Math.max(fitHeightDistance, fitWidthDistance); | ||
if (distance > 0) { | ||
@@ -391,3 +360,2 @@ var newCameraPosition = center.clone().sub(camera.position).normalize().multiplyScalar(-distance); | ||
} | ||
return this; | ||
@@ -404,4 +372,5 @@ }, | ||
return box.expandByObject(obj); | ||
}); // extract global x,y,z min/max | ||
}); | ||
// extract global x,y,z min/max | ||
return Object.assign.apply(Object, _toConsumableArray(['x', 'y', 'z'].map(function (c) { | ||
@@ -414,3 +383,2 @@ return _defineProperty({}, c, [box.min[c], box.max[c]]); | ||
vec.project(this.camera()); // project to the camera plane | ||
return { | ||
@@ -433,3 +401,2 @@ // align relative pos to canvas dimensions | ||
raycaster.params.Line.threshold = state.lineHoverPrecision; // set linePrecision | ||
raycaster.setFromCamera(relCoords, state.camera); | ||
@@ -456,4 +423,4 @@ return raycaster.intersectObjects(state.objects, true); | ||
} // to be deprecated | ||
}, | ||
}, | ||
stateInit: function stateInit() { | ||
@@ -468,18 +435,19 @@ return { | ||
var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
_ref4$controlType = _ref4.controlType, | ||
controlType = _ref4$controlType === void 0 ? 'trackball' : _ref4$controlType, | ||
_ref4$rendererConfig = _ref4.rendererConfig, | ||
rendererConfig = _ref4$rendererConfig === void 0 ? {} : _ref4$rendererConfig, | ||
_ref4$extraRenderers = _ref4.extraRenderers, | ||
extraRenderers = _ref4$extraRenderers === void 0 ? [] : _ref4$extraRenderers, | ||
_ref4$waitForLoadComp = _ref4.waitForLoadComplete, | ||
waitForLoadComplete = _ref4$waitForLoadComp === void 0 ? true : _ref4$waitForLoadComp; | ||
_ref4$controlType = _ref4.controlType, | ||
controlType = _ref4$controlType === void 0 ? 'trackball' : _ref4$controlType, | ||
_ref4$rendererConfig = _ref4.rendererConfig, | ||
rendererConfig = _ref4$rendererConfig === void 0 ? {} : _ref4$rendererConfig, | ||
_ref4$extraRenderers = _ref4.extraRenderers, | ||
extraRenderers = _ref4$extraRenderers === void 0 ? [] : _ref4$extraRenderers, | ||
_ref4$waitForLoadComp = _ref4.waitForLoadComplete, | ||
waitForLoadComplete = _ref4$waitForLoadComp === void 0 ? true : _ref4$waitForLoadComp; | ||
// Wipe DOM | ||
domNode.innerHTML = ''; // Add relative container | ||
domNode.innerHTML = ''; | ||
// Add relative container | ||
domNode.appendChild(state.container = document.createElement('div')); | ||
state.container.className = 'scene-container'; | ||
state.container.style.position = 'relative'; // Add nav info section | ||
state.container.style.position = 'relative'; | ||
// Add nav info section | ||
state.container.appendChild(state.navInfo = document.createElement('div')); | ||
@@ -492,11 +460,12 @@ state.navInfo.className = 'scene-nav-info'; | ||
}[controlType] || ''; | ||
state.navInfo.style.display = state.showNavInfo ? null : 'none'; // Setup tooltip | ||
state.navInfo.style.display = state.showNavInfo ? null : 'none'; | ||
// Setup tooltip | ||
state.toolTipElem = document.createElement('div'); | ||
state.toolTipElem.classList.add('scene-tooltip'); | ||
state.container.appendChild(state.toolTipElem); // Capture pointer coords on move or touchstart | ||
state.container.appendChild(state.toolTipElem); | ||
// Capture pointer coords on move or touchstart | ||
state.pointerPos = new three.Vector2(); | ||
state.pointerPos.x = -2; // Initialize off canvas | ||
state.pointerPos.y = -2; | ||
@@ -506,4 +475,5 @@ ['pointermove', 'pointerdown'].forEach(function (evType) { | ||
// track click state | ||
evType === 'pointerdown' && (state.isPointerPressed = true); // detect point drag | ||
evType === 'pointerdown' && (state.isPointerPressed = true); | ||
// detect point drag | ||
!state.isPointerDragging && ev.type === 'pointermove' && (ev.pressure > 0 || state.isPointerPressed) // ev.pressure always 0 on Safari, so we used the isPointerPressed tracker | ||
@@ -514,3 +484,2 @@ && (ev.pointerType !== 'touch' || ev.movementX === undefined || [ev.movementX, ev.movementY].some(function (m) { | ||
&& (state.isPointerDragging = true); | ||
if (state.enablePointerInteraction) { | ||
@@ -520,15 +489,16 @@ // update the pointer pos | ||
state.pointerPos.x = ev.pageX - offset.left; | ||
state.pointerPos.y = ev.pageY - offset.top; // Move tooltip | ||
state.pointerPos.y = ev.pageY - offset.top; | ||
// Move tooltip | ||
state.toolTipElem.style.top = "".concat(state.pointerPos.y, "px"); | ||
state.toolTipElem.style.left = "".concat(state.pointerPos.x, "px"); // adjust horizontal position to not exceed canvas boundaries | ||
state.toolTipElem.style.transform = "translate(-".concat(state.pointerPos.x / state.width * 100, "%, ").concat( // flip to above if near bottom | ||
state.toolTipElem.style.left = "".concat(state.pointerPos.x, "px"); | ||
// adjust horizontal position to not exceed canvas boundaries | ||
state.toolTipElem.style.transform = "translate(-".concat(state.pointerPos.x / state.width * 100, "%, ").concat( | ||
// flip to above if near bottom | ||
state.height - state.pointerPos.y < 100 ? 'calc(-100% - 8px)' : '21px', ")"); | ||
} | ||
function getOffset(el) { | ||
var rect = el.getBoundingClientRect(), | ||
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft, | ||
scrollTop = window.pageYOffset || document.documentElement.scrollTop; | ||
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft, | ||
scrollTop = window.pageYOffset || document.documentElement.scrollTop; | ||
return { | ||
@@ -542,7 +512,7 @@ top: rect.top + scrollTop, | ||
}); | ||
}); // Handle click events on objs | ||
}); | ||
// Handle click events on objs | ||
state.container.addEventListener('pointerup', function (ev) { | ||
state.isPointerPressed = false; | ||
if (state.isPointerDragging) { | ||
@@ -572,4 +542,5 @@ state.isPointerDragging = false; | ||
if (state.onRightClick) ev.preventDefault(); // prevent default contextmenu behavior and allow pointerup to fire instead | ||
}); // Setup renderer, camera and controls | ||
}); | ||
// Setup renderer, camera and controls | ||
state.renderer = new three.WebGLRenderer(Object.assign({ | ||
@@ -580,5 +551,5 @@ antialias: true, | ||
state.renderer.setPixelRatio(Math.min(2, window.devicePixelRatio)); // clamp device pixel ratio | ||
state.container.appendChild(state.renderer.domElement); | ||
state.container.appendChild(state.renderer.domElement); // Setup extra renderers | ||
// Setup extra renderers | ||
state.extraRenderers = extraRenderers; | ||
@@ -591,8 +562,9 @@ state.extraRenderers.forEach(function (r) { | ||
state.container.appendChild(r.domElement); | ||
}); // configure post-processing composer | ||
}); | ||
// configure post-processing composer | ||
state.postProcessingComposer = new EffectComposer(state.renderer); | ||
state.postProcessingComposer.addPass(new RenderPass(state.scene, state.camera)); // render scene as first pass | ||
// configure controls | ||
state.controls = new { | ||
@@ -603,3 +575,2 @@ trackball: TrackballControls, | ||
}[controlType](state.camera, state.renderer.domElement); | ||
if (controlType === 'fly') { | ||
@@ -610,3 +581,2 @@ state.controls.movementSpeed = 300; | ||
} | ||
if (controlType === 'trackball' || controlType === 'orbit') { | ||
@@ -628,3 +598,2 @@ state.controls.minDistance = 0.1; | ||
} | ||
[state.renderer, state.postProcessingComposer].concat(_toConsumableArray(state.extraRenderers)).forEach(function (r) { | ||
@@ -635,4 +604,5 @@ return r.setSize(state.width, state.height); | ||
state.camera.updateProjectionMatrix(); | ||
state.camera.position.z = 1000; // add sky | ||
state.camera.position.z = 1000; | ||
// add sky | ||
state.scene.add(state.skysphere = new three.Mesh()); | ||
@@ -654,3 +624,2 @@ state.skysphere.visible = false; | ||
} | ||
if (changedProps.hasOwnProperty('skyRadius') && state.skyRadius) { | ||
@@ -662,3 +631,2 @@ state.controls.hasOwnProperty('maxDistance') && changedProps.skyRadius && (state.controls.maxDistance = Math.min(state.controls.maxDistance, state.skyRadius)); | ||
} | ||
if (changedProps.hasOwnProperty('backgroundColor')) { | ||
@@ -669,3 +637,2 @@ var alpha = parseToRgb(state.backgroundColor).alpha; | ||
} | ||
if (changedProps.hasOwnProperty('backgroundImageUrl')) { | ||
@@ -682,4 +649,5 @@ if (!state.backgroundImageUrl) { | ||
}); | ||
state.skysphere.visible = true; // triggered when background image finishes loading (asynchronously to allow 1 frame to load texture) | ||
state.skysphere.visible = true; | ||
// triggered when background image finishes loading (asynchronously to allow 1 frame to load texture) | ||
state.onBackgroundImageLoaded && setTimeout(state.onBackgroundImageLoaded); | ||
@@ -690,5 +658,3 @@ !state.loadComplete && finishLoad(); | ||
} | ||
changedProps.hasOwnProperty('showNavInfo') && (state.navInfo.style.display = state.showNavInfo ? null : 'none'); | ||
if (changedProps.hasOwnProperty('objects')) { | ||
@@ -698,8 +664,8 @@ (changedProps.objects || []).forEach(function (obj) { | ||
}); // Clear the place | ||
state.objects.forEach(function (obj) { | ||
return state.scene.add(obj); | ||
}); // Add to scene | ||
} // | ||
} | ||
// | ||
@@ -706,0 +672,0 @@ function finishLoad() { |
{ | ||
"name": "three-render-objects", | ||
"version": "1.27.4", | ||
"version": "1.27.5", | ||
"description": "Easy way to render ThreeJS objects with built-in interaction defaults", | ||
@@ -38,3 +38,3 @@ "license": "MIT", | ||
"build": "rimraf dist && rollup -c", | ||
"dev": "rollup -w -c rollup.config.dev.js", | ||
"dev": "rollup -w -c rollup.config.dev.mjs", | ||
"prepare": "npm run build" | ||
@@ -52,18 +52,18 @@ }, | ||
"devDependencies": { | ||
"@babel/core": "^7.19.1", | ||
"@babel/core": "^7.19.6", | ||
"@babel/plugin-proposal-class-properties": "^7.18.6", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.18.9", | ||
"@babel/preset-env": "^7.19.1", | ||
"@rollup/plugin-babel": "^5.3.1", | ||
"@rollup/plugin-commonjs": "^22.0.2", | ||
"@rollup/plugin-node-resolve": "^14.1.0", | ||
"postcss": "^8.4.16", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.19.4", | ||
"@babel/preset-env": "^7.19.4", | ||
"@rollup/plugin-babel": "^6.0.2", | ||
"@rollup/plugin-commonjs": "^23.0.2", | ||
"@rollup/plugin-node-resolve": "^15.0.1", | ||
"postcss": "^8.4.18", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.79.1", | ||
"rollup-plugin-dts": "^4.2.2", | ||
"rollup": "^3.2.5", | ||
"rollup-plugin-dts": "^5.0.0", | ||
"rollup-plugin-postcss": "^4.0.2", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"three": "^0.144.0", | ||
"typescript": "^4.8.3" | ||
"three": "^0.146.0", | ||
"typescript": "^4.8.4" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
729736
5519