Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

three-render-objects

Package Overview
Dependencies
Maintainers
1
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

three-render-objects - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

1

dist/three-render-objects.common.js

@@ -175,2 +175,3 @@ 'use strict';

// Setup renderer, camera and controls
state.renderer.setSize(state.width, state.height);
state.container.appendChild(state.renderer.domElement);

@@ -177,0 +178,0 @@ state.tbControls = new ThreeTrackballControls(state.camera, state.renderer.domElement);

3

dist/three-render-objects.js

@@ -1,2 +0,2 @@

// Version 0.1.0 three-render-objects - https://github.com/vasturiano/three-render-objects
// Version 0.1.1 three-render-objects - https://github.com/vasturiano/three-render-objects
(function (global, factory) {

@@ -852,2 +852,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('three')) :

// Setup renderer, camera and controls
state.renderer.setSize(state.width, state.height);
state.container.appendChild(state.renderer.domElement);

@@ -854,0 +855,0 @@ state.tbControls = new threeTrackballcontrols(state.camera, state.renderer.domElement);

@@ -1,2 +0,2 @@

// Version 0.1.0 three-render-objects - https://github.com/vasturiano/three-render-objects
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("three")):"function"==typeof define&&define.amd?define(["three"],t):e.ThreeRenderObjects=t(e.THREE)}(this,function(e){"use strict";var t="default"in e?e.default:e;!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===n&&o.firstChild?o.insertBefore(i,o.firstChild):o.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}(".scene-nav-info {\n bottom: 5px;\n width: 100%;\n text-align: center;\n color: slategrey;\n opacity: 0.7;\n font-size: 10px;\n}\n\n.scene-tooltip {\n color: lavender;\n font-size: 18px;\n transform: translate(-50%, 25px);\n}\n\n.scene-nav-info, .scene-tooltip {\n position: absolute;\n font-family: Sans-serif;\n}");var n,q=window.THREE||t,o=n=function(e,t){var r=this,a={NONE:-1,ROTATE:0,ZOOM:1,PAN:2,TOUCH_ROTATE:3,TOUCH_ZOOM_PAN:4};this.object=e,this.domElement=void 0!==t?t:document,this.enabled=!0,this.screen={left:0,top:0,width:0,height:0},this.rotateSpeed=1,this.zoomSpeed=1.2,this.panSpeed=.3,this.noRotate=!1,this.noZoom=!1,this.noPan=!1,this.staticMoving=!1,this.dynamicDampingFactor=.2,this.minDistance=0,this.maxDistance=1/0,this.keys=[65,83,68],this.target=new q.Vector3;var n=new q.Vector3,c=a.NONE,o=a.NONE,i=new q.Vector3,s=new q.Vector2,u=new q.Vector2,d=new q.Vector3,p=0,l=new q.Vector2,h=new q.Vector2,f=0,m=0,v=new q.Vector2,g=new q.Vector2;this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.up0=this.object.up.clone();var y={type:"change"},w={type:"start"},E={type:"end"};this.handleResize=function(){if(this.domElement===document)this.screen.left=0,this.screen.top=0,this.screen.width=window.innerWidth,this.screen.height=window.innerHeight;else{var e=this.domElement.getBoundingClientRect(),t=this.domElement.ownerDocument.documentElement;this.screen.left=e.left+window.pageXOffset-t.clientLeft,this.screen.top=e.top+window.pageYOffset-t.clientTop,this.screen.width=e.width,this.screen.height=e.height}},this.handleEvent=function(e){"function"==typeof this[e.type]&&this[e.type](e)};var b,O,x,j,T,C,L,P,V,A,N,D,R=(b=new q.Vector2,function(e,t){return b.set((e-r.screen.left)/r.screen.width,(t-r.screen.top)/r.screen.height),b}),k=(O=new q.Vector2,function(e,t){return O.set((e-.5*r.screen.width-r.screen.left)/(.5*r.screen.width),(r.screen.height+2*(r.screen.top-t))/r.screen.width),O});function M(e,t){return Array.isArray(e)?-1!==e.indexOf(t):e===t}function S(e){!1!==r.enabled&&(window.removeEventListener("keydown",S),(o=c)===a.NONE&&(M(r.keys[a.ROTATE],e.keyCode)&&!r.noRotate?c=a.ROTATE:M(r.keys[a.ZOOM],e.keyCode)&&!r.noZoom?c=a.ZOOM:M(r.keys[a.PAN],e.keyCode)&&!r.noPan&&(c=a.PAN)))}function Y(e){!1!==r.enabled&&(c=o,window.addEventListener("keydown",S,!1))}function _(e){!1!==r.enabled&&(e.preventDefault(),e.stopPropagation(),c===a.NONE&&(c=e.button),c!==a.ROTATE||r.noRotate?c!==a.ZOOM||r.noZoom?c!==a.PAN||r.noPan||(v.copy(R(e.pageX,e.pageY)),g.copy(v)):(l.copy(R(e.pageX,e.pageY)),h.copy(l)):(u.copy(k(e.pageX,e.pageY)),s.copy(u)),document.addEventListener("mousemove",X,!1),document.addEventListener("mouseup",H,!1),r.dispatchEvent(w))}function X(e){!1!==r.enabled&&(e.preventDefault(),e.stopPropagation(),c!==a.ROTATE||r.noRotate?c!==a.ZOOM||r.noZoom?c!==a.PAN||r.noPan||g.copy(R(e.pageX,e.pageY)):h.copy(R(e.pageX,e.pageY)):(s.copy(u),u.copy(k(e.pageX,e.pageY))))}function H(e){!1!==r.enabled&&(e.preventDefault(),e.stopPropagation(),c=a.NONE,document.removeEventListener("mousemove",X),document.removeEventListener("mouseup",H),r.dispatchEvent(E))}function z(e){if(!1!==r.enabled){switch(e.preventDefault(),e.stopPropagation(),e.deltaMode){case 2:l.y-=.025*e.deltaY;break;case 1:l.y-=.01*e.deltaY;break;default:l.y-=25e-5*e.deltaY}r.dispatchEvent(w),r.dispatchEvent(E)}}function U(e){if(!1!==r.enabled){switch(e.touches.length){case 1:c=a.TOUCH_ROTATE,u.copy(k(e.touches[0].pageX,e.touches[0].pageY)),s.copy(u);break;default:c=a.TOUCH_ZOOM_PAN;var t=e.touches[0].pageX-e.touches[1].pageX,n=e.touches[0].pageY-e.touches[1].pageY;m=f=Math.sqrt(t*t+n*n);var o=(e.touches[0].pageX+e.touches[1].pageX)/2,i=(e.touches[0].pageY+e.touches[1].pageY)/2;v.copy(R(o,i)),g.copy(v)}r.dispatchEvent(w)}}function I(e){if(!1!==r.enabled)switch(e.preventDefault(),e.stopPropagation(),e.touches.length){case 1:s.copy(u),u.copy(k(e.touches[0].pageX,e.touches[0].pageY));break;default:var t=e.touches[0].pageX-e.touches[1].pageX,n=e.touches[0].pageY-e.touches[1].pageY;m=Math.sqrt(t*t+n*n);var o=(e.touches[0].pageX+e.touches[1].pageX)/2,i=(e.touches[0].pageY+e.touches[1].pageY)/2;g.copy(R(o,i))}}function Z(e){if(!1!==r.enabled){switch(e.touches.length){case 0:c=a.NONE;break;case 1:c=a.TOUCH_ROTATE,u.copy(k(e.touches[0].pageX,e.touches[0].pageY)),s.copy(u)}r.dispatchEvent(E)}}function F(e){!1!==r.enabled&&e.preventDefault()}this.rotateCamera=(j=new q.Vector3,T=new q.Quaternion,C=new q.Vector3,L=new q.Vector3,P=new q.Vector3,V=new q.Vector3,function(){V.set(u.x-s.x,u.y-s.y,0),(x=V.length())?(i.copy(r.object.position).sub(r.target),C.copy(i).normalize(),L.copy(r.object.up).normalize(),P.crossVectors(L,C).normalize(),L.setLength(u.y-s.y),P.setLength(u.x-s.x),V.copy(L.add(P)),j.crossVectors(V,i).normalize(),x*=r.rotateSpeed,T.setFromAxisAngle(j,x),i.applyQuaternion(T),r.object.up.applyQuaternion(T),d.copy(j),p=x):!r.staticMoving&&p&&(p*=Math.sqrt(1-r.dynamicDampingFactor),i.copy(r.object.position).sub(r.target),T.setFromAxisAngle(d,p),i.applyQuaternion(T),r.object.up.applyQuaternion(T)),s.copy(u)}),this.zoomCamera=function(){var e;c===a.TOUCH_ZOOM_PAN?(e=f/m,f=m,i.multiplyScalar(e)):(1!==(e=1+(h.y-l.y)*r.zoomSpeed)&&0<e&&i.multiplyScalar(e),r.staticMoving?l.copy(h):l.y+=(h.y-l.y)*this.dynamicDampingFactor)},this.panCamera=(A=new q.Vector2,N=new q.Vector3,D=new q.Vector3,function(){A.copy(g).sub(v),A.lengthSq()&&(A.multiplyScalar(i.length()*r.panSpeed),D.copy(i).cross(r.object.up).setLength(A.x),D.add(N.copy(r.object.up).setLength(A.y)),r.object.position.add(D),r.target.add(D),r.staticMoving?v.copy(g):v.add(A.subVectors(g,v).multiplyScalar(r.dynamicDampingFactor)))}),this.checkDistances=function(){r.noZoom&&r.noPan||(i.lengthSq()>r.maxDistance*r.maxDistance&&(r.object.position.addVectors(r.target,i.setLength(r.maxDistance)),l.copy(h)),i.lengthSq()<r.minDistance*r.minDistance&&(r.object.position.addVectors(r.target,i.setLength(r.minDistance)),l.copy(h)))},this.update=function(){i.subVectors(r.object.position,r.target),r.noRotate||r.rotateCamera(),r.noZoom||r.zoomCamera(),r.noPan||r.panCamera(),r.object.position.addVectors(r.target,i),r.checkDistances(),r.object.lookAt(r.target),1e-6<n.distanceToSquared(r.object.position)&&(r.dispatchEvent(y),n.copy(r.object.position))},this.reset=function(){c=a.NONE,o=a.NONE,r.target.copy(r.target0),r.object.position.copy(r.position0),r.object.up.copy(r.up0),i.subVectors(r.object.position,r.target),r.object.lookAt(r.target),r.dispatchEvent(y),n.copy(r.object.position)},this.dispose=function(){this.domElement.removeEventListener("contextmenu",F,!1),this.domElement.removeEventListener("mousedown",_,!1),this.domElement.removeEventListener("wheel",z,!1),this.domElement.removeEventListener("touchstart",U,!1),this.domElement.removeEventListener("touchend",Z,!1),this.domElement.removeEventListener("touchmove",I,!1),document.removeEventListener("mousemove",X,!1),document.removeEventListener("mouseup",H,!1),window.removeEventListener("keydown",S,!1),window.removeEventListener("keyup",Y,!1)},this.domElement.addEventListener("contextmenu",F,!1),this.domElement.addEventListener("mousedown",_,!1),this.domElement.addEventListener("wheel",z,!1),this.domElement.addEventListener("touchstart",U,!1),this.domElement.addEventListener("touchend",Z,!1),this.domElement.addEventListener("touchmove",I,!1),window.addEventListener("keydown",S,!1),window.addEventListener("keyup",Y,!1),this.handleResize(),this.update()};n.prototype=Object.create(q.EventDispatcher.prototype);"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function i(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function r(e,t){return e(t={exports:{}},t.exports),t.exports}var a=r(function(e,t){e.exports=function(n){function o(e){if(i[e])return i[e].exports;var t=i[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,o),t.l=!0,t.exports}var i={};return o.m=n,o.c=i,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=0)}([function(e,t,n){var o,i,r;i=[e,t],void 0!==(r="function"==typeof(o=function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(t){return t instanceof Function?t:"string"==typeof t?function(e){return e[t]}:function(e){return t}},e.exports=t.default})?o.apply(t,i):o)&&(e.exports=r)}])}),c=i(a),s=(a.accessorFn,r(function(e,t){"undefined"!=typeof self&&self,e.exports=function(n){var o={};function i(e){if(o[e])return o[e].exports;var t=o[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,i),t.l=!0,t.exports}return i.m=n,i.c=o,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0)}([function(e,t,n){var o,i,r,a;a=function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=e.stateInit,o=void 0===t?function(){return{}}:t,n=e.props,i=void 0===n?{}:n,r=e.methods,c=void 0===r?{}:r,a=e.aliases,s=void 0===a?{}:a,u=e.init,d=void 0===u?function(){}:u,p=e.update,l=void 0===p?function(){}:p,h=Object.keys(i).map(function(e){return new v(e,i[e])});return function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},r=Object.assign({},o instanceof Function?o():o,{initialised:!1});function a(e){return n(e,t),i(),a}var n=function(e,t){d.call(a,e,r,t),r.initialised=!0},i=(0,f.default)(function(){r.initialised&&l.call(a,r)},1);return h.forEach(function(e){a[e.name]=function(t){var n=1<arguments.length&&void 0!==arguments[1]&&arguments[1],o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:function(e,t){};return function(e){return arguments.length?(r[t]=e,o.call(a,e,r),n&&i(),a):r[t]}}(e.name,e.triggerUpdate,e.onChange)}),Object.keys(c).forEach(function(i){a[i]=function(){for(var e,t=arguments.length,n=Array(t),o=0;o<t;o++)n[o]=arguments[o];return(e=c[i]).call.apply(e,[a,r].concat(n))}}),Object.entries(s).forEach(function(e){var t=m(e,2),n=t[0],o=t[1];return a[n]=a[o]}),a.resetProps=function(){return h.forEach(function(e){a[e.name](e.defaultVal)}),a},a.resetProps(),r._rerender=i,a}};var o,f=(o=n)&&o.__esModule?o:{default:o},m=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],o=!0,i=!1,r=void 0;try{for(var a,c=e[Symbol.iterator]();!(o=(a=c.next()).done)&&(n.push(a.value),!t||n.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{!o&&c.return&&c.return()}finally{if(i)throw r}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},v=function e(t,n){var o=n.default,i=void 0===o?null:o,r=n.triggerUpdate,a=void 0===r||r,c=n.onChange,s=void 0===c?function(e,t){}:c;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.name=t,this.defaultVal=i,this.triggerUpdate=a,this.onChange=s};e.exports=t.default},i=[e,t,n(1)],void 0===(r="function"==typeof(o=a)?o.apply(t,i):o)||(e.exports=r)},function(e,t){e.exports=function(t,n,o){var i,r,a,c,s;function u(){var e=Date.now()-c;e<n&&0<=e?i=setTimeout(u,n-e):(i=null,o||(s=t.apply(a,r),a=r=null))}null==n&&(n=100);var e=function(){a=this,r=arguments,c=Date.now();var e=o&&!i;return i||(i=setTimeout(u,n)),e&&(s=t.apply(a,r),a=r=null),s};return e.clear=function(){i&&(clearTimeout(i),i=null)},e.flush=function(){i&&(s=t.apply(a,r),a=r=null,clearTimeout(i),i=null)},e}}])})),u=i(s),d=(s.Kapsule,window.THREE?window.THREE:{WebGLRenderer:e.WebGLRenderer,Scene:e.Scene,PerspectiveCamera:e.PerspectiveCamera,AmbientLight:e.AmbientLight,Raycaster:e.Raycaster,Vector2:e.Vector2});return u({props:{width:{default:window.innerWidth},height:{default:window.innerHeight},showNavInfo:{default:!0},objects:{default:[],onChange:function(e,t){(t.prevObjs||[]).forEach(function(e){return t.scene.remove(e)}),(t.prevObjs=e).forEach(function(e){return t.scene.add(e)})},triggerUpdate:!1},enablePointerInteraction:{default:!0,onChange:function(e,t){t.hoverObj=null},triggerUpdate:!1},lineHoverPrecision:{default:1,triggerUpdate:!1},tooltipContent:{triggerUpdate:!1},onHover:{default:function(){},triggerUpdate:!1},onClick:{default:function(){},triggerUpdate:!1}},methods:{tick:function(e){if(e.initialised&&(e.tbControls.update(),e.renderer.render(e.scene,e.camera),e.enablePointerInteraction)){var t=new d.Raycaster;t.linePrecision=e.lineHoverPrecision,t.setFromCamera(e.mousePos,e.camera);var n=t.intersectObjects(e.objects),o=n.length?n[0].object:null;o!==e.hoverObj&&(e.onHover(o,e.hoverObj),e.toolTipElem.innerHTML=o&&c(e.tooltipContent)(o)||"",e.hoverObj=o)}return this},renderer:function(e){return e.renderer},scene:function(e){return e.scene},camera:function(e){return e.camera}},stateInit:{renderer:new d.WebGLRenderer,scene:new d.Scene,camera:new d.PerspectiveCamera},init:function(e,s){e.innerHTML="",e.appendChild(s.container=document.createElement("div")),s.container.style.position="relative",s.container.appendChild(s.navInfo=document.createElement("div")),s.navInfo.className="scene-nav-info",s.navInfo.textContent="MOVE mouse & press LEFT/A: rotate, MIDDLE/S: zoom, RIGHT/D: pan",s.toolTipElem=document.createElement("div"),s.toolTipElem.classList.add("scene-tooltip"),s.container.appendChild(s.toolTipElem),s.mousePos=new d.Vector2,s.mousePos.x=-2,s.mousePos.y=-2,s.container.addEventListener("mousemove",function(e){if(s.enablePointerInteraction){var t=(i=s.container,r=i.getBoundingClientRect(),a=window.pageXOffset||document.documentElement.scrollLeft,c=window.pageYOffset||document.documentElement.scrollTop,{top:r.top+c,left:r.left+a}),n=e.pageX-t.left,o=e.pageY-t.top;s.mousePos.x=n/s.width*2-1,s.mousePos.y=-o/s.height*2+1,s.toolTipElem.style.top=o+"px",s.toolTipElem.style.left=n+"px"}var i,r,a,c},!1),s.container.addEventListener("click",function(e){s.hoverObj&&s.onClick(s.hoverObj)},!1),s.container.appendChild(s.renderer.domElement),s.tbControls=new o(s.camera,s.renderer.domElement),s.tbControls.minDistance=.1,s.tbControls.maxDistance=5e4,s.camera.position.z=1e3,s.camera.far=5e4,window.scene=s.scene},update:function(e){e.width&&e.height&&(e.container.style.width=e.width,e.container.style.height=e.height,e.renderer.setSize(e.width,e.height),e.camera.aspect=e.width/e.height,e.camera.updateProjectionMatrix()),e.navInfo.style.display=e.showNavInfo?null:"none"}})});
// Version 0.1.1 three-render-objects - https://github.com/vasturiano/three-render-objects
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("three")):"function"==typeof define&&define.amd?define(["three"],t):e.ThreeRenderObjects=t(e.THREE)}(this,function(e){"use strict";var t="default"in e?e.default:e;!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===n&&o.firstChild?o.insertBefore(i,o.firstChild):o.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}(".scene-nav-info {\n bottom: 5px;\n width: 100%;\n text-align: center;\n color: slategrey;\n opacity: 0.7;\n font-size: 10px;\n}\n\n.scene-tooltip {\n color: lavender;\n font-size: 18px;\n transform: translate(-50%, 25px);\n}\n\n.scene-nav-info, .scene-tooltip {\n position: absolute;\n font-family: Sans-serif;\n}");var n,q=window.THREE||t,o=n=function(e,t){var r=this,a={NONE:-1,ROTATE:0,ZOOM:1,PAN:2,TOUCH_ROTATE:3,TOUCH_ZOOM_PAN:4};this.object=e,this.domElement=void 0!==t?t:document,this.enabled=!0,this.screen={left:0,top:0,width:0,height:0},this.rotateSpeed=1,this.zoomSpeed=1.2,this.panSpeed=.3,this.noRotate=!1,this.noZoom=!1,this.noPan=!1,this.staticMoving=!1,this.dynamicDampingFactor=.2,this.minDistance=0,this.maxDistance=1/0,this.keys=[65,83,68],this.target=new q.Vector3;var n=new q.Vector3,c=a.NONE,o=a.NONE,i=new q.Vector3,s=new q.Vector2,u=new q.Vector2,d=new q.Vector3,p=0,l=new q.Vector2,h=new q.Vector2,f=0,m=0,v=new q.Vector2,g=new q.Vector2;this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.up0=this.object.up.clone();var y={type:"change"},w={type:"start"},E={type:"end"};this.handleResize=function(){if(this.domElement===document)this.screen.left=0,this.screen.top=0,this.screen.width=window.innerWidth,this.screen.height=window.innerHeight;else{var e=this.domElement.getBoundingClientRect(),t=this.domElement.ownerDocument.documentElement;this.screen.left=e.left+window.pageXOffset-t.clientLeft,this.screen.top=e.top+window.pageYOffset-t.clientTop,this.screen.width=e.width,this.screen.height=e.height}},this.handleEvent=function(e){"function"==typeof this[e.type]&&this[e.type](e)};var b,O,x,j,T,C,L,P,V,A,N,D,R=(b=new q.Vector2,function(e,t){return b.set((e-r.screen.left)/r.screen.width,(t-r.screen.top)/r.screen.height),b}),k=(O=new q.Vector2,function(e,t){return O.set((e-.5*r.screen.width-r.screen.left)/(.5*r.screen.width),(r.screen.height+2*(r.screen.top-t))/r.screen.width),O});function M(e,t){return Array.isArray(e)?-1!==e.indexOf(t):e===t}function S(e){!1!==r.enabled&&(window.removeEventListener("keydown",S),(o=c)===a.NONE&&(M(r.keys[a.ROTATE],e.keyCode)&&!r.noRotate?c=a.ROTATE:M(r.keys[a.ZOOM],e.keyCode)&&!r.noZoom?c=a.ZOOM:M(r.keys[a.PAN],e.keyCode)&&!r.noPan&&(c=a.PAN)))}function Y(e){!1!==r.enabled&&(c=o,window.addEventListener("keydown",S,!1))}function _(e){!1!==r.enabled&&(e.preventDefault(),e.stopPropagation(),c===a.NONE&&(c=e.button),c!==a.ROTATE||r.noRotate?c!==a.ZOOM||r.noZoom?c!==a.PAN||r.noPan||(v.copy(R(e.pageX,e.pageY)),g.copy(v)):(l.copy(R(e.pageX,e.pageY)),h.copy(l)):(u.copy(k(e.pageX,e.pageY)),s.copy(u)),document.addEventListener("mousemove",X,!1),document.addEventListener("mouseup",H,!1),r.dispatchEvent(w))}function X(e){!1!==r.enabled&&(e.preventDefault(),e.stopPropagation(),c!==a.ROTATE||r.noRotate?c!==a.ZOOM||r.noZoom?c!==a.PAN||r.noPan||g.copy(R(e.pageX,e.pageY)):h.copy(R(e.pageX,e.pageY)):(s.copy(u),u.copy(k(e.pageX,e.pageY))))}function H(e){!1!==r.enabled&&(e.preventDefault(),e.stopPropagation(),c=a.NONE,document.removeEventListener("mousemove",X),document.removeEventListener("mouseup",H),r.dispatchEvent(E))}function z(e){if(!1!==r.enabled){switch(e.preventDefault(),e.stopPropagation(),e.deltaMode){case 2:l.y-=.025*e.deltaY;break;case 1:l.y-=.01*e.deltaY;break;default:l.y-=25e-5*e.deltaY}r.dispatchEvent(w),r.dispatchEvent(E)}}function U(e){if(!1!==r.enabled){switch(e.touches.length){case 1:c=a.TOUCH_ROTATE,u.copy(k(e.touches[0].pageX,e.touches[0].pageY)),s.copy(u);break;default:c=a.TOUCH_ZOOM_PAN;var t=e.touches[0].pageX-e.touches[1].pageX,n=e.touches[0].pageY-e.touches[1].pageY;m=f=Math.sqrt(t*t+n*n);var o=(e.touches[0].pageX+e.touches[1].pageX)/2,i=(e.touches[0].pageY+e.touches[1].pageY)/2;v.copy(R(o,i)),g.copy(v)}r.dispatchEvent(w)}}function I(e){if(!1!==r.enabled)switch(e.preventDefault(),e.stopPropagation(),e.touches.length){case 1:s.copy(u),u.copy(k(e.touches[0].pageX,e.touches[0].pageY));break;default:var t=e.touches[0].pageX-e.touches[1].pageX,n=e.touches[0].pageY-e.touches[1].pageY;m=Math.sqrt(t*t+n*n);var o=(e.touches[0].pageX+e.touches[1].pageX)/2,i=(e.touches[0].pageY+e.touches[1].pageY)/2;g.copy(R(o,i))}}function Z(e){if(!1!==r.enabled){switch(e.touches.length){case 0:c=a.NONE;break;case 1:c=a.TOUCH_ROTATE,u.copy(k(e.touches[0].pageX,e.touches[0].pageY)),s.copy(u)}r.dispatchEvent(E)}}function F(e){!1!==r.enabled&&e.preventDefault()}this.rotateCamera=(j=new q.Vector3,T=new q.Quaternion,C=new q.Vector3,L=new q.Vector3,P=new q.Vector3,V=new q.Vector3,function(){V.set(u.x-s.x,u.y-s.y,0),(x=V.length())?(i.copy(r.object.position).sub(r.target),C.copy(i).normalize(),L.copy(r.object.up).normalize(),P.crossVectors(L,C).normalize(),L.setLength(u.y-s.y),P.setLength(u.x-s.x),V.copy(L.add(P)),j.crossVectors(V,i).normalize(),x*=r.rotateSpeed,T.setFromAxisAngle(j,x),i.applyQuaternion(T),r.object.up.applyQuaternion(T),d.copy(j),p=x):!r.staticMoving&&p&&(p*=Math.sqrt(1-r.dynamicDampingFactor),i.copy(r.object.position).sub(r.target),T.setFromAxisAngle(d,p),i.applyQuaternion(T),r.object.up.applyQuaternion(T)),s.copy(u)}),this.zoomCamera=function(){var e;c===a.TOUCH_ZOOM_PAN?(e=f/m,f=m,i.multiplyScalar(e)):(1!==(e=1+(h.y-l.y)*r.zoomSpeed)&&0<e&&i.multiplyScalar(e),r.staticMoving?l.copy(h):l.y+=(h.y-l.y)*this.dynamicDampingFactor)},this.panCamera=(A=new q.Vector2,N=new q.Vector3,D=new q.Vector3,function(){A.copy(g).sub(v),A.lengthSq()&&(A.multiplyScalar(i.length()*r.panSpeed),D.copy(i).cross(r.object.up).setLength(A.x),D.add(N.copy(r.object.up).setLength(A.y)),r.object.position.add(D),r.target.add(D),r.staticMoving?v.copy(g):v.add(A.subVectors(g,v).multiplyScalar(r.dynamicDampingFactor)))}),this.checkDistances=function(){r.noZoom&&r.noPan||(i.lengthSq()>r.maxDistance*r.maxDistance&&(r.object.position.addVectors(r.target,i.setLength(r.maxDistance)),l.copy(h)),i.lengthSq()<r.minDistance*r.minDistance&&(r.object.position.addVectors(r.target,i.setLength(r.minDistance)),l.copy(h)))},this.update=function(){i.subVectors(r.object.position,r.target),r.noRotate||r.rotateCamera(),r.noZoom||r.zoomCamera(),r.noPan||r.panCamera(),r.object.position.addVectors(r.target,i),r.checkDistances(),r.object.lookAt(r.target),1e-6<n.distanceToSquared(r.object.position)&&(r.dispatchEvent(y),n.copy(r.object.position))},this.reset=function(){c=a.NONE,o=a.NONE,r.target.copy(r.target0),r.object.position.copy(r.position0),r.object.up.copy(r.up0),i.subVectors(r.object.position,r.target),r.object.lookAt(r.target),r.dispatchEvent(y),n.copy(r.object.position)},this.dispose=function(){this.domElement.removeEventListener("contextmenu",F,!1),this.domElement.removeEventListener("mousedown",_,!1),this.domElement.removeEventListener("wheel",z,!1),this.domElement.removeEventListener("touchstart",U,!1),this.domElement.removeEventListener("touchend",Z,!1),this.domElement.removeEventListener("touchmove",I,!1),document.removeEventListener("mousemove",X,!1),document.removeEventListener("mouseup",H,!1),window.removeEventListener("keydown",S,!1),window.removeEventListener("keyup",Y,!1)},this.domElement.addEventListener("contextmenu",F,!1),this.domElement.addEventListener("mousedown",_,!1),this.domElement.addEventListener("wheel",z,!1),this.domElement.addEventListener("touchstart",U,!1),this.domElement.addEventListener("touchend",Z,!1),this.domElement.addEventListener("touchmove",I,!1),window.addEventListener("keydown",S,!1),window.addEventListener("keyup",Y,!1),this.handleResize(),this.update()};n.prototype=Object.create(q.EventDispatcher.prototype);"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function i(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function r(e,t){return e(t={exports:{}},t.exports),t.exports}var a=r(function(e,t){e.exports=function(n){function o(e){if(i[e])return i[e].exports;var t=i[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,o),t.l=!0,t.exports}var i={};return o.m=n,o.c=i,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=0)}([function(e,t,n){var o,i,r;i=[e,t],void 0!==(r="function"==typeof(o=function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(t){return t instanceof Function?t:"string"==typeof t?function(e){return e[t]}:function(e){return t}},e.exports=t.default})?o.apply(t,i):o)&&(e.exports=r)}])}),c=i(a),s=(a.accessorFn,r(function(e,t){"undefined"!=typeof self&&self,e.exports=function(n){var o={};function i(e){if(o[e])return o[e].exports;var t=o[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,i),t.l=!0,t.exports}return i.m=n,i.c=o,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0)}([function(e,t,n){var o,i,r,a;a=function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=e.stateInit,o=void 0===t?function(){return{}}:t,n=e.props,i=void 0===n?{}:n,r=e.methods,c=void 0===r?{}:r,a=e.aliases,s=void 0===a?{}:a,u=e.init,d=void 0===u?function(){}:u,p=e.update,l=void 0===p?function(){}:p,h=Object.keys(i).map(function(e){return new v(e,i[e])});return function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},r=Object.assign({},o instanceof Function?o():o,{initialised:!1});function a(e){return n(e,t),i(),a}var n=function(e,t){d.call(a,e,r,t),r.initialised=!0},i=(0,f.default)(function(){r.initialised&&l.call(a,r)},1);return h.forEach(function(e){a[e.name]=function(t){var n=1<arguments.length&&void 0!==arguments[1]&&arguments[1],o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:function(e,t){};return function(e){return arguments.length?(r[t]=e,o.call(a,e,r),n&&i(),a):r[t]}}(e.name,e.triggerUpdate,e.onChange)}),Object.keys(c).forEach(function(i){a[i]=function(){for(var e,t=arguments.length,n=Array(t),o=0;o<t;o++)n[o]=arguments[o];return(e=c[i]).call.apply(e,[a,r].concat(n))}}),Object.entries(s).forEach(function(e){var t=m(e,2),n=t[0],o=t[1];return a[n]=a[o]}),a.resetProps=function(){return h.forEach(function(e){a[e.name](e.defaultVal)}),a},a.resetProps(),r._rerender=i,a}};var o,f=(o=n)&&o.__esModule?o:{default:o},m=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],o=!0,i=!1,r=void 0;try{for(var a,c=e[Symbol.iterator]();!(o=(a=c.next()).done)&&(n.push(a.value),!t||n.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{!o&&c.return&&c.return()}finally{if(i)throw r}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},v=function e(t,n){var o=n.default,i=void 0===o?null:o,r=n.triggerUpdate,a=void 0===r||r,c=n.onChange,s=void 0===c?function(e,t){}:c;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.name=t,this.defaultVal=i,this.triggerUpdate=a,this.onChange=s};e.exports=t.default},i=[e,t,n(1)],void 0===(r="function"==typeof(o=a)?o.apply(t,i):o)||(e.exports=r)},function(e,t){e.exports=function(t,n,o){var i,r,a,c,s;function u(){var e=Date.now()-c;e<n&&0<=e?i=setTimeout(u,n-e):(i=null,o||(s=t.apply(a,r),a=r=null))}null==n&&(n=100);var e=function(){a=this,r=arguments,c=Date.now();var e=o&&!i;return i||(i=setTimeout(u,n)),e&&(s=t.apply(a,r),a=r=null),s};return e.clear=function(){i&&(clearTimeout(i),i=null)},e.flush=function(){i&&(s=t.apply(a,r),a=r=null,clearTimeout(i),i=null)},e}}])})),u=i(s),d=(s.Kapsule,window.THREE?window.THREE:{WebGLRenderer:e.WebGLRenderer,Scene:e.Scene,PerspectiveCamera:e.PerspectiveCamera,AmbientLight:e.AmbientLight,Raycaster:e.Raycaster,Vector2:e.Vector2});return u({props:{width:{default:window.innerWidth},height:{default:window.innerHeight},showNavInfo:{default:!0},objects:{default:[],onChange:function(e,t){(t.prevObjs||[]).forEach(function(e){return t.scene.remove(e)}),(t.prevObjs=e).forEach(function(e){return t.scene.add(e)})},triggerUpdate:!1},enablePointerInteraction:{default:!0,onChange:function(e,t){t.hoverObj=null},triggerUpdate:!1},lineHoverPrecision:{default:1,triggerUpdate:!1},tooltipContent:{triggerUpdate:!1},onHover:{default:function(){},triggerUpdate:!1},onClick:{default:function(){},triggerUpdate:!1}},methods:{tick:function(e){if(e.initialised&&(e.tbControls.update(),e.renderer.render(e.scene,e.camera),e.enablePointerInteraction)){var t=new d.Raycaster;t.linePrecision=e.lineHoverPrecision,t.setFromCamera(e.mousePos,e.camera);var n=t.intersectObjects(e.objects),o=n.length?n[0].object:null;o!==e.hoverObj&&(e.onHover(o,e.hoverObj),e.toolTipElem.innerHTML=o&&c(e.tooltipContent)(o)||"",e.hoverObj=o)}return this},renderer:function(e){return e.renderer},scene:function(e){return e.scene},camera:function(e){return e.camera}},stateInit:{renderer:new d.WebGLRenderer,scene:new d.Scene,camera:new d.PerspectiveCamera},init:function(e,s){e.innerHTML="",e.appendChild(s.container=document.createElement("div")),s.container.style.position="relative",s.container.appendChild(s.navInfo=document.createElement("div")),s.navInfo.className="scene-nav-info",s.navInfo.textContent="MOVE mouse & press LEFT/A: rotate, MIDDLE/S: zoom, RIGHT/D: pan",s.toolTipElem=document.createElement("div"),s.toolTipElem.classList.add("scene-tooltip"),s.container.appendChild(s.toolTipElem),s.mousePos=new d.Vector2,s.mousePos.x=-2,s.mousePos.y=-2,s.container.addEventListener("mousemove",function(e){if(s.enablePointerInteraction){var t=(i=s.container,r=i.getBoundingClientRect(),a=window.pageXOffset||document.documentElement.scrollLeft,c=window.pageYOffset||document.documentElement.scrollTop,{top:r.top+c,left:r.left+a}),n=e.pageX-t.left,o=e.pageY-t.top;s.mousePos.x=n/s.width*2-1,s.mousePos.y=-o/s.height*2+1,s.toolTipElem.style.top=o+"px",s.toolTipElem.style.left=n+"px"}var i,r,a,c},!1),s.container.addEventListener("click",function(e){s.hoverObj&&s.onClick(s.hoverObj)},!1),s.renderer.setSize(s.width,s.height),s.container.appendChild(s.renderer.domElement),s.tbControls=new o(s.camera,s.renderer.domElement),s.tbControls.minDistance=.1,s.tbControls.maxDistance=5e4,s.camera.position.z=1e3,s.camera.far=5e4,window.scene=s.scene},update:function(e){e.width&&e.height&&(e.container.style.width=e.width,e.container.style.height=e.height,e.renderer.setSize(e.width,e.height),e.camera.aspect=e.width/e.height,e.camera.updateProjectionMatrix()),e.navInfo.style.display=e.showNavInfo?null:"none"}})});

@@ -171,2 +171,3 @@ import { WebGLRenderer, Scene, PerspectiveCamera, AmbientLight, Raycaster, Vector2 } from 'three';

// Setup renderer, camera and controls
state.renderer.setSize(state.width, state.height);
state.container.appendChild(state.renderer.domElement);

@@ -173,0 +174,0 @@ state.tbControls = new ThreeTrackballControls(state.camera, state.renderer.domElement);

{
"name": "three-render-objects",
"version": "0.1.0",
"version": "0.1.1",
"description": "Easy way to render ThreeJS objects with built-in interaction defaults",

@@ -5,0 +5,0 @@ "unpkg": "dist/three-render-objects.min.js",

@@ -135,2 +135,3 @@ import {

// Setup renderer, camera and controls
state.renderer.setSize(state.width, state.height);
state.container.appendChild(state.renderer.domElement);

@@ -137,0 +138,0 @@ state.tbControls = new ThreeTrackballControls(state.camera, state.renderer.domElement);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc