tela.js 1.2.15 → 1.2.16
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
package/src/Camera2D/Camera2D.js
CHANGED
|
@@ -49,7 +49,7 @@ export default class Camera2D {
|
|
|
49
49
|
}
|
|
50
50
|
return {
|
|
51
51
|
to: tela => {
|
|
52
|
-
const elements = scene.
|
|
52
|
+
const elements = scene.getElementsInBox(this.box);
|
|
53
53
|
for (let i = 0; i < elements.length; i++) {
|
|
54
54
|
const element = elements[i];
|
|
55
55
|
const rasterizer = type2render[element.constructor.name];
|
package/src/Scene/BScene.js
CHANGED
|
@@ -31,7 +31,7 @@ export default class BScene extends NaiveScene {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
distanceToPoint(p) {
|
|
34
|
-
return this.
|
|
34
|
+
return this.getElementsNear(p).distanceToPoint(p);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
interceptWithRay(ray, level) {
|
|
@@ -43,9 +43,9 @@ export default class BScene extends NaiveScene {
|
|
|
43
43
|
return this.boundingBoxScene.distanceOnRay(ray, combineLeafs);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
getElementsNear(p) {
|
|
47
47
|
if (this.boundingBoxScene.numberOfLeafs < 2) {
|
|
48
|
-
return this.boundingBoxScene.
|
|
48
|
+
return this.boundingBoxScene.getElementsNear(p);
|
|
49
49
|
}
|
|
50
50
|
const initial = [this.boundingBoxScene.left, this.boundingBoxScene.right]
|
|
51
51
|
.map(x => ({ node: x, distance: x.box.distanceToPoint(p) }));
|
|
@@ -60,7 +60,7 @@ export default class BScene extends NaiveScene {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
getElementsInBox(box) {
|
|
64
64
|
return this.boundingBoxScene.getElemInBox(box);
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -178,7 +178,7 @@ class Node {
|
|
|
178
178
|
return secondHit <= firstHit ? secondHit : firstHit;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
getElementsNear(p) {
|
|
182
182
|
const children = [this.left, this.right].filter(x => x);
|
|
183
183
|
const index = argmin(children, n => n.box.center.sub(p).length());
|
|
184
184
|
return children[index].getElemNear(p);
|
package/src/Scene/KScene.js
CHANGED
|
@@ -36,7 +36,7 @@ export default class KScene extends NaiveScene {
|
|
|
36
36
|
if (this.boundingBoxScene.leafs.length > 0) {
|
|
37
37
|
return distanceFromLeafs(this.boundingBoxScene.leafs, p, combineLeafs);
|
|
38
38
|
}
|
|
39
|
-
return this.
|
|
39
|
+
return this.getElementsNear(p).distanceToPoint(p);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
normalToPoint(p) {
|
|
@@ -44,7 +44,7 @@ export default class KScene extends NaiveScene {
|
|
|
44
44
|
let weight = 0;
|
|
45
45
|
const ones = Vec3(1, 1, 1).scale(1 / (2 * this.k));
|
|
46
46
|
const box = new Box(p.sub(ones), p.add(ones));
|
|
47
|
-
const elements = this.
|
|
47
|
+
const elements = this.getElementsInBox(box);
|
|
48
48
|
const size = elements.length;
|
|
49
49
|
for (let i = 0; i < size; i++) {
|
|
50
50
|
const n = elements[i].normalToPoint(p);
|
|
@@ -63,9 +63,9 @@ export default class KScene extends NaiveScene {
|
|
|
63
63
|
return this.boundingBoxScene.distanceOnRay(ray, combineLeafs);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
getElementsNear(p) {
|
|
67
67
|
if (this.boundingBoxScene.leafs.length > 0) {
|
|
68
|
-
return this.boundingBoxScene.
|
|
68
|
+
return this.boundingBoxScene.getElementsNear(p);
|
|
69
69
|
}
|
|
70
70
|
const initial = [this.boundingBoxScene.left, this.boundingBoxScene.right]
|
|
71
71
|
.map(x => ({ node: x, distance: x.box.distanceToPoint(p) }));
|
|
@@ -86,7 +86,7 @@ export default class KScene extends NaiveScene {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
getElementsInBox(box) {
|
|
90
90
|
return this.boundingBoxScene.getElemInBox(box);
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -221,7 +221,7 @@ class Node {
|
|
|
221
221
|
|
|
222
222
|
distanceToPoint(p) {
|
|
223
223
|
if (!this.left && !this.right) return Number.MAX_VALUE;
|
|
224
|
-
return this.
|
|
224
|
+
return this.getElementsNear(p).distanceToPoint(p);
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
distanceOnRay(ray, combineLeafs) {
|
|
@@ -241,14 +241,14 @@ class Node {
|
|
|
241
241
|
return secondHit <= firstHit ? secondHit : firstHit;
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
|
|
244
|
+
getElementsNear(p) {
|
|
245
245
|
if (this.leafs.length > 0) {
|
|
246
246
|
const minIndex = argmin(this.leafs, x => x.distanceToPoint(p));
|
|
247
247
|
return this.leafs[minIndex].element;
|
|
248
248
|
}
|
|
249
249
|
const children = [this.left, this.right];
|
|
250
250
|
const index = argmin(children, n => n.box.center.sub(p).length());
|
|
251
|
-
return children[index].
|
|
251
|
+
return children[index].getElementsNear(p);
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
getNodeNear(p) {
|
package/src/Scene/NaiveScene.js
CHANGED
|
@@ -85,12 +85,19 @@ export default class NaiveScene {
|
|
|
85
85
|
return this.distanceToPoint(ray.init);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
getElementsNear(p) {
|
|
89
89
|
return this.sceneElements[argmin(this.sceneElements, x => x.distanceToPoint(p))];
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
getElementsInBox(box) {
|
|
93
|
+
let filteredElements = [];
|
|
94
|
+
for (let i = 0; i < this.sceneElements.length; i++) {
|
|
95
|
+
const elem = this.sceneElements[i];
|
|
96
|
+
if (elem.getBoundingBox().collidesWith(box)) {
|
|
97
|
+
filteredElements.push(elem);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return filteredElements;
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
rebuild() {
|
package/src/Scene/RandomScene.js
CHANGED
|
@@ -80,11 +80,11 @@ export default class RandomScene {
|
|
|
80
80
|
return this.sceneElements;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
getElementsInBox(box) {
|
|
84
84
|
return this.boundingBoxScene.getElemIn(box);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
getElementsNear(p) {
|
|
88
88
|
return this.boundingBoxScene.getElemNear(p);
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -105,7 +105,7 @@ export default class RandomScene {
|
|
|
105
105
|
}
|
|
106
106
|
return distance;
|
|
107
107
|
}
|
|
108
|
-
return this.
|
|
108
|
+
return this.getElementsNear(p).distanceToPoint(p);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
normalToPoint(p) {
|
package/src/Scene/VoxelScene.js
CHANGED
|
@@ -116,11 +116,11 @@ export default class VoxelScene extends NaiveScene {
|
|
|
116
116
|
return Number.MAX_VALUE;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
getElementsNear(p) {
|
|
120
120
|
throw Error("Not implemented");
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
getElementsInBox(box) {
|
|
124
124
|
const size = box.diagonal.fold((e, x) => e * x, 1);
|
|
125
125
|
const samples = Math.floor(size / this.gridSpace);
|
|
126
126
|
let elements = [];
|