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/index.cjs.js +1 -1
- package/package.json +1 -1
- package/renderers/CSS2DRenderer.cjs.js +1 -1
- package/renderers/CSS2DRenderer.js +124 -99
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three")
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
17
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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
|
-
|
|
34
|
+
const _a = /*#__PURE__*/new Vector3();
|
|
29
35
|
|
|
30
|
-
|
|
36
|
+
const _b = /*#__PURE__*/new Vector3();
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
let _width, _height;
|
|
43
|
+
|
|
44
|
+
let _widthHalf, _heightHalf;
|
|
45
|
+
|
|
46
|
+
const cache = {
|
|
47
|
+
objects: new WeakMap()
|
|
46
48
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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
|
-
|
|
72
|
-
|
|
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
|
-
|
|
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
|
-
|
|
79
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
110
|
-
|
|
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
|
-
|
|
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 };
|