@inweb/viewer-three 26.3.2 → 26.4.0
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/viewer-three.js +131 -129
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +2 -2
- package/dist/viewer-three.module.js +97 -97
- package/dist/viewer-three.module.js.map +1 -1
- package/package.json +5 -5
- package/src/Viewer/commands/ClearSelected.ts +3 -3
- package/src/Viewer/commands/SetSelected.ts +3 -3
|
@@ -1486,103 +1486,10 @@ function clearMarkup(viewer) {
|
|
|
1486
1486
|
viewer.clearOverlay();
|
|
1487
1487
|
}
|
|
1488
1488
|
|
|
1489
|
-
class SelectionComponent {
|
|
1490
|
-
constructor(viewer) {
|
|
1491
|
-
this.onPointerDown = event => {
|
|
1492
|
-
if (!event.isPrimary || event.button !== 0) return;
|
|
1493
|
-
this.getMousePosition(event, this.downPosition);
|
|
1494
|
-
};
|
|
1495
|
-
this.onPointerUp = event => {
|
|
1496
|
-
if (!event.isPrimary) return;
|
|
1497
|
-
const upPosition = this.getMousePosition(event, new Vector2);
|
|
1498
|
-
if (this.downPosition.distanceTo(upPosition) !== 0) return;
|
|
1499
|
-
const intersects = this.getPointerIntersects(upPosition);
|
|
1500
|
-
this.clearSelection();
|
|
1501
|
-
if (intersects.length > 0) this.select(intersects[0].object);
|
|
1502
|
-
this.viewer.update();
|
|
1503
|
-
this.viewer.emitEvent({
|
|
1504
|
-
type: "select",
|
|
1505
|
-
data: undefined,
|
|
1506
|
-
handles: this.viewer.getSelected()
|
|
1507
|
-
});
|
|
1508
|
-
};
|
|
1509
|
-
this.onDoubleClick = event => {
|
|
1510
|
-
if (event.button !== 0) return;
|
|
1511
|
-
this.viewer.executeCommand("zoomToSelected");
|
|
1512
|
-
};
|
|
1513
|
-
this.optionsChange = () => {
|
|
1514
|
-
const {facesColor: facesColor, facesTransparancy: facesTransparancy} = this.viewer.options;
|
|
1515
|
-
this.facesMaterial.color.setRGB(facesColor.r / 255, facesColor.g / 255, facesColor.b / 255);
|
|
1516
|
-
this.facesMaterial.opacity = (255 - facesTransparancy) / 255;
|
|
1517
|
-
this.viewer.update();
|
|
1518
|
-
};
|
|
1519
|
-
this.viewer = viewer;
|
|
1520
|
-
this.raycaster = new Raycaster;
|
|
1521
|
-
this.downPosition = new Vector2;
|
|
1522
|
-
const {facesColor: facesColor, facesTransparancy: facesTransparancy} = this.viewer.options;
|
|
1523
|
-
this.facesMaterial = new MeshBasicMaterial;
|
|
1524
|
-
this.facesMaterial.color.setRGB(facesColor.r / 255, facesColor.g / 255, facesColor.b / 255);
|
|
1525
|
-
this.facesMaterial.opacity = (255 - facesTransparancy) / 255;
|
|
1526
|
-
this.facesMaterial.transparent = true;
|
|
1527
|
-
this.viewer.addEventListener("pointerdown", this.onPointerDown);
|
|
1528
|
-
this.viewer.addEventListener("pointerup", this.onPointerUp);
|
|
1529
|
-
this.viewer.addEventListener("dblclick", this.onDoubleClick);
|
|
1530
|
-
this.viewer.addEventListener("optionschange", this.optionsChange);
|
|
1531
|
-
}
|
|
1532
|
-
dispose() {
|
|
1533
|
-
this.facesMaterial.dispose();
|
|
1534
|
-
this.viewer.removeEventListener("pointerdown", this.onPointerDown);
|
|
1535
|
-
this.viewer.removeEventListener("pointerup", this.onPointerUp);
|
|
1536
|
-
this.viewer.removeEventListener("dblclick", this.onDoubleClick);
|
|
1537
|
-
this.viewer.removeEventListener("optionschange", this.optionsChange);
|
|
1538
|
-
}
|
|
1539
|
-
getMousePosition(event, target) {
|
|
1540
|
-
return target.set(event.clientX, event.clientY);
|
|
1541
|
-
}
|
|
1542
|
-
getPointerIntersects(mouse) {
|
|
1543
|
-
const rect = this.viewer.canvas.getBoundingClientRect();
|
|
1544
|
-
const x = (mouse.x - rect.left) / rect.width * 2 - 1;
|
|
1545
|
-
const y = -(mouse.y - rect.top) / rect.height * 2 + 1;
|
|
1546
|
-
const coords = new Vector2(x, y);
|
|
1547
|
-
this.raycaster.setFromCamera(coords, this.viewer.camera);
|
|
1548
|
-
const objects = [];
|
|
1549
|
-
this.viewer.scene.traverseVisible((child => objects.push(child)));
|
|
1550
|
-
this.raycaster.params = this.raycaster.params = {
|
|
1551
|
-
Mesh: {},
|
|
1552
|
-
Line: {
|
|
1553
|
-
threshold: .25
|
|
1554
|
-
},
|
|
1555
|
-
Line2: {
|
|
1556
|
-
threshold: .25
|
|
1557
|
-
},
|
|
1558
|
-
LOD: {},
|
|
1559
|
-
Points: {
|
|
1560
|
-
threshold: .1
|
|
1561
|
-
},
|
|
1562
|
-
Sprite: {}
|
|
1563
|
-
};
|
|
1564
|
-
return this.raycaster.intersectObjects(objects, false);
|
|
1565
|
-
}
|
|
1566
|
-
select(object) {
|
|
1567
|
-
if (object.isSelected) return;
|
|
1568
|
-
object.isSelected = true;
|
|
1569
|
-
object.originalMaterial = object.material;
|
|
1570
|
-
object.material = this.facesMaterial;
|
|
1571
|
-
this.viewer.selected.push(object);
|
|
1572
|
-
}
|
|
1573
|
-
clearSelection() {
|
|
1574
|
-
this.viewer.selected.forEach((object => {
|
|
1575
|
-
object.isSelected = false;
|
|
1576
|
-
object.material = object.originalMaterial;
|
|
1577
|
-
}));
|
|
1578
|
-
this.viewer.selected.length = 0;
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
1489
|
function clearSelected(viewer) {
|
|
1583
|
-
const selection =
|
|
1490
|
+
const selection = viewer.getComponent("SelectionComponent");
|
|
1491
|
+
if (!selection) return;
|
|
1584
1492
|
selection.clearSelection();
|
|
1585
|
-
selection.dispose();
|
|
1586
1493
|
viewer.update();
|
|
1587
1494
|
viewer.emitEvent({
|
|
1588
1495
|
type: "select",
|
|
@@ -1731,6 +1638,99 @@ function getSelected(viewer) {
|
|
|
1731
1638
|
})).filter((handle => handle));
|
|
1732
1639
|
}
|
|
1733
1640
|
|
|
1641
|
+
class SelectionComponent {
|
|
1642
|
+
constructor(viewer) {
|
|
1643
|
+
this.onPointerDown = event => {
|
|
1644
|
+
if (!event.isPrimary || event.button !== 0) return;
|
|
1645
|
+
this.getMousePosition(event, this.downPosition);
|
|
1646
|
+
};
|
|
1647
|
+
this.onPointerUp = event => {
|
|
1648
|
+
if (!event.isPrimary) return;
|
|
1649
|
+
const upPosition = this.getMousePosition(event, new Vector2);
|
|
1650
|
+
if (this.downPosition.distanceTo(upPosition) !== 0) return;
|
|
1651
|
+
const intersects = this.getPointerIntersects(upPosition);
|
|
1652
|
+
this.clearSelection();
|
|
1653
|
+
if (intersects.length > 0) this.select(intersects[0].object);
|
|
1654
|
+
this.viewer.update();
|
|
1655
|
+
this.viewer.emitEvent({
|
|
1656
|
+
type: "select",
|
|
1657
|
+
data: undefined,
|
|
1658
|
+
handles: this.viewer.getSelected()
|
|
1659
|
+
});
|
|
1660
|
+
};
|
|
1661
|
+
this.onDoubleClick = event => {
|
|
1662
|
+
if (event.button !== 0) return;
|
|
1663
|
+
this.viewer.executeCommand("zoomToSelected");
|
|
1664
|
+
};
|
|
1665
|
+
this.optionsChange = () => {
|
|
1666
|
+
const {facesColor: facesColor, facesTransparancy: facesTransparancy} = this.viewer.options;
|
|
1667
|
+
this.facesMaterial.color.setRGB(facesColor.r / 255, facesColor.g / 255, facesColor.b / 255);
|
|
1668
|
+
this.facesMaterial.opacity = (255 - facesTransparancy) / 255;
|
|
1669
|
+
this.viewer.update();
|
|
1670
|
+
};
|
|
1671
|
+
this.viewer = viewer;
|
|
1672
|
+
this.raycaster = new Raycaster;
|
|
1673
|
+
this.downPosition = new Vector2;
|
|
1674
|
+
const {facesColor: facesColor, facesTransparancy: facesTransparancy} = this.viewer.options;
|
|
1675
|
+
this.facesMaterial = new MeshBasicMaterial;
|
|
1676
|
+
this.facesMaterial.color.setRGB(facesColor.r / 255, facesColor.g / 255, facesColor.b / 255);
|
|
1677
|
+
this.facesMaterial.opacity = (255 - facesTransparancy) / 255;
|
|
1678
|
+
this.facesMaterial.transparent = true;
|
|
1679
|
+
this.viewer.addEventListener("pointerdown", this.onPointerDown);
|
|
1680
|
+
this.viewer.addEventListener("pointerup", this.onPointerUp);
|
|
1681
|
+
this.viewer.addEventListener("dblclick", this.onDoubleClick);
|
|
1682
|
+
this.viewer.addEventListener("optionschange", this.optionsChange);
|
|
1683
|
+
}
|
|
1684
|
+
dispose() {
|
|
1685
|
+
this.facesMaterial.dispose();
|
|
1686
|
+
this.viewer.removeEventListener("pointerdown", this.onPointerDown);
|
|
1687
|
+
this.viewer.removeEventListener("pointerup", this.onPointerUp);
|
|
1688
|
+
this.viewer.removeEventListener("dblclick", this.onDoubleClick);
|
|
1689
|
+
this.viewer.removeEventListener("optionschange", this.optionsChange);
|
|
1690
|
+
}
|
|
1691
|
+
getMousePosition(event, target) {
|
|
1692
|
+
return target.set(event.clientX, event.clientY);
|
|
1693
|
+
}
|
|
1694
|
+
getPointerIntersects(mouse) {
|
|
1695
|
+
const rect = this.viewer.canvas.getBoundingClientRect();
|
|
1696
|
+
const x = (mouse.x - rect.left) / rect.width * 2 - 1;
|
|
1697
|
+
const y = -(mouse.y - rect.top) / rect.height * 2 + 1;
|
|
1698
|
+
const coords = new Vector2(x, y);
|
|
1699
|
+
this.raycaster.setFromCamera(coords, this.viewer.camera);
|
|
1700
|
+
const objects = [];
|
|
1701
|
+
this.viewer.scene.traverseVisible((child => objects.push(child)));
|
|
1702
|
+
this.raycaster.params = this.raycaster.params = {
|
|
1703
|
+
Mesh: {},
|
|
1704
|
+
Line: {
|
|
1705
|
+
threshold: .25
|
|
1706
|
+
},
|
|
1707
|
+
Line2: {
|
|
1708
|
+
threshold: .25
|
|
1709
|
+
},
|
|
1710
|
+
LOD: {},
|
|
1711
|
+
Points: {
|
|
1712
|
+
threshold: .1
|
|
1713
|
+
},
|
|
1714
|
+
Sprite: {}
|
|
1715
|
+
};
|
|
1716
|
+
return this.raycaster.intersectObjects(objects, false);
|
|
1717
|
+
}
|
|
1718
|
+
select(object) {
|
|
1719
|
+
if (object.isSelected) return;
|
|
1720
|
+
object.isSelected = true;
|
|
1721
|
+
object.originalMaterial = object.material;
|
|
1722
|
+
object.material = this.facesMaterial;
|
|
1723
|
+
this.viewer.selected.push(object);
|
|
1724
|
+
}
|
|
1725
|
+
clearSelection() {
|
|
1726
|
+
this.viewer.selected.forEach((object => {
|
|
1727
|
+
object.isSelected = false;
|
|
1728
|
+
object.material = object.originalMaterial;
|
|
1729
|
+
}));
|
|
1730
|
+
this.viewer.selected.length = 0;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
1734
|
function hideSelected(viewer) {
|
|
1735
1735
|
viewer.selected.forEach((object => object.visible = false));
|
|
1736
1736
|
const selection = new SelectionComponent(viewer);
|
|
@@ -1804,10 +1804,10 @@ function setSelected(viewer, handles = []) {
|
|
|
1804
1804
|
var _a;
|
|
1805
1805
|
if (handleSet.has((_a = child.userData) === null || _a === undefined ? undefined : _a.handle)) objects.push(child);
|
|
1806
1806
|
}));
|
|
1807
|
-
const selection =
|
|
1807
|
+
const selection = viewer.getComponent("SelectionComponent");
|
|
1808
|
+
if (!selection) return;
|
|
1808
1809
|
selection.clearSelection();
|
|
1809
1810
|
objects.forEach((object => selection.select(object)));
|
|
1810
|
-
selection.dispose();
|
|
1811
1811
|
viewer.update();
|
|
1812
1812
|
viewer.emitEvent({
|
|
1813
1813
|
type: "select",
|