@terraware/web-components 5.0.27-rc.0 → 5.0.27
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/components/AntSwitch/index.js +22 -19
- package/components/Autocomplete/Autocomplete.js +130 -106
- package/components/Badge/index.js +29 -28
- package/components/BusySpinner/index.js +45 -40
- package/components/Button/Button.js +47 -41
- package/components/Checkbox.js +63 -64
- package/components/Confirm/index.js +83 -74
- package/components/DatePicker/DatePicker.js +141 -138
- package/components/DialogBox/DialogBox.js +118 -111
- package/components/Divisor.js +18 -18
- package/components/Dropdown.js +94 -66
- package/components/EditableTable/index.js +271 -211
- package/components/ErrorBox/ErrorBox.js +49 -47
- package/components/FileChooser/index.js +135 -117
- package/components/FormBottomBar/index.js +84 -75
- package/components/Icon/Icon.js +20 -12
- package/components/Icon/icons/index.js +256 -256
- package/components/IconTooltip/index.js +60 -49
- package/components/Map/MapBox.js +452 -545
- package/components/Map/MapContainer.js +29 -25
- package/components/Map/MapDateSliderControl.js +64 -64
- package/components/Map/MapDrawer.js +47 -41
- package/components/Map/MapLegend.js +172 -176
- package/components/Map/MapViewStyleControl.js +63 -59
- package/components/Map/ReactMapboxWrapper.js +2 -3
- package/components/Map/index.js +180 -161
- package/components/Map/types.js +17 -12
- package/components/Map/useMaintainLayerOrder.js +26 -16
- package/components/Markdown/index.js +26 -25
- package/components/Message/Message.js +76 -73
- package/components/MultiSelect/index.js +124 -112
- package/components/Navbar/NavFooter.js +13 -9
- package/components/Navbar/NavItem.js +76 -70
- package/components/Navbar/NavSection.js +19 -17
- package/components/Navbar/Navbar.js +46 -39
- package/components/Navbar/SubNavbar.js +13 -9
- package/components/Note.js +22 -18
- package/components/OverlayModal/OverlayModal.js +63 -56
- package/components/PageForm/index.js +41 -33
- package/components/PhotoChooser/index.js +173 -165
- package/components/PhotosCarousel/PhotoSlide.js +35 -32
- package/components/PhotosCarousel/index.js +85 -80
- package/components/PhotosCarousel/usePhotosCarousel.js +76 -69
- package/components/Pill/index.js +45 -41
- package/components/PillList/index.js +24 -17
- package/components/PlacementWrapper/index.js +59 -38
- package/components/PopoverMenu/Popover.js +85 -68
- package/components/PopoverMenu/index.js +56 -51
- package/components/PopoverMultiSelect/index.js +59 -52
- package/components/ProgressCircle/ProgressCircle.js +32 -28
- package/components/RadioButton.js +19 -17
- package/components/Select/Select.js +15 -13
- package/components/Select/SelectT.js +250 -235
- package/components/Separator/index.js +17 -14
- package/components/Size.js +1 -0
- package/components/Slider/index.js +56 -43
- package/components/SummaryBox.js +72 -70
- package/components/Tabs/index.js +135 -133
- package/components/TextTruncated/index.js +130 -117
- package/components/Textfield/Textfield.js +190 -158
- package/components/Textfield/TruncatedTextArea.js +84 -70
- package/components/TimelineSlider/TimelineMarker.js +30 -25
- package/components/TimelineSlider/TimelineRail.js +11 -8
- package/components/TimelineSlider/index.js +66 -64
- package/components/TimelineSliderV2/ClusterBadge.js +29 -25
- package/components/TimelineSliderV2/TimelineDot.js +35 -31
- package/components/TimelineSliderV2/TimelineRail.js +11 -8
- package/components/TimelineSliderV2/index.js +103 -121
- package/components/TimelineSliderV2/layout.js +147 -124
- package/components/TimelineSliderV2/types.js +1 -0
- package/components/Tooltip/Tooltip.js +56 -47
- package/components/ViewPhotosDialog/index.js +35 -28
- package/components/VirtualWalkthrough/Annotation.js +207 -163
- package/components/VirtualWalkthrough/AnnotationEditPane.js +184 -198
- package/components/VirtualWalkthrough/AnnotationPanel.js +199 -187
- package/components/VirtualWalkthrough/Application.js +34 -31
- package/components/VirtualWalkthrough/AutoRotator.js +223 -85
- package/components/VirtualWalkthrough/BlockingSpinner.js +28 -26
- package/components/VirtualWalkthrough/BoundaryRing.js +34 -30
- package/components/VirtualWalkthrough/BoundaryWall.js +36 -32
- package/components/VirtualWalkthrough/CameraInfo.js +89 -100
- package/components/VirtualWalkthrough/ControlsInfoPane.js +195 -254
- package/components/VirtualWalkthrough/GradientSky.js +73 -72
- package/components/VirtualWalkthrough/SplatControls.js +221 -209
- package/components/VirtualWalkthrough/SplatCrop.js +20 -21
- package/components/VirtualWalkthrough/SplatFadeCrop.js +20 -21
- package/components/VirtualWalkthrough/SplatModel.js +85 -65
- package/components/VirtualWalkthrough/SplatRevealRain.js +46 -41
- package/components/VirtualWalkthrough/TfAnnotationManager.js +379 -197
- package/components/VirtualWalkthrough/TfXrNavigation.js +162 -73
- package/components/VirtualWalkthrough/VirtualWalkthroughViewer.js +431 -438
- package/components/VirtualWalkthrough/VrAnnotationPanel.js +22 -18
- package/components/VirtualWalkthrough/XrAnnotationInteraction.js +17 -14
- package/components/VirtualWalkthrough/XrExitButton.js +17 -14
- package/components/VirtualWalkthrough/XrGazeDwell.js +17 -14
- package/components/VirtualWalkthrough/XrPointerRay.js +17 -14
- package/components/VirtualWalkthrough/XrStartPose.js +121 -67
- package/components/VirtualWalkthrough/boundary-ring.js +117 -87
- package/components/VirtualWalkthrough/boundary-wall.js +258 -175
- package/components/VirtualWalkthrough/camera-adoption.js +64 -18
- package/components/VirtualWalkthrough/groundPlane.js +47 -32
- package/components/VirtualWalkthrough/gsplat-fade-crop-effect.js +35 -35
- package/components/VirtualWalkthrough/splatFormat.js +47 -13
- package/components/VirtualWalkthrough/useAdoptedCamera.js +44 -23
- package/components/VirtualWalkthrough/useRestartOnVr.js +37 -26
- package/components/VirtualWalkthrough/useXrRenderTuning.js +54 -33
- package/components/VirtualWalkthrough/vr-annotation-panel-layout.js +99 -67
- package/components/VirtualWalkthrough/vr-annotation-panel.js +433 -403
- package/components/VirtualWalkthrough/vr-annotation-scroll.js +28 -10
- package/components/VirtualWalkthrough/walkthrough-camera.js +329 -204
- package/components/VirtualWalkthrough/xr-annotation-candidate-buffer.js +80 -39
- package/components/VirtualWalkthrough/xr-annotation-candidates.js +18 -6
- package/components/VirtualWalkthrough/xr-annotation-interaction.js +56 -31
- package/components/VirtualWalkthrough/xr-annotation-targeting.js +38 -22
- package/components/VirtualWalkthrough/xr-button-arming.js +17 -7
- package/components/VirtualWalkthrough/xr-button-hold.js +36 -22
- package/components/VirtualWalkthrough/xr-exit-button-mask.js +36 -22
- package/components/VirtualWalkthrough/xr-exit-button.js +207 -148
- package/components/VirtualWalkthrough/xr-face-buttons.js +29 -19
- package/components/VirtualWalkthrough/xr-gaze-dwell-state.js +34 -23
- package/components/VirtualWalkthrough/xr-gaze-dwell.js +144 -107
- package/components/VirtualWalkthrough/xr-interactive-ui.js +24 -12
- package/components/VirtualWalkthrough/xr-pointer-ray.js +20 -13
- package/components/VirtualWalkthrough/xr-progress-pie-material.js +88 -117
- package/components/VirtualWalkthrough/xr-progress-pie.js +10 -1
- package/components/VirtualWalkthrough/xr-ray-quad.js +30 -16
- package/components/VirtualWalkthrough/xr-render-tuning.js +48 -17
- package/components/VirtualWalkthrough/xr-scene-bounds.js +37 -21
- package/components/VirtualWalkthrough/xr-start-pose.js +73 -27
- package/components/VirtualWalkthrough/xr-teleport-gesture.js +42 -16
- package/components/svg/BlobbyGrayIconImage.js +39 -41
- package/components/svg/BlobbyGrayIconImport.js +39 -41
- package/components/svg/BlobbyGrayIconUploadToTheCloud.js +39 -41
- package/components/svg/BlobbyIconCloudChecked.js +164 -202
- package/components/svg/BlobbyIconExportOrUploadPhoto.js +164 -202
- package/components/svg/BlobbyIconFolder.js +164 -202
- package/components/svg/BlobbyIconGraphReport.js +164 -202
- package/components/svg/BlobbyIconHappy.js +164 -202
- package/components/svg/BlobbyIconHeartMonitor.js +164 -202
- package/components/svg/BlobbyIconLeaf.js +164 -202
- package/components/svg/BlobbyIconLibrary.js +164 -202
- package/components/svg/BlobbyIconNursery.js +166 -204
- package/components/svg/BlobbyIconOrganization.js +164 -202
- package/components/svg/BlobbyIconParchment.js +164 -202
- package/components/svg/BlobbyIconPeople.js +164 -202
- package/components/svg/BlobbyIconSeedBank.js +164 -202
- package/components/svg/BlobbyIconSeedling.js +164 -202
- package/components/svg/BlobbyIconSeeds.js +164 -202
- package/components/svg/BlobbyIconSite.js +167 -206
- package/components/svg/BlobbyIconSparkles.js +164 -202
- package/components/svg/BlobbyIconWrench.js +164 -202
- package/components/svg/Bug.js +21 -19
- package/components/svg/Calendar.js +21 -19
- package/components/svg/CaretDown.js +21 -19
- package/components/svg/CaretLeft.js +21 -19
- package/components/svg/CaretRight.js +21 -19
- package/components/svg/CaretUp.js +21 -19
- package/components/svg/ChevronDown.js +21 -19
- package/components/svg/ChevronUp.js +21 -19
- package/components/svg/Close.js +21 -19
- package/components/svg/Critical.js +21 -19
- package/components/svg/Edit.js +164 -202
- package/components/svg/Error.js +21 -19
- package/components/svg/Filter.js +21 -19
- package/components/svg/Folder.js +21 -19
- package/components/svg/Help.js +21 -19
- package/components/svg/Home.js +21 -19
- package/components/svg/IconAdd.js +21 -19
- package/components/svg/IconArrowRight.js +23 -21
- package/components/svg/IconBusinessNetwork.js +21 -19
- package/components/svg/IconCalendar.js +21 -19
- package/components/svg/IconCancel.js +21 -19
- package/components/svg/IconChargingBattery.js +21 -19
- package/components/svg/IconChecklist.js +23 -21
- package/components/svg/IconCheckmark.js +21 -19
- package/components/svg/IconCoinInHand.js +21 -19
- package/components/svg/IconColumns.js +21 -19
- package/components/svg/IconComment.js +22 -20
- package/components/svg/IconDashboard.js +21 -19
- package/components/svg/IconDataMigration.js +21 -19
- package/components/svg/IconDocument.js +23 -21
- package/components/svg/IconDownloadFromTheCloud.js +23 -21
- package/components/svg/IconEdit.js +23 -21
- package/components/svg/IconExpand.js +23 -21
- package/components/svg/IconExport.js +21 -19
- package/components/svg/IconExternalLink.js +21 -19
- package/components/svg/IconEye.js +21 -19
- package/components/svg/IconEyeOff.js +21 -19
- package/components/svg/IconFile.js +21 -19
- package/components/svg/IconFolder.js +21 -19
- package/components/svg/IconFullScreen.js +22 -20
- package/components/svg/IconFutures.js +21 -19
- package/components/svg/IconGraphReport.js +21 -19
- package/components/svg/IconGrid.js +21 -19
- package/components/svg/IconHeartMonitor.js +21 -19
- package/components/svg/IconHelp.js +23 -21
- package/components/svg/IconHistory.js +21 -19
- package/components/svg/IconImport.js +21 -19
- package/components/svg/IconIndex.js +21 -19
- package/components/svg/IconLayers.js +21 -19
- package/components/svg/IconLibrary.js +22 -20
- package/components/svg/IconList.js +21 -19
- package/components/svg/IconLivePlant.js +21 -19
- package/components/svg/IconLocations.js +21 -19
- package/components/svg/IconMail.js +21 -19
- package/components/svg/IconManager.js +21 -19
- package/components/svg/IconMap.js +21 -19
- package/components/svg/IconMarker.js +21 -19
- package/components/svg/IconMenu.js +21 -19
- package/components/svg/IconMenuHorizontal.js +21 -19
- package/components/svg/IconModule.js +21 -19
- package/components/svg/IconMyLocation.js +21 -19
- package/components/svg/IconNote.js +23 -21
- package/components/svg/IconNursery.js +23 -21
- package/components/svg/IconOrg.js +21 -19
- package/components/svg/IconParchment.js +21 -19
- package/components/svg/IconPhoto.js +21 -19
- package/components/svg/IconPlantsFilled.js +21 -19
- package/components/svg/IconRedo.js +21 -19
- package/components/svg/IconRestorationSite.js +21 -19
- package/components/svg/IconSeedBank.js +21 -19
- package/components/svg/IconSeedling.js +21 -19
- package/components/svg/IconSettings.js +21 -19
- package/components/svg/IconSlice.js +21 -19
- package/components/svg/IconSubmit.js +21 -19
- package/components/svg/IconSubtract.js +23 -21
- package/components/svg/IconSynced.js +21 -19
- package/components/svg/IconTrashCan.js +21 -19
- package/components/svg/IconTreasureMap.js +21 -19
- package/components/svg/IconUnavailable.js +21 -19
- package/components/svg/IconUndo.js +21 -19
- package/components/svg/IconVariable.js +21 -19
- package/components/svg/IconVideo.js +31 -30
- package/components/svg/IconWifi.js +21 -19
- package/components/svg/Info.js +21 -19
- package/components/svg/Key.js +21 -19
- package/components/svg/Leaf.js +21 -19
- package/components/svg/Lock.js +21 -19
- package/components/svg/Logo.js +43 -48
- package/components/svg/MenuVertical.js +21 -19
- package/components/svg/Notification.js +21 -19
- package/components/svg/Person.js +21 -19
- package/components/svg/Plus.js +21 -19
- package/components/svg/RestorationSite.js +21 -19
- package/components/svg/Search.js +21 -19
- package/components/svg/Seeds.js +21 -19
- package/components/svg/Site.js +21 -19
- package/components/svg/Sparkles.js +21 -19
- package/components/svg/Species.js +21 -19
- package/components/svg/Species2.js +164 -202
- package/components/svg/Spinner.js +48 -54
- package/components/svg/Star.js +21 -19
- package/components/svg/Success.js +21 -19
- package/components/svg/SuccessFilled.js +21 -19
- package/components/svg/TerrawareLogoDesktop.js +49 -55
- package/components/svg/TerrawareLogoMobile.js +26 -25
- package/components/svg/Touchscreen.js +21 -19
- package/components/svg/UploadCloud.js +164 -202
- package/components/svg/Warning.js +21 -19
- package/components/svg/WelcomeClipboard.js +133 -156
- package/components/svg/index.js +129 -129
- package/components/table/EnhancedTableToolbar.js +74 -68
- package/components/table/EnhancedTableToolbarV2.js +41 -31
- package/components/table/TableCellRenderer.js +231 -196
- package/components/table/TableHeader.js +73 -71
- package/components/table/TableHeaderItem.js +102 -97
- package/components/table/density.js +19 -18
- package/components/table/index.js +369 -350
- package/components/table/sort.js +52 -27
- package/components/table/types.js +1 -0
- package/components/types/index.js +1 -0
- package/hooks/cameraEntityContext.js +13 -2
- package/hooks/useBoolean.js +13 -17
- package/hooks/useCameraPosition.js +56 -56
- package/hooks/useDevicePerformance.js +17 -17
- package/hooks/useXr.js +87 -85
- package/index.js +58 -58
- package/package.json +1 -1
- package/setupTests.js +4 -0
- package/strings/export.js +170 -111
- package/strings/index.js +54 -25
- package/strings/locales.js +41 -21
- package/strings/strings-en.js +51 -49
- package/strings/strings-es.js +51 -49
- package/strings/strings-fr.js +51 -49
- package/strings/strings-gx.js +51 -49
- package/style-dictionary-dist/TerrawareTheme.js +186 -186
- package/theme.js +76 -74
- package/utils/color.js +15 -8
- package/utils/date.js +108 -42
- package/utils/index.js +4 -4
- package/utils/preventDefaultEvent.js +3 -3
- package/utils/text.js +11 -11
- package/utils/useDeviceInfo.js +79 -42
- package/virtualWalkthrough.js +23 -23
|
@@ -1,62 +1,109 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { computeGroundPlane, yOnPlane } from
|
|
3
|
-
import { distanceToCircleEdge } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
import { Script, Vec3, Color, ShaderMaterial, SEMANTIC_TEXCOORD0, SEMANTIC_POSITION, BLEND_NORMAL, CULLFACE_NONE, Mesh, MeshInstance, LAYERID_IMMEDIATE } from 'playcanvas';
|
|
2
|
+
import { computeGroundPlane, yOnPlane } from './groundPlane.js';
|
|
3
|
+
import { distanceToCircleEdge } from './xr-scene-bounds.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Flat-array geometry ready for `Mesh.setPositions` / `Mesh.setUvs` / `Mesh.setIndices`, plus the
|
|
7
|
+
* grid cell counts the shader needs to know how far the UVs run.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Triangle geometry for an upright cylinder standing on the boundary circle. Each segment is a quad
|
|
12
|
+
* (two triangles) spanning from the ground up to `topY`; the base is sampled on the ground plane so
|
|
13
|
+
* the wall meets the dashed BoundaryRing exactly, while the top is a flat ring at `topY` — the user
|
|
14
|
+
* stands on the rig floor, not on the splat's ground plane, so the top is positioned relative to the
|
|
15
|
+
* former and only the base follows the latter.
|
|
16
|
+
*
|
|
17
|
+
* UVs are emitted in **grid cell units** rather than metres — u runs 0..columns around the
|
|
18
|
+
* circumference and v runs 0..rows up the wall — so the shader can draw a line at every whole number
|
|
19
|
+
* and have the seam at u = columns line up perfectly with u = 0.
|
|
20
|
+
*/
|
|
21
|
+
const boundaryWallMesh = ({
|
|
22
|
+
center,
|
|
23
|
+
radius,
|
|
24
|
+
groundPlane,
|
|
25
|
+
baseY,
|
|
26
|
+
topY,
|
|
27
|
+
gridSpacing,
|
|
28
|
+
segments = 96
|
|
29
|
+
}) => {
|
|
30
|
+
if (radius <= 0 || segments <= 0 || gridSpacing <= 0) {
|
|
31
|
+
return {
|
|
32
|
+
positions: [],
|
|
33
|
+
uvs: [],
|
|
34
|
+
indices: [],
|
|
35
|
+
columns: 0,
|
|
36
|
+
rows: 0
|
|
32
37
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
}
|
|
39
|
+
const plane = computeGroundPlane(groundPlane);
|
|
40
|
+
const step = Math.PI * 2 / segments;
|
|
41
|
+
|
|
42
|
+
// First pass: the bottom of every column, which the row count and the extent guard both need
|
|
43
|
+
// before any vertex can be emitted.
|
|
44
|
+
const bottoms = Array.from({
|
|
45
|
+
length: segments
|
|
46
|
+
}, (_, index) => {
|
|
47
|
+
const angle = index * step;
|
|
48
|
+
const x = center.x + radius * Math.cos(angle);
|
|
49
|
+
const z = center.z + radius * Math.sin(angle);
|
|
50
|
+
return {
|
|
51
|
+
x,
|
|
52
|
+
z,
|
|
53
|
+
y: plane ? yOnPlane(x, z, plane.normal, plane.point, baseY) : baseY
|
|
44
54
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
pushColumn(i);
|
|
48
|
-
pushColumn(i + 1);
|
|
49
|
-
indices.push(base, base + 1, base + 3, base, base + 3, base + 2);
|
|
50
|
-
}
|
|
55
|
+
});
|
|
56
|
+
if (bottoms.some(bottom => bottom.y >= topY)) {
|
|
51
57
|
return {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
positions: [],
|
|
59
|
+
uvs: [],
|
|
60
|
+
indices: [],
|
|
61
|
+
columns: 0,
|
|
62
|
+
rows: 0
|
|
57
63
|
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Every column has its own world height once the ground tilts, but v still runs 0..rows uniformly
|
|
67
|
+
// for all of them, so a single row count has to stand for the whole wall. Deriving it from the
|
|
68
|
+
// average bottom is exact for a flat ground plane (the common case) and keeps the cells square on
|
|
69
|
+
// average when the plane is tilted.
|
|
70
|
+
const averageBottomY = bottoms.reduce((total, bottom) => total + bottom.y, 0) / bottoms.length;
|
|
71
|
+
const columns = Math.max(1, Math.round(Math.PI * 2 * radius / gridSpacing));
|
|
72
|
+
const rows = Math.max(1, Math.round((topY - averageBottomY) / gridSpacing));
|
|
73
|
+
const positions = [];
|
|
74
|
+
const uvs = [];
|
|
75
|
+
const indices = [];
|
|
76
|
+
const pushColumn = index => {
|
|
77
|
+
// The closing column (index === segments) reuses column 0's position so the loop shuts exactly,
|
|
78
|
+
// while u keeps counting up to `columns` to place the seam.
|
|
79
|
+
const {
|
|
80
|
+
x,
|
|
81
|
+
z,
|
|
82
|
+
y
|
|
83
|
+
} = bottoms[index % segments];
|
|
84
|
+
const u = index / segments * columns;
|
|
85
|
+
positions.push(x, y, z, x, topY, z);
|
|
86
|
+
uvs.push(u, 0, u, rows);
|
|
87
|
+
};
|
|
88
|
+
for (let i = 0; i < segments; i++) {
|
|
89
|
+
const base = i * 4;
|
|
90
|
+
// Per segment: v0 bottom@a0, v1 top@a0, v2 bottom@a1, v3 top@a1.
|
|
91
|
+
pushColumn(i);
|
|
92
|
+
pushColumn(i + 1);
|
|
93
|
+
indices.push(base, base + 1, base + 3, base, base + 3, base + 2);
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
positions,
|
|
97
|
+
uvs,
|
|
98
|
+
indices,
|
|
99
|
+
columns,
|
|
100
|
+
rows
|
|
101
|
+
};
|
|
58
102
|
};
|
|
59
|
-
|
|
103
|
+
|
|
104
|
+
// GLSL only: @playcanvas/react's Application defaults to deviceTypes [DEVICETYPE_WEBGL2], so the
|
|
105
|
+
// WGSL variants the engine's own shaders carry would never be compiled here.
|
|
106
|
+
const wallVertexGLSL = /* glsl */`
|
|
60
107
|
attribute vec3 vertex_position;
|
|
61
108
|
attribute vec2 aUv0;
|
|
62
109
|
|
|
@@ -73,7 +120,7 @@ const wallVertexGLSL = `
|
|
|
73
120
|
gl_Position = matrix_viewProjection * world;
|
|
74
121
|
}
|
|
75
122
|
`;
|
|
76
|
-
const wallFragmentGLSL =
|
|
123
|
+
const wallFragmentGLSL = /* glsl */`
|
|
77
124
|
uniform vec3 uHeadPos;
|
|
78
125
|
uniform float uFadeDistance;
|
|
79
126
|
uniform float uBlockedFadeScale;
|
|
@@ -118,131 +165,167 @@ const wallFragmentGLSL = `
|
|
|
118
165
|
gl_FragColor = vec4(mix(uCalmColor, uWarnColor, max(proximity, uBlocked)), alpha);
|
|
119
166
|
}
|
|
120
167
|
`;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Structural shape of TfXrNavigation this script depends on, kept local so it does not have to
|
|
171
|
+
* import the navigation script. `enabled` is optional because a disabled script (e.g. while edit
|
|
172
|
+
* mode is on) stops receiving postUpdate and would otherwise latch a stale clampDistance.
|
|
173
|
+
*/
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Draws a Quest-guardian-style boundary wall: an upright cylinder on the bounds circle whose grid
|
|
177
|
+
* fades in and shifts toward a warning colour as the head approaches, and goes to full intensity
|
|
178
|
+
* while XR navigation is actively holding the user back.
|
|
179
|
+
*
|
|
180
|
+
* center / radius / groundPlane / baseY are set imperatively by the BoundaryWall component (see
|
|
181
|
+
* BoundaryWall.tsx for why they are not reactive Script props), which calls `rebuild()` afterwards.
|
|
182
|
+
*/
|
|
121
183
|
class BoundaryWallScript extends Script {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
184
|
+
static scriptName = 'boundaryWall';
|
|
185
|
+
center = new Vec3();
|
|
186
|
+
radius = 0;
|
|
187
|
+
groundPlane = [];
|
|
188
|
+
/** Flat bottom height used when no usable ground plane is supplied. */
|
|
189
|
+
baseY = 0;
|
|
190
|
+
/**
|
|
191
|
+
* Absolute world Y of the wall's top edge. The default puts it 2.5 m above a rig floor at y = 0,
|
|
192
|
+
* which is where the user actually stands - the splat's ground plane can be well below that.
|
|
193
|
+
*/
|
|
194
|
+
topY = 2.5;
|
|
195
|
+
segments = 96;
|
|
196
|
+
gridSpacing = 0.5;
|
|
197
|
+
/** Grid line thickness in world metres. */
|
|
198
|
+
lineWidth = 0.025;
|
|
199
|
+
/** Head distance, in world metres, at which the wall starts to appear. */
|
|
200
|
+
fadeDistance = 1.5;
|
|
201
|
+
/** Multiplier applied to fadeDistance while movement is being clamped. */
|
|
202
|
+
blockedFadeScale = 2.5;
|
|
203
|
+
calmColor = new Color(0.35, 0.7, 1);
|
|
204
|
+
warnColor = new Color(1, 0.45, 0.2);
|
|
205
|
+
_camera = null;
|
|
206
|
+
_navigation = null;
|
|
207
|
+
_headParam = new Float32Array(3);
|
|
208
|
+
initialize() {
|
|
209
|
+
this._material = new ShaderMaterial({
|
|
210
|
+
uniqueName: 'boundary-wall',
|
|
211
|
+
vertexGLSL: wallVertexGLSL,
|
|
212
|
+
fragmentGLSL: wallFragmentGLSL,
|
|
213
|
+
attributes: {
|
|
214
|
+
vertex_position: SEMANTIC_POSITION,
|
|
215
|
+
aUv0: SEMANTIC_TEXCOORD0
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
this._material.blendType = BLEND_NORMAL;
|
|
219
|
+
this._material.cull = CULLFACE_NONE;
|
|
220
|
+
this._material.depthWrite = false;
|
|
221
|
+
this._material.update();
|
|
222
|
+
this._resolveDependencies();
|
|
223
|
+
this.rebuild();
|
|
224
|
+
this.once('destroy', () => {
|
|
225
|
+
this._clearMesh();
|
|
226
|
+
this._material?.destroy();
|
|
227
|
+
this._material = undefined;
|
|
228
|
+
this._camera = null;
|
|
229
|
+
this._navigation = null;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* The camera and the navigation script both live on entities this one does not own. They are
|
|
235
|
+
* resolved lazily rather than once, because script initialize order across sibling entities is not
|
|
236
|
+
* guaranteed and this entity mounts when an XR session starts.
|
|
237
|
+
*/
|
|
238
|
+
_resolveDependencies() {
|
|
239
|
+
if (!this._camera) {
|
|
240
|
+
this._camera = this.app.root.findComponent('camera')?.entity ?? null;
|
|
163
241
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
this._navigation = rig?.script?.tfXrNavigation ?? null;
|
|
169
|
-
}
|
|
242
|
+
if (!this._navigation) {
|
|
243
|
+
const rig = this.app.root.findByName('camera-root');
|
|
244
|
+
// @ts-expect-error - scripts are added dynamically to the entity
|
|
245
|
+
this._navigation = rig?.script?.tfXrNavigation ?? null;
|
|
170
246
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
this._material.setParameter('uBlockedFadeScale', this.blockedFadeScale);
|
|
186
|
-
this._material.setParameter('uRows', geometry.rows);
|
|
187
|
-
this._material.setParameter('uCalmColor', [
|
|
188
|
-
this.calmColor.r,
|
|
189
|
-
this.calmColor.g,
|
|
190
|
-
this.calmColor.b
|
|
191
|
-
]);
|
|
192
|
-
this._material.setParameter('uWarnColor', [
|
|
193
|
-
this.warnColor.r,
|
|
194
|
-
this.warnColor.g,
|
|
195
|
-
this.warnColor.b
|
|
196
|
-
]);
|
|
197
|
-
this._material.setParameter('uBlocked', 0);
|
|
198
|
-
this._material.setParameter('uHeadPos', [
|
|
199
|
-
0,
|
|
200
|
-
0,
|
|
201
|
-
0
|
|
202
|
-
]);
|
|
203
|
-
const mesh = new Mesh(this.app.graphicsDevice);
|
|
204
|
-
mesh.setPositions(geometry.positions);
|
|
205
|
-
mesh.setUvs(0, geometry.uvs);
|
|
206
|
-
mesh.setIndices(geometry.indices);
|
|
207
|
-
mesh.update();
|
|
208
|
-
this._mesh = mesh;
|
|
209
|
-
const meshInstance = new MeshInstance(mesh, this._material);
|
|
210
|
-
if (this.entity.render) this.entity.render.meshInstances = [
|
|
211
|
-
meshInstance
|
|
212
|
-
];
|
|
213
|
-
else this.entity.addComponent('render', {
|
|
214
|
-
meshInstances: [
|
|
215
|
-
meshInstance
|
|
216
|
-
],
|
|
217
|
-
layers: [
|
|
218
|
-
LAYERID_IMMEDIATE
|
|
219
|
-
]
|
|
220
|
-
});
|
|
247
|
+
}
|
|
248
|
+
rebuild() {
|
|
249
|
+
this._clearMesh();
|
|
250
|
+
const geometry = boundaryWallMesh({
|
|
251
|
+
center: this.center,
|
|
252
|
+
radius: this.radius,
|
|
253
|
+
groundPlane: this.groundPlane,
|
|
254
|
+
baseY: this.baseY,
|
|
255
|
+
topY: this.topY,
|
|
256
|
+
gridSpacing: this.gridSpacing,
|
|
257
|
+
segments: this.segments
|
|
258
|
+
});
|
|
259
|
+
if (geometry.positions.length === 0 || !this._material) {
|
|
260
|
+
return;
|
|
221
261
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
262
|
+
|
|
263
|
+
// The shader measures distance in grid cells, so convert. A cell is gridSpacing across only
|
|
264
|
+
// approximately - columns and rows are rounded to whole numbers - but that error is well under
|
|
265
|
+
// a line width, so it is not worth carrying the exact cell size through as a second uniform.
|
|
266
|
+
this._material.setParameter('uLineHalfWidth', this.lineWidth / this.gridSpacing * 0.5);
|
|
267
|
+
this._material.setParameter('uFadeDistance', this.fadeDistance);
|
|
268
|
+
this._material.setParameter('uBlockedFadeScale', this.blockedFadeScale);
|
|
269
|
+
this._material.setParameter('uRows', geometry.rows);
|
|
270
|
+
this._material.setParameter('uCalmColor', [this.calmColor.r, this.calmColor.g, this.calmColor.b]);
|
|
271
|
+
this._material.setParameter('uWarnColor', [this.warnColor.r, this.warnColor.g, this.warnColor.b]);
|
|
272
|
+
this._material.setParameter('uBlocked', 0);
|
|
273
|
+
this._material.setParameter('uHeadPos', [0, 0, 0]);
|
|
274
|
+
const mesh = new Mesh(this.app.graphicsDevice);
|
|
275
|
+
mesh.setPositions(geometry.positions);
|
|
276
|
+
mesh.setUvs(0, geometry.uvs);
|
|
277
|
+
mesh.setIndices(geometry.indices);
|
|
278
|
+
mesh.update();
|
|
279
|
+
this._mesh = mesh;
|
|
280
|
+
const meshInstance = new MeshInstance(mesh, this._material);
|
|
281
|
+
if (this.entity.render) {
|
|
282
|
+
this.entity.render.meshInstances = [meshInstance];
|
|
283
|
+
} else {
|
|
284
|
+
// Immediate layer, drawn after the World layer where the splats render, so the wall is not
|
|
285
|
+
// composited behind them - same reason BoundaryRingScript uses it.
|
|
286
|
+
this.entity.addComponent('render', {
|
|
287
|
+
meshInstances: [meshInstance],
|
|
288
|
+
layers: [LAYERID_IMMEDIATE]
|
|
289
|
+
});
|
|
239
290
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
291
|
+
}
|
|
292
|
+
update() {
|
|
293
|
+
this._resolveDependencies();
|
|
294
|
+
const material = this._material;
|
|
295
|
+
const camera = this._camera;
|
|
296
|
+
if (!material || !camera || !this.entity.render) {
|
|
297
|
+
return;
|
|
246
298
|
}
|
|
299
|
+
const navigation = this._navigation;
|
|
300
|
+
// A disabled navigation script (e.g. edit mode) stops receiving postUpdate, so its
|
|
301
|
+
// clampDistance would otherwise latch whatever value it last held.
|
|
302
|
+
const blocked = navigation?.enabled !== false && (navigation?.clampDistance ?? 0) > 0 ? 1 : 0;
|
|
303
|
+
const reveal = this.fadeDistance * (blocked ? this.blockedFadeScale : 1);
|
|
304
|
+
const head = camera.getPosition();
|
|
305
|
+
|
|
306
|
+
// Skip the transparent draw entirely while the head is deeper inside than the widest reveal
|
|
307
|
+
// radius - every fragment would discard anyway. Toggling render.enabled rather than
|
|
308
|
+
// entity.enabled keeps this update running so the wall can come back.
|
|
309
|
+
const edgeDistance = distanceToCircleEdge(head.x, head.z, this.center.x, this.center.z, this.radius);
|
|
310
|
+
this.entity.render.enabled = this.radius > 0 && edgeDistance > -reveal;
|
|
311
|
+
if (!this.entity.render.enabled) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
this._headParam[0] = head.x;
|
|
315
|
+
this._headParam[1] = head.y;
|
|
316
|
+
this._headParam[2] = head.z;
|
|
317
|
+
material.setParameter('uHeadPos', this._headParam);
|
|
318
|
+
material.setParameter('uBlocked', blocked);
|
|
319
|
+
}
|
|
320
|
+
_clearMesh() {
|
|
321
|
+
if (this.entity.render) {
|
|
322
|
+
this.entity.render.meshInstances = [];
|
|
323
|
+
}
|
|
324
|
+
if (this._mesh) {
|
|
325
|
+
this._mesh.destroy();
|
|
326
|
+
this._mesh = undefined;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
247
329
|
}
|
|
330
|
+
|
|
248
331
|
export { BoundaryWallScript, boundaryWallMesh };
|
|
@@ -1,20 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The pose an adopted camera is put back to when the walkthrough releases it.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A camera the walkthrough took over, and the call that hands it back.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Hands the scene's existing camera to a walkthrough rig that hasn't been given one.
|
|
11
|
+
*
|
|
12
|
+
* A caller mounting the viewer into a scene it doesn't own passes `camera={null}`, because an XR
|
|
13
|
+
* session is welded to the camera component it was started on — `XrManager.camera` is read-only and
|
|
14
|
+
* `start` refuses while a session is running — so a walkthrough that brought a camera of its own
|
|
15
|
+
* could only become the session's camera by ending it, which drops the user out of the headset.
|
|
16
|
+
*
|
|
17
|
+
* That leaves the rig with no camera under it, and everything that poses or solves against the head
|
|
18
|
+
* resolves it with `findComponent('camera')` on the rig: `WalkthroughCamera`'s pointer and keyboard
|
|
19
|
+
* walk, `XrStartPose`, `XrNavigation`'s thumbstick movement and turning, and the bounds clamp all go
|
|
20
|
+
* inert, so the head is never placed at the walkthrough's start point and can never be moved from
|
|
21
|
+
* wherever the host scene left it. Splat LOD is chosen from
|
|
22
|
+
* the camera's distance to each octree node, so the far side of the model stays coarse for the whole
|
|
23
|
+
* session no matter which way the headset turns.
|
|
24
|
+
*
|
|
25
|
+
* Reparenting carries the live camera component with it, so the session, its views, and the host's
|
|
26
|
+
* own clear color and clip planes are all untouched — only which entity the camera hangs off
|
|
27
|
+
* changes. The camera becomes a direct child of the rig, which is exactly where a camera the viewer
|
|
28
|
+
* owns sits, so the rig means the same thing either way.
|
|
29
|
+
*
|
|
30
|
+
* @param root - The scene root to look for a camera in, expected to hold exactly one camera.
|
|
31
|
+
* @param rig - The entity the walkthrough's XR scripts move, `camera-root`.
|
|
32
|
+
* @param ownCamera - The entity the viewer mounts its own camera on. Nothing is adopted when it
|
|
33
|
+
* already carries one.
|
|
34
|
+
* @returns The adopted camera and the call that puts it back, or null when there was nothing to
|
|
35
|
+
* adopt.
|
|
36
|
+
*/
|
|
37
|
+
const adoptSceneCamera = (root, rig, ownCamera) => {
|
|
38
|
+
if (ownCamera.camera) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const camera = root.findComponent('camera')?.entity;
|
|
42
|
+
// isDescendantOf covers a host that mounted the walkthrough inside its own camera, where
|
|
43
|
+
// reparenting would make a cycle.
|
|
44
|
+
if (!camera || camera === rig || !camera.parent || rig.isDescendantOf(camera)) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const previous = {
|
|
48
|
+
parent: camera.parent,
|
|
49
|
+
position: camera.getLocalPosition().clone(),
|
|
50
|
+
rotation: camera.getLocalRotation().clone()
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// addChild keeps the local transform, so the host's authored camera pose survives the move and
|
|
54
|
+
// only has to be restored because a session overwrites it with the head pose every frame.
|
|
55
|
+
rig.addChild(camera);
|
|
56
|
+
return {
|
|
57
|
+
camera,
|
|
58
|
+
release: () => {
|
|
59
|
+
previous.parent.addChild(camera);
|
|
60
|
+
camera.setLocalPosition(previous.position);
|
|
61
|
+
camera.setLocalRotation(previous.rotation);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
19
64
|
};
|
|
65
|
+
|
|
20
66
|
export { adoptSceneCamera };
|
|
@@ -1,35 +1,50 @@
|
|
|
1
|
-
import { Vec3 } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Vec3 } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
/** Compute Y on the plane defined by `normal` passing through `point` at world XZ coords (x, z). */
|
|
4
|
+
const yOnPlane = (x, z, normal, point, fallback) => {
|
|
5
|
+
if (Math.abs(normal.y) < 1e-6) {
|
|
6
|
+
return fallback;
|
|
7
|
+
}
|
|
8
|
+
return point.y - (normal.x * (x - point.x) + normal.z * (z - point.z)) / normal.y;
|
|
5
9
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Derive a ground plane from 3 world-space points.
|
|
13
|
+
* Returns a normalized normal (flipped so normal.y >= 0) and a point on the plane,
|
|
14
|
+
* or null when fewer than 3 points are supplied or they are degenerate/collinear.
|
|
15
|
+
*/
|
|
16
|
+
const computeGroundPlane = points => {
|
|
17
|
+
if (points.length < 3) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const p0 = points[0];
|
|
21
|
+
const p1 = points[1];
|
|
22
|
+
const p2 = points[2];
|
|
23
|
+
const v1x = p1.x - p0.x;
|
|
24
|
+
const v1y = p1.y - p0.y;
|
|
25
|
+
const v1z = p1.z - p0.z;
|
|
26
|
+
const v2x = p2.x - p0.x;
|
|
27
|
+
const v2y = p2.y - p0.y;
|
|
28
|
+
const v2z = p2.z - p0.z;
|
|
29
|
+
let nx = v1y * v2z - v1z * v2y;
|
|
30
|
+
let ny = v1z * v2x - v1x * v2z;
|
|
31
|
+
let nz = v1x * v2y - v1y * v2x;
|
|
32
|
+
const len = Math.sqrt(nx * nx + ny * ny + nz * nz);
|
|
33
|
+
if (len < 1e-10) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
nx /= len;
|
|
37
|
+
ny /= len;
|
|
38
|
+
nz /= len;
|
|
39
|
+
if (ny < 0) {
|
|
40
|
+
nx = -nx;
|
|
41
|
+
ny = -ny;
|
|
42
|
+
nz = -nz;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
normal: new Vec3(nx, ny, nz),
|
|
46
|
+
point: new Vec3(p0.x, p0.y, p0.z)
|
|
47
|
+
};
|
|
34
48
|
};
|
|
49
|
+
|
|
35
50
|
export { computeGroundPlane, yOnPlane };
|