three-stdlib 2.20.4 → 2.20.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-stdlib",
3
- "version": "2.20.4",
3
+ "version": "2.20.5",
4
4
  "private": false,
5
5
  "description": "stand-alone library of threejs examples",
6
6
  "main": "index.cjs.js",
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=function(t){e.Object3D.call(this),this.element=t||document.createElement("div"),this.element.style.position="absolute",this.addEventListener("removed",(function(){this.traverse((function(e){e.element instanceof Element&&null!==e.element.parentNode&&e.element.parentNode.removeChild(e.element)}))}))};t.prototype=Object.assign(Object.create(e.Object3D.prototype),{constructor:t,copy:function(t,n){return e.Object3D.prototype.copy.call(this,t,n),this.element=t.element.cloneNode(!0),this}});exports.CSS2DObject=t,exports.CSS2DRenderer=function(){var n,r,o,i,a=this,s=new e.Vector3,l=new e.Matrix4,c=new e.Matrix4,d={objects:new WeakMap},u=document.createElement("div");u.style.overflow="hidden",this.domElement=u,this.getSize=function(){return{width:n,height:r}},this.setSize=function(e,t){o=(n=e)/2,i=(r=t)/2,u.style.width=e+"px",u.style.height=t+"px"};var p,m,h=function(e,n,r){if(e instanceof t){e.onBeforeRender(a,n,r),s.setFromMatrixPosition(e.matrixWorld),s.applyMatrix4(c);var l=e.element;l.style.transform="translate(-50%,-50%) translate("+(s.x*o+o)+"px,"+(-s.y*i+i)+"px)",l.style.display=e.visible&&s.z>=-1&&s.z<=1?"":"none";var p={distanceToCameraSquared:f(r,e)};d.objects.set(e,p),l.parentNode!==u&&u.appendChild(l),e.onAfterRender(a,n,r)}for(let t=0,o=e.children.length;t<o;t++)h(e.children[t],n,r)},f=(p=new e.Vector3,m=new e.Vector3,function(e,t){return p.setFromMatrixPosition(e.matrixWorld),m.setFromMatrixPosition(t.matrixWorld),p.distanceToSquared(m)}),x=function(e){var n=function(e){var n=[];return e.traverse((function(e){e instanceof t&&n.push(e)})),n}(e).sort((function(e,t){return d.objects.get(e).distanceToCameraSquared-d.objects.get(t).distanceToCameraSquared})),r=n.length;for(let e=0,t=n.length;e<t;e++)n[e].element.style.zIndex=r-e};this.render=function(e,t){!0===e.autoUpdate&&e.updateMatrixWorld(),null===t.parent&&t.updateMatrixWorld(),l.copy(t.matrixWorldInverse),c.multiplyMatrices(t.projectionMatrix,l),h(e,e,t),x(e)}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Object3D{constructor(e=document.createElement("div")){super(),this.isCSS2DObject=!0,this.element=e,this.element.style.position="absolute",this.element.style.userSelect="none",this.element.setAttribute("draggable",!1),this.addEventListener("removed",(function(){this.traverse((function(e){e.element instanceof Element&&null!==e.element.parentNode&&e.element.parentNode.removeChild(e.element)}))}))}copy(e,t){return super.copy(e,t),this.element=e.element.cloneNode(!0),this}}const r=new e.Vector3,n=new e.Matrix4,o=new e.Matrix4,i=new e.Vector3,s=new e.Vector3;exports.CSS2DObject=t,exports.CSS2DRenderer=class{constructor(e={}){const t=this;let l,a,d,c;const u={objects:new WeakMap},m=void 0!==e.element?e.element:document.createElement("div");function p(e,n,i){if(e.isCSS2DObject){r.setFromMatrixPosition(e.matrixWorld),r.applyMatrix4(o);const s=!0===e.visible&&r.z>=-1&&r.z<=1&&!0===e.layers.test(i.layers);if(e.element.style.display=!0===s?"":"none",!0===s){e.onBeforeRender(t,n,i);const o=e.element;o.style.transform="translate(-50%,-50%) translate("+(r.x*d+d)+"px,"+(-r.y*c+c)+"px)",o.parentNode!==m&&m.appendChild(o),e.onAfterRender(t,n,i)}const l={distanceToCameraSquared:h(i,e)};u.objects.set(e,l)}for(let t=0,r=e.children.length;t<r;t++)p(e.children[t],n,i)}function h(e,t){return i.setFromMatrixPosition(e.matrixWorld),s.setFromMatrixPosition(t.matrixWorld),i.distanceToSquared(s)}m.style.overflow="hidden",this.domElement=m,this.getSize=function(){return{width:l,height:a}},this.render=function(e,t){!0!==e.matrixWorldAutoUpdate&&!0!==e.autoUpdate||e.updateMatrixWorld(),null!==t.parent||null!=t.matrixWorldAutoUpdate&&!0!==t.matrixWorldAutoUpdate||t.updateMatrixWorld(),n.copy(t.matrixWorldInverse),o.multiplyMatrices(t.projectionMatrix,n),p(e,e,t),function(e){const t=function(e){const t=[];return e.traverse((function(e){e.isCSS2DObject&&t.push(e)})),t}(e).sort((function(e,t){if(e.renderOrder!==t.renderOrder)return t.renderOrder-e.renderOrder;return u.objects.get(e).distanceToCameraSquared-u.objects.get(t).distanceToCameraSquared})),r=t.length;for(let e=0,n=t.length;e<n;e++)t[e].element.style.zIndex=r-e}(e)},this.setSize=function(e,t){l=e,a=t,d=l/2,c=a/2,m.style.width=e+"px",m.style.height=t+"px"}}};
@@ -1,124 +1,149 @@
1
1
  import { Object3D, Vector3, Matrix4 } from 'three';
2
2
 
3
- var CSS2DObject = function (element) {
4
- Object3D.call(this);
5
- this.element = element || document.createElement('div');
6
- this.element.style.position = 'absolute';
7
- this.addEventListener('removed', function () {
8
- this.traverse(function (object) {
9
- if (object.element instanceof Element && object.element.parentNode !== null) {
10
- object.element.parentNode.removeChild(object.element);
11
- }
3
+ class CSS2DObject extends Object3D {
4
+ constructor(element = document.createElement('div')) {
5
+ super();
6
+ this.isCSS2DObject = true;
7
+ this.element = element;
8
+ this.element.style.position = 'absolute';
9
+ this.element.style.userSelect = 'none';
10
+ this.element.setAttribute('draggable', false);
11
+ this.addEventListener('removed', function () {
12
+ this.traverse(function (object) {
13
+ if (object.element instanceof Element && object.element.parentNode !== null) {
14
+ object.element.parentNode.removeChild(object.element);
15
+ }
16
+ });
12
17
  });
13
- });
14
- };
18
+ }
15
19
 
16
- CSS2DObject.prototype = Object.assign(Object.create(Object3D.prototype), {
17
- constructor: CSS2DObject,
18
- copy: function (source, recursive) {
19
- Object3D.prototype.copy.call(this, source, recursive);
20
+ copy(source, recursive) {
21
+ super.copy(source, recursive);
20
22
  this.element = source.element.cloneNode(true);
21
23
  return this;
22
24
  }
23
- }); //
24
25
 
25
- var CSS2DRenderer = function () {
26
- var _this = this;
26
+ }
27
+
28
+ const _vector = /*#__PURE__*/new Vector3();
29
+
30
+ const _viewMatrix = /*#__PURE__*/new Matrix4();
31
+
32
+ const _viewProjectionMatrix = /*#__PURE__*/new Matrix4();
27
33
 
28
- var _width, _height;
34
+ const _a = /*#__PURE__*/new Vector3();
29
35
 
30
- var _widthHalf, _heightHalf;
36
+ const _b = /*#__PURE__*/new Vector3();
31
37
 
32
- var vector = new Vector3();
33
- var viewMatrix = new Matrix4();
34
- var viewProjectionMatrix = new Matrix4();
35
- var cache = {
36
- objects: new WeakMap()
37
- };
38
- var domElement = document.createElement('div');
39
- domElement.style.overflow = 'hidden';
40
- this.domElement = domElement;
38
+ class CSS2DRenderer {
39
+ constructor(parameters = {}) {
40
+ const _this = this;
41
41
 
42
- this.getSize = function () {
43
- return {
44
- width: _width,
45
- height: _height
42
+ let _width, _height;
43
+
44
+ let _widthHalf, _heightHalf;
45
+
46
+ const cache = {
47
+ objects: new WeakMap()
46
48
  };
47
- };
48
-
49
- this.setSize = function (width, height) {
50
- _width = width;
51
- _height = height;
52
- _widthHalf = _width / 2;
53
- _heightHalf = _height / 2;
54
- domElement.style.width = width + 'px';
55
- domElement.style.height = height + 'px';
56
- };
57
-
58
- var renderObject = function (object, scene, camera) {
59
- if (object instanceof CSS2DObject) {
60
- object.onBeforeRender(_this, scene, camera);
61
- vector.setFromMatrixPosition(object.matrixWorld);
62
- vector.applyMatrix4(viewProjectionMatrix);
63
- var element = object.element;
64
- element.style.transform = 'translate(-50%,-50%) translate(' + (vector.x * _widthHalf + _widthHalf) + 'px,' + (-vector.y * _heightHalf + _heightHalf) + 'px)';
65
- element.style.display = object.visible && vector.z >= -1 && vector.z <= 1 ? '' : 'none';
66
- var objectData = {
67
- distanceToCameraSquared: getDistanceToSquared(camera, object)
49
+ const domElement = parameters.element !== undefined ? parameters.element : document.createElement('div');
50
+ domElement.style.overflow = 'hidden';
51
+ this.domElement = domElement;
52
+
53
+ this.getSize = function () {
54
+ return {
55
+ width: _width,
56
+ height: _height
68
57
  };
69
- cache.objects.set(object, objectData);
58
+ };
59
+
60
+ this.render = function (scene, camera) {
61
+ if (scene.matrixWorldAutoUpdate === true || scene.autoUpdate === true) scene.updateMatrixWorld();
62
+ if (camera.parent === null && (camera.matrixWorldAutoUpdate == null || camera.matrixWorldAutoUpdate === true)) camera.updateMatrixWorld();
63
+
64
+ _viewMatrix.copy(camera.matrixWorldInverse);
65
+
66
+ _viewProjectionMatrix.multiplyMatrices(camera.projectionMatrix, _viewMatrix);
67
+
68
+ renderObject(scene, scene, camera);
69
+ zOrder(scene);
70
+ };
71
+
72
+ this.setSize = function (width, height) {
73
+ _width = width;
74
+ _height = height;
75
+ _widthHalf = _width / 2;
76
+ _heightHalf = _height / 2;
77
+ domElement.style.width = width + 'px';
78
+ domElement.style.height = height + 'px';
79
+ };
80
+
81
+ function renderObject(object, scene, camera) {
82
+ if (object.isCSS2DObject) {
83
+ _vector.setFromMatrixPosition(object.matrixWorld);
84
+
85
+ _vector.applyMatrix4(_viewProjectionMatrix);
70
86
 
71
- if (element.parentNode !== domElement) {
72
- domElement.appendChild(element);
87
+ const visible = object.visible === true && _vector.z >= -1 && _vector.z <= 1 && object.layers.test(camera.layers) === true;
88
+ object.element.style.display = visible === true ? '' : 'none';
89
+
90
+ if (visible === true) {
91
+ object.onBeforeRender(_this, scene, camera);
92
+ const element = object.element;
93
+ element.style.transform = 'translate(-50%,-50%) translate(' + (_vector.x * _widthHalf + _widthHalf) + 'px,' + (-_vector.y * _heightHalf + _heightHalf) + 'px)';
94
+
95
+ if (element.parentNode !== domElement) {
96
+ domElement.appendChild(element);
97
+ }
98
+
99
+ object.onAfterRender(_this, scene, camera);
100
+ }
101
+
102
+ const objectData = {
103
+ distanceToCameraSquared: getDistanceToSquared(camera, object)
104
+ };
105
+ cache.objects.set(object, objectData);
73
106
  }
74
107
 
75
- object.onAfterRender(_this, scene, camera);
108
+ for (let i = 0, l = object.children.length; i < l; i++) {
109
+ renderObject(object.children[i], scene, camera);
110
+ }
76
111
  }
77
112
 
78
- for (let i = 0, l = object.children.length; i < l; i++) {
79
- renderObject(object.children[i], scene, camera);
113
+ function getDistanceToSquared(object1, object2) {
114
+ _a.setFromMatrixPosition(object1.matrixWorld);
115
+
116
+ _b.setFromMatrixPosition(object2.matrixWorld);
117
+
118
+ return _a.distanceToSquared(_b);
80
119
  }
81
- };
82
-
83
- var getDistanceToSquared = function () {
84
- var a = new Vector3();
85
- var b = new Vector3();
86
- return function (object1, object2) {
87
- a.setFromMatrixPosition(object1.matrixWorld);
88
- b.setFromMatrixPosition(object2.matrixWorld);
89
- return a.distanceToSquared(b);
90
- };
91
- }();
92
120
 
93
- var filterAndFlatten = function (scene) {
94
- var result = [];
95
- scene.traverse(function (object) {
96
- if (object instanceof CSS2DObject) result.push(object);
97
- });
98
- return result;
99
- };
100
-
101
- var zOrder = function (scene) {
102
- var sorted = filterAndFlatten(scene).sort(function (a, b) {
103
- var distanceA = cache.objects.get(a).distanceToCameraSquared;
104
- var distanceB = cache.objects.get(b).distanceToCameraSquared;
105
- return distanceA - distanceB;
106
- });
107
- var zMax = sorted.length;
121
+ function filterAndFlatten(scene) {
122
+ const result = [];
123
+ scene.traverse(function (object) {
124
+ if (object.isCSS2DObject) result.push(object);
125
+ });
126
+ return result;
127
+ }
128
+
129
+ function zOrder(scene) {
130
+ const sorted = filterAndFlatten(scene).sort(function (a, b) {
131
+ if (a.renderOrder !== b.renderOrder) {
132
+ return b.renderOrder - a.renderOrder;
133
+ }
108
134
 
109
- for (let i = 0, l = sorted.length; i < l; i++) {
110
- sorted[i].element.style.zIndex = zMax - i;
135
+ const distanceA = cache.objects.get(a).distanceToCameraSquared;
136
+ const distanceB = cache.objects.get(b).distanceToCameraSquared;
137
+ return distanceA - distanceB;
138
+ });
139
+ const zMax = sorted.length;
140
+
141
+ for (let i = 0, l = sorted.length; i < l; i++) {
142
+ sorted[i].element.style.zIndex = zMax - i;
143
+ }
111
144
  }
112
- };
113
-
114
- this.render = function (scene, camera) {
115
- if (scene.autoUpdate === true) scene.updateMatrixWorld();
116
- if (camera.parent === null) camera.updateMatrixWorld();
117
- viewMatrix.copy(camera.matrixWorldInverse);
118
- viewProjectionMatrix.multiplyMatrices(camera.projectionMatrix, viewMatrix);
119
- renderObject(scene, scene, camera);
120
- zOrder(scene);
121
- };
122
- };
145
+ }
146
+
147
+ }
123
148
 
124
149
  export { CSS2DObject, CSS2DRenderer };