@expofp/renderer 2.0.1 → 2.1.1
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/dist/index.js +21 -11
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -8,7 +8,8 @@ import { BatchedText as BatchedText$1, Text as Text$1 } from "troika-three-text"
|
|
|
8
8
|
import createLog from "debug";
|
|
9
9
|
import { LineMaterial, LineSegmentsGeometry } from "three/examples/jsm/Addons.js";
|
|
10
10
|
import { MaxRectsPacker, Rectangle } from "maxrects-packer";
|
|
11
|
-
import {
|
|
11
|
+
import { extend, colord } from "colord";
|
|
12
|
+
import namesPlugin from "colord/plugins/names";
|
|
12
13
|
import { RAD2DEG, DEG2RAD as DEG2RAD$1 } from "three/src/math/MathUtils.js";
|
|
13
14
|
import { EventManager, Rotate, Pan } from "mjolnir.js";
|
|
14
15
|
const floatsPerMember = 32;
|
|
@@ -368,7 +369,8 @@ const dimColorFrag = (
|
|
|
368
369
|
}`
|
|
369
370
|
);
|
|
370
371
|
function createLogger(namespace) {
|
|
371
|
-
const
|
|
372
|
+
const fullNamespace = namespace ? `renderer:${namespace}` : "renderer";
|
|
373
|
+
const info = createLog(fullNamespace);
|
|
372
374
|
info.log = console.info.bind(console);
|
|
373
375
|
const debug = info.extend("debug");
|
|
374
376
|
debug.log = console.debug.bind(console);
|
|
@@ -1721,6 +1723,7 @@ class Polygon {
|
|
|
1721
1723
|
}
|
|
1722
1724
|
}
|
|
1723
1725
|
const logger$7 = createLogger("mesh");
|
|
1726
|
+
extend([namesPlugin]);
|
|
1724
1727
|
class MeshSystem extends RenderableSystem {
|
|
1725
1728
|
/**
|
|
1726
1729
|
* @param materialSystem {@link MaterialSystem}
|
|
@@ -1728,7 +1731,6 @@ class MeshSystem extends RenderableSystem {
|
|
|
1728
1731
|
*/
|
|
1729
1732
|
constructor(materialSystem, renderer) {
|
|
1730
1733
|
super("mesh", renderer, logger$7);
|
|
1731
|
-
__publicField(this, "toRgbConverter", converter("rgb"));
|
|
1732
1734
|
__publicField(this, "meshColor", new Color());
|
|
1733
1735
|
this.materialSystem = materialSystem;
|
|
1734
1736
|
}
|
|
@@ -1743,10 +1745,10 @@ class MeshSystem extends RenderableSystem {
|
|
|
1743
1745
|
shapes,
|
|
1744
1746
|
(shapeDef) => {
|
|
1745
1747
|
var _a2;
|
|
1746
|
-
return (((_a2 = mapShapeToNormColor.get(shapeDef)) == null ? void 0 : _a2.
|
|
1748
|
+
return (((_a2 = mapShapeToNormColor.get(shapeDef)) == null ? void 0 : _a2.a) ?? 1) === 1;
|
|
1747
1749
|
}
|
|
1748
1750
|
);
|
|
1749
|
-
const transparentShapesGrouped = groupBy(transparentShapes, (shapeDef) => mapShapeToNormColor.get(shapeDef).
|
|
1751
|
+
const transparentShapesGrouped = groupBy(transparentShapes, (shapeDef) => mapShapeToNormColor.get(shapeDef).a);
|
|
1750
1752
|
const group = new Group();
|
|
1751
1753
|
for (const [opacity, shapes2] of transparentShapesGrouped) {
|
|
1752
1754
|
const transparentMesh = this.buildBatchedMesh(shapes2, opacity);
|
|
@@ -1768,9 +1770,12 @@ class MeshSystem extends RenderableSystem {
|
|
|
1768
1770
|
}
|
|
1769
1771
|
updateDefImpl(shapeDef, mesh, instanceIds) {
|
|
1770
1772
|
const color = this.normalizeColor(shapeDef.color);
|
|
1771
|
-
if (color
|
|
1773
|
+
if (!color) {
|
|
1774
|
+
logger$7.warn(`Invalid color: ${shapeDef.color} %O`, shapeDef);
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1772
1777
|
for (const instanceId of instanceIds) {
|
|
1773
|
-
mesh.setColorAt(instanceId, this.meshColor.setRGB(color.r, color.g, color.b, SRGBColorSpace));
|
|
1778
|
+
mesh.setColorAt(instanceId, this.meshColor.setRGB(color.r / 255, color.g / 255, color.b / 255, SRGBColorSpace));
|
|
1774
1779
|
}
|
|
1775
1780
|
}
|
|
1776
1781
|
buildBatchedMesh(shapes, opacity = 1) {
|
|
@@ -1801,7 +1806,9 @@ class MeshSystem extends RenderableSystem {
|
|
|
1801
1806
|
const rotation = new Quaternion();
|
|
1802
1807
|
const scale = new Vector3();
|
|
1803
1808
|
const matrix = new Matrix4();
|
|
1804
|
-
|
|
1809
|
+
const [rects, polygons] = partition(shapes, (shapeDef) => shapeDef.shape instanceof Rect);
|
|
1810
|
+
const sortedShapes = [...rects, ...polygons];
|
|
1811
|
+
for (const shapeDef of sortedShapes) {
|
|
1805
1812
|
let instanceId = void 0;
|
|
1806
1813
|
if (shapeDef.shape instanceof Rect && rectGeometryId !== void 0) {
|
|
1807
1814
|
instanceId = batchedMesh.addInstance(rectGeometryId);
|
|
@@ -1820,8 +1827,11 @@ class MeshSystem extends RenderableSystem {
|
|
|
1820
1827
|
}
|
|
1821
1828
|
return batchedMesh;
|
|
1822
1829
|
}
|
|
1823
|
-
normalizeColor(
|
|
1824
|
-
|
|
1830
|
+
normalizeColor(colorInput) {
|
|
1831
|
+
const colorString = typeof colorInput === "string" ? colorInput : `#${colorInput.toString(16).padStart(6, "0")}`;
|
|
1832
|
+
const color = colord(colorString);
|
|
1833
|
+
if (!color.isValid()) return void 0;
|
|
1834
|
+
return color.toRgb();
|
|
1825
1835
|
}
|
|
1826
1836
|
buildPolygonGeometry(polygon) {
|
|
1827
1837
|
const geometry = new BufferGeometry().setFromPoints(polygon.vertices).setIndex(polygon.indices.flat());
|
|
@@ -6212,7 +6222,7 @@ class InteractionsSystem {
|
|
|
6212
6222
|
this.canvasListeners = void 0;
|
|
6213
6223
|
}
|
|
6214
6224
|
}
|
|
6215
|
-
const logger = createLogger("
|
|
6225
|
+
const logger = createLogger("");
|
|
6216
6226
|
class Renderer {
|
|
6217
6227
|
/**
|
|
6218
6228
|
* @param opts {@link RendererOptions}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expofp/renderer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
},
|
|
11
11
|
"exports": "./dist/index.js",
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@types/culori": "^2.1.1",
|
|
14
13
|
"@types/debug": "^4.1.12",
|
|
15
14
|
"@types/object-hash": "^3.0.6",
|
|
16
15
|
"@types/three": "^0.174.0",
|
|
17
16
|
"stats-gl": "^3.6.0",
|
|
18
17
|
"typescript": "^5.2.2",
|
|
19
18
|
"vite": "^5.2.0",
|
|
19
|
+
"vite-bundle-analyzer": "^1.3.2",
|
|
20
20
|
"vite-plugin-dts": "^4.5.4",
|
|
21
21
|
"vite-plugin-externalize-deps": "^0.9.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"camera-controls": "^3.1.1",
|
|
25
|
-
"
|
|
25
|
+
"colord": "^2.9.3",
|
|
26
26
|
"debug": "^4.4.3",
|
|
27
27
|
"maxrects-packer": "^2.7.3",
|
|
28
28
|
"mjolnir.js": "^3.0.0",
|