@spatial-elements/core 0.1.0-beta.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/LICENSE +373 -0
- package/README.md +17 -0
- package/dist/catalog/CarouselGlassCompositor.d.ts +24 -0
- package/dist/catalog/CarouselGlassCompositor.d.ts.map +1 -0
- package/dist/catalog/CarouselGlassCompositor.js +132 -0
- package/dist/catalog/CarouselGlassCompositor.js.map +1 -0
- package/dist/catalog/CatalogEndpointRegistry.d.ts +59 -0
- package/dist/catalog/CatalogEndpointRegistry.d.ts.map +1 -0
- package/dist/catalog/CatalogEndpointRegistry.js +187 -0
- package/dist/catalog/CatalogEndpointRegistry.js.map +1 -0
- package/dist/catalog/CatalogGeometryFade.d.ts +12 -0
- package/dist/catalog/CatalogGeometryFade.d.ts.map +1 -0
- package/dist/catalog/CatalogGeometryFade.js +67 -0
- package/dist/catalog/CatalogGeometryFade.js.map +1 -0
- package/dist/catalog/CatalogPreparation.d.ts +40 -0
- package/dist/catalog/CatalogPreparation.d.ts.map +1 -0
- package/dist/catalog/CatalogPreparation.js +141 -0
- package/dist/catalog/CatalogPreparation.js.map +1 -0
- package/dist/catalog/CatalogSections.d.ts +36 -0
- package/dist/catalog/CatalogSections.d.ts.map +1 -0
- package/dist/catalog/CatalogSections.js +51 -0
- package/dist/catalog/CatalogSections.js.map +1 -0
- package/dist/catalog/CatalogSpatialElementLayer.d.ts +149 -0
- package/dist/catalog/CatalogSpatialElementLayer.d.ts.map +1 -0
- package/dist/catalog/CatalogSpatialElementLayer.js +920 -0
- package/dist/catalog/CatalogSpatialElementLayer.js.map +1 -0
- package/dist/catalog/CatalogTransition.d.ts +93 -0
- package/dist/catalog/CatalogTransition.d.ts.map +1 -0
- package/dist/catalog/CatalogTransition.js +1299 -0
- package/dist/catalog/CatalogTransition.js.map +1 -0
- package/dist/catalog/EnvironmentCache.d.ts +30 -0
- package/dist/catalog/EnvironmentCache.d.ts.map +1 -0
- package/dist/catalog/EnvironmentCache.js +128 -0
- package/dist/catalog/EnvironmentCache.js.map +1 -0
- package/dist/catalog/PreparationGate.d.ts +10 -0
- package/dist/catalog/PreparationGate.d.ts.map +1 -0
- package/dist/catalog/PreparationGate.js +66 -0
- package/dist/catalog/PreparationGate.js.map +1 -0
- package/dist/catalog/PresentationLease.d.ts +16 -0
- package/dist/catalog/PresentationLease.d.ts.map +1 -0
- package/dist/catalog/PresentationLease.js +33 -0
- package/dist/catalog/PresentationLease.js.map +1 -0
- package/dist/catalog/SpatialGeometryCapture.d.ts +63 -0
- package/dist/catalog/SpatialGeometryCapture.d.ts.map +1 -0
- package/dist/catalog/SpatialGeometryCapture.js +158 -0
- package/dist/catalog/SpatialGeometryCapture.js.map +1 -0
- package/dist/catalog/assets/SpatialElementAssetManager.d.ts +92 -0
- package/dist/catalog/assets/SpatialElementAssetManager.d.ts.map +1 -0
- package/dist/catalog/assets/SpatialElementAssetManager.js +305 -0
- package/dist/catalog/assets/SpatialElementAssetManager.js.map +1 -0
- package/dist/catalog/assets/assetCosts.d.ts +4 -0
- package/dist/catalog/assets/assetCosts.d.ts.map +1 -0
- package/dist/catalog/assets/assetCosts.js +33 -0
- package/dist/catalog/assets/assetCosts.js.map +1 -0
- package/dist/catalog/assets/spatialElementAssetResources.d.ts +25 -0
- package/dist/catalog/assets/spatialElementAssetResources.d.ts.map +1 -0
- package/dist/catalog/assets/spatialElementAssetResources.js +100 -0
- package/dist/catalog/assets/spatialElementAssetResources.js.map +1 -0
- package/dist/catalog/carouselPanelProjection.d.ts +9 -0
- package/dist/catalog/carouselPanelProjection.d.ts.map +1 -0
- package/dist/catalog/carouselPanelProjection.js +33 -0
- package/dist/catalog/carouselPanelProjection.js.map +1 -0
- package/dist/catalog/carouselSelection.d.ts +7 -0
- package/dist/catalog/carouselSelection.d.ts.map +1 -0
- package/dist/catalog/carouselSelection.js +15 -0
- package/dist/catalog/carouselSelection.js.map +1 -0
- package/dist/catalog/catalogAction.d.ts +4 -0
- package/dist/catalog/catalogAction.d.ts.map +1 -0
- package/dist/catalog/catalogAction.js +9 -0
- package/dist/catalog/catalogAction.js.map +1 -0
- package/dist/catalog/catalogGeometryRequest.d.ts +13 -0
- package/dist/catalog/catalogGeometryRequest.d.ts.map +1 -0
- package/dist/catalog/catalogGeometryRequest.js +8 -0
- package/dist/catalog/catalogGeometryRequest.js.map +1 -0
- package/dist/catalog/catalogItems.d.ts +10 -0
- package/dist/catalog/catalogItems.d.ts.map +1 -0
- package/dist/catalog/catalogItems.js +23 -0
- package/dist/catalog/catalogItems.js.map +1 -0
- package/dist/catalog/catalogJourney.d.ts +38 -0
- package/dist/catalog/catalogJourney.d.ts.map +1 -0
- package/dist/catalog/catalogJourney.js +64 -0
- package/dist/catalog/catalogJourney.js.map +1 -0
- package/dist/catalog/catalogPage.d.ts +11 -0
- package/dist/catalog/catalogPage.d.ts.map +1 -0
- package/dist/catalog/catalogPage.js +2 -0
- package/dist/catalog/catalogPage.js.map +1 -0
- package/dist/catalog/catalogPose.d.ts +30 -0
- package/dist/catalog/catalogPose.d.ts.map +1 -0
- package/dist/catalog/catalogPose.js +35 -0
- package/dist/catalog/catalogPose.js.map +1 -0
- package/dist/catalog/catalogPresentation.d.ts +24 -0
- package/dist/catalog/catalogPresentation.d.ts.map +1 -0
- package/dist/catalog/catalogPresentation.js +56 -0
- package/dist/catalog/catalogPresentation.js.map +1 -0
- package/dist/catalog/catalogRecipes.d.ts +21 -0
- package/dist/catalog/catalogRecipes.d.ts.map +1 -0
- package/dist/catalog/catalogRecipes.js +84 -0
- package/dist/catalog/catalogRecipes.js.map +1 -0
- package/dist/catalog/catalogSurfaceCapture.d.ts +11 -0
- package/dist/catalog/catalogSurfaceCapture.d.ts.map +1 -0
- package/dist/catalog/catalogSurfaceCapture.js +11 -0
- package/dist/catalog/catalogSurfaceCapture.js.map +1 -0
- package/dist/catalog/catalogViewLink.d.ts +8 -0
- package/dist/catalog/catalogViewLink.d.ts.map +1 -0
- package/dist/catalog/catalogViewLink.js +37 -0
- package/dist/catalog/catalogViewLink.js.map +1 -0
- package/dist/catalog/rebasePresentation.d.ts +3 -0
- package/dist/catalog/rebasePresentation.d.ts.map +1 -0
- package/dist/catalog/rebasePresentation.js +26 -0
- package/dist/catalog/rebasePresentation.js.map +1 -0
- package/dist/catalog/spatialElementAssets.d.ts +158 -0
- package/dist/catalog/spatialElementAssets.d.ts.map +1 -0
- package/dist/catalog/spatialElementAssets.js +92 -0
- package/dist/catalog/spatialElementAssets.js.map +1 -0
- package/dist/catalog/spatialElementLodPair.d.ts +17 -0
- package/dist/catalog/spatialElementLodPair.d.ts.map +1 -0
- package/dist/catalog/spatialElementLodPair.js +5 -0
- package/dist/catalog/spatialElementLodPair.js.map +1 -0
- package/dist/catalog/transitionTiming.d.ts +15 -0
- package/dist/catalog/transitionTiming.d.ts.map +1 -0
- package/dist/catalog/transitionTiming.js +22 -0
- package/dist/catalog/transitionTiming.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/spatial-element/SpatialElementDockController.d.ts +101 -0
- package/dist/spatial-element/SpatialElementDockController.d.ts.map +1 -0
- package/dist/spatial-element/SpatialElementDockController.js +627 -0
- package/dist/spatial-element/SpatialElementDockController.js.map +1 -0
- package/dist/spatial-element/spatialElement.d.ts +28 -0
- package/dist/spatial-element/spatialElement.d.ts.map +1 -0
- package/dist/spatial-element/spatialElement.js +45 -0
- package/dist/spatial-element/spatialElement.js.map +1 -0
- package/dist/spatial-element/spatialElementDock.d.ts +43 -0
- package/dist/spatial-element/spatialElementDock.d.ts.map +1 -0
- package/dist/spatial-element/spatialElementDock.js +126 -0
- package/dist/spatial-element/spatialElementDock.js.map +1 -0
- package/dist/spatial-element/spatialElementSectionRegistry.d.ts +29 -0
- package/dist/spatial-element/spatialElementSectionRegistry.d.ts.map +1 -0
- package/dist/spatial-element/spatialElementSectionRegistry.js +67 -0
- package/dist/spatial-element/spatialElementSectionRegistry.js.map +1 -0
- package/dist/spatial-element/types.d.ts +165 -0
- package/dist/spatial-element/types.d.ts.map +1 -0
- package/dist/spatial-element/types.js +2 -0
- package/dist/spatial-element/types.js.map +1 -0
- package/dist/stage/LiquidGlassPanel.d.ts +55 -0
- package/dist/stage/LiquidGlassPanel.d.ts.map +1 -0
- package/dist/stage/LiquidGlassPanel.js +447 -0
- package/dist/stage/LiquidGlassPanel.js.map +1 -0
- package/dist/stage/MinimapBlurPipeline.d.ts +34 -0
- package/dist/stage/MinimapBlurPipeline.d.ts.map +1 -0
- package/dist/stage/MinimapBlurPipeline.js +147 -0
- package/dist/stage/MinimapBlurPipeline.js.map +1 -0
- package/dist/stage/MinimapController.d.ts +113 -0
- package/dist/stage/MinimapController.d.ts.map +1 -0
- package/dist/stage/MinimapController.js +803 -0
- package/dist/stage/MinimapController.js.map +1 -0
- package/dist/stage/OrbitControlsInterop.d.ts +8 -0
- package/dist/stage/OrbitControlsInterop.d.ts.map +1 -0
- package/dist/stage/OrbitControlsInterop.js +19 -0
- package/dist/stage/OrbitControlsInterop.js.map +1 -0
- package/dist/stage/PageBindingController.d.ts +41 -0
- package/dist/stage/PageBindingController.d.ts.map +1 -0
- package/dist/stage/PageBindingController.js +92 -0
- package/dist/stage/PageBindingController.js.map +1 -0
- package/dist/stage/PanelPresentationController.d.ts +92 -0
- package/dist/stage/PanelPresentationController.d.ts.map +1 -0
- package/dist/stage/PanelPresentationController.js +569 -0
- package/dist/stage/PanelPresentationController.js.map +1 -0
- package/dist/stage/PresentationReadiness.d.ts +30 -0
- package/dist/stage/PresentationReadiness.d.ts.map +1 -0
- package/dist/stage/PresentationReadiness.js +94 -0
- package/dist/stage/PresentationReadiness.js.map +1 -0
- package/dist/stage/SpaceMouseAdapter.d.ts +76 -0
- package/dist/stage/SpaceMouseAdapter.d.ts.map +1 -0
- package/dist/stage/SpaceMouseAdapter.js +197 -0
- package/dist/stage/SpaceMouseAdapter.js.map +1 -0
- package/dist/stage/SpatialElementInteractionController.d.ts +126 -0
- package/dist/stage/SpatialElementInteractionController.d.ts.map +1 -0
- package/dist/stage/SpatialElementInteractionController.js +581 -0
- package/dist/stage/SpatialElementInteractionController.js.map +1 -0
- package/dist/stage/SpatialElementPresentationController.d.ts +82 -0
- package/dist/stage/SpatialElementPresentationController.d.ts.map +1 -0
- package/dist/stage/SpatialElementPresentationController.js +372 -0
- package/dist/stage/SpatialElementPresentationController.js.map +1 -0
- package/dist/stage/SpatialElementRefinement.d.ts +26 -0
- package/dist/stage/SpatialElementRefinement.d.ts.map +1 -0
- package/dist/stage/SpatialElementRefinement.js +105 -0
- package/dist/stage/SpatialElementRefinement.js.map +1 -0
- package/dist/stage/StageExperience.d.ts +536 -0
- package/dist/stage/StageExperience.d.ts.map +1 -0
- package/dist/stage/StageExperience.js +2399 -0
- package/dist/stage/StageExperience.js.map +1 -0
- package/dist/stage/StagePanelLayout.d.ts +15 -0
- package/dist/stage/StagePanelLayout.d.ts.map +1 -0
- package/dist/stage/StagePanelLayout.js +20 -0
- package/dist/stage/StagePanelLayout.js.map +1 -0
- package/dist/stage/StagePanelRuntime.d.ts +20 -0
- package/dist/stage/StagePanelRuntime.d.ts.map +1 -0
- package/dist/stage/StagePanelRuntime.js +2 -0
- package/dist/stage/StagePanelRuntime.js.map +1 -0
- package/dist/stage/StageRenderPipeline.d.ts +179 -0
- package/dist/stage/StageRenderPipeline.d.ts.map +1 -0
- package/dist/stage/StageRenderPipeline.js +901 -0
- package/dist/stage/StageRenderPipeline.js.map +1 -0
- package/dist/stage/VirtualScrollController.d.ts +64 -0
- package/dist/stage/VirtualScrollController.d.ts.map +1 -0
- package/dist/stage/VirtualScrollController.js +329 -0
- package/dist/stage/VirtualScrollController.js.map +1 -0
- package/dist/stage/cssProjection.d.ts +18 -0
- package/dist/stage/cssProjection.d.ts.map +1 -0
- package/dist/stage/cssProjection.js +52 -0
- package/dist/stage/cssProjection.js.map +1 -0
- package/dist/stage/damping.d.ts +3 -0
- package/dist/stage/damping.d.ts.map +1 -0
- package/dist/stage/damping.js +8 -0
- package/dist/stage/damping.js.map +1 -0
- package/dist/stage/minimap/MinimapGeometry.d.ts +31 -0
- package/dist/stage/minimap/MinimapGeometry.d.ts.map +1 -0
- package/dist/stage/minimap/MinimapGeometry.js +163 -0
- package/dist/stage/minimap/MinimapGeometry.js.map +1 -0
- package/dist/stage/minimap/MinimapModel.d.ts +16 -0
- package/dist/stage/minimap/MinimapModel.d.ts.map +1 -0
- package/dist/stage/minimap/MinimapModel.js +51 -0
- package/dist/stage/minimap/MinimapModel.js.map +1 -0
- package/dist/stage/minimap/MinimapProjection.d.ts +41 -0
- package/dist/stage/minimap/MinimapProjection.d.ts.map +1 -0
- package/dist/stage/minimap/MinimapProjection.js +113 -0
- package/dist/stage/minimap/MinimapProjection.js.map +1 -0
- package/dist/stage/minimap/MinimapState.d.ts +102 -0
- package/dist/stage/minimap/MinimapState.d.ts.map +1 -0
- package/dist/stage/minimap/MinimapState.js +2 -0
- package/dist/stage/minimap/MinimapState.js.map +1 -0
- package/dist/stage/minimapMeasurement.d.ts +5 -0
- package/dist/stage/minimapMeasurement.d.ts.map +1 -0
- package/dist/stage/minimapMeasurement.js +11 -0
- package/dist/stage/minimapMeasurement.js.map +1 -0
- package/dist/stage/panelContext.d.ts +71 -0
- package/dist/stage/panelContext.d.ts.map +1 -0
- package/dist/stage/panelContext.js +6 -0
- package/dist/stage/panelContext.js.map +1 -0
- package/dist/stage/panelShadow.d.ts +20 -0
- package/dist/stage/panelShadow.d.ts.map +1 -0
- package/dist/stage/panelShadow.js +22 -0
- package/dist/stage/panelShadow.js.map +1 -0
- package/dist/stage/renderMeasurement.d.ts +3 -0
- package/dist/stage/renderMeasurement.d.ts.map +1 -0
- package/dist/stage/renderMeasurement.js +19 -0
- package/dist/stage/renderMeasurement.js.map +1 -0
- package/dist/stage/renderTargetInventory.d.ts +17 -0
- package/dist/stage/renderTargetInventory.d.ts.map +1 -0
- package/dist/stage/renderTargetInventory.js +27 -0
- package/dist/stage/renderTargetInventory.js.map +1 -0
- package/dist/stage/rendererState.d.ts +14 -0
- package/dist/stage/rendererState.d.ts.map +1 -0
- package/dist/stage/rendererState.js +35 -0
- package/dist/stage/rendererState.js.map +1 -0
- package/dist/stage/resolveStageProfile.d.ts +44 -0
- package/dist/stage/resolveStageProfile.d.ts.map +1 -0
- package/dist/stage/resolveStageProfile.js +30 -0
- package/dist/stage/resolveStageProfile.js.map +1 -0
- package/dist/stage/scrollAnimation.d.ts +10 -0
- package/dist/stage/scrollAnimation.d.ts.map +1 -0
- package/dist/stage/scrollAnimation.js +11 -0
- package/dist/stage/scrollAnimation.js.map +1 -0
- package/dist/stage/scrollFrame.d.ts +43 -0
- package/dist/stage/scrollFrame.d.ts.map +1 -0
- package/dist/stage/scrollFrame.js +232 -0
- package/dist/stage/scrollFrame.js.map +1 -0
- package/dist/stage/spatialElementFrame.d.ts +6 -0
- package/dist/stage/spatialElementFrame.d.ts.map +1 -0
- package/dist/stage/spatialElementFrame.js +22 -0
- package/dist/stage/spatialElementFrame.js.map +1 -0
- package/dist/stage/stageConstants.d.ts +85 -0
- package/dist/stage/stageConstants.d.ts.map +1 -0
- package/dist/stage/stageConstants.js +85 -0
- package/dist/stage/stageConstants.js.map +1 -0
- package/dist/stage/stageDom.d.ts +10 -0
- package/dist/stage/stageDom.d.ts.map +1 -0
- package/dist/stage/stageDom.js +22 -0
- package/dist/stage/stageDom.js.map +1 -0
- package/dist/stage/stageMath.d.ts +187 -0
- package/dist/stage/stageMath.d.ts.map +1 -0
- package/dist/stage/stageMath.js +344 -0
- package/dist/stage/stageMath.js.map +1 -0
- package/dist/stage/stageSceneUtils.d.ts +42 -0
- package/dist/stage/stageSceneUtils.d.ts.map +1 -0
- package/dist/stage/stageSceneUtils.js +154 -0
- package/dist/stage/stageSceneUtils.js.map +1 -0
- package/dist/stage/stageTypes.d.ts +189 -0
- package/dist/stage/stageTypes.d.ts.map +1 -0
- package/dist/stage/stageTypes.js +2 -0
- package/dist/stage/stageTypes.js.map +1 -0
- package/dist/stage/stageVisualTest.d.ts +92 -0
- package/dist/stage/stageVisualTest.d.ts.map +1 -0
- package/dist/stage/stageVisualTest.js +5 -0
- package/dist/stage/stageVisualTest.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,920 @@
|
|
|
1
|
+
import { CatalogGeometryFade } from './CatalogGeometryFade.js';
|
|
2
|
+
import { recordCarouselPanel } from './carouselPanelProjection.js';
|
|
3
|
+
import { prepareSpatialElementFrame } from '../stage/spatialElementFrame.js';
|
|
4
|
+
import { resolveSpatialElementLodPair } from './spatialElementLodPair.js';
|
|
5
|
+
import * as THREE from 'three/webgpu';
|
|
6
|
+
import { getStageVisualScrollPosition } from '../stage/scrollFrame.js';
|
|
7
|
+
import { getCameraOrbitQuaternion, getPanelPointerInfluence, getPanelPointerRotation, setPanelLocalPerspectiveMatrix } from '../stage/stageMath.js';
|
|
8
|
+
import { applyModelMaterialOverrides, centerAndScale, getMeshBounds, getMeshMaterials, isMesh } from '../stage/stageSceneUtils.js';
|
|
9
|
+
import { SpatialElementAssetManager } from './assets/SpatialElementAssetManager.js';
|
|
10
|
+
import { getSpatialElementEntityKey } from './spatialElementAssets.js';
|
|
11
|
+
import { applyCatalogMaterialOpacity, captureCatalogMaterialOpacity } from './catalogPresentation.js';
|
|
12
|
+
import { CATALOG_POSE_CHANGED } from './catalogPose.js';
|
|
13
|
+
import { getProjectiveCssMatrix3d } from '../stage/cssProjection.js';
|
|
14
|
+
import { CarouselGlassCompositor } from './CarouselGlassCompositor.js';
|
|
15
|
+
/** Removes irrelevant homogeneous scale so the reference point follows a continuous screen path. */
|
|
16
|
+
export function normalizeSpatialElementClipMatrix(matrix, point) {
|
|
17
|
+
const clip = new THREE.Vector4(point.x, point.y, point.z, 1).applyMatrix4(matrix);
|
|
18
|
+
if (clip.w > 0.000001)
|
|
19
|
+
matrix.multiplyScalar(1 / clip.w);
|
|
20
|
+
return matrix;
|
|
21
|
+
}
|
|
22
|
+
/** Factor camera-relative rotation out of clip space before interpolating framing.
|
|
23
|
+
* Interpolating complete MVP matrices collapses opposite rotations into a flat image.
|
|
24
|
+
* Residual matrices retain authored shear and exact endpoint projections.
|
|
25
|
+
*/
|
|
26
|
+
export function getSpatialElementHandoffProjection(sourceClip, targetClip, progress, modelWorld, cameraWorld, poses, target = new THREE.Matrix4()) {
|
|
27
|
+
const t = THREE.MathUtils.clamp(progress, 0, 1);
|
|
28
|
+
const rotation = (model, camera) => {
|
|
29
|
+
const q = new THREE.Quaternion();
|
|
30
|
+
camera.clone().invert().multiply(model).decompose(new THREE.Vector3(), q, new THREE.Vector3());
|
|
31
|
+
return q.normalize();
|
|
32
|
+
};
|
|
33
|
+
const from = rotation(poses.sourceModel, poses.sourceCamera);
|
|
34
|
+
const to = rotation(poses.targetModel, poses.targetCamera);
|
|
35
|
+
const a = sourceClip
|
|
36
|
+
.clone()
|
|
37
|
+
.multiply(new THREE.Matrix4().makeRotationFromQuaternion(from.clone().invert()));
|
|
38
|
+
const b = targetClip
|
|
39
|
+
.clone()
|
|
40
|
+
.multiply(new THREE.Matrix4().makeRotationFromQuaternion(to.clone().invert()));
|
|
41
|
+
for (let i = 0; i < 16; i++)
|
|
42
|
+
target.elements[i] = THREE.MathUtils.lerp(a.elements[i], b.elements[i], t);
|
|
43
|
+
target.multiply(new THREE.Matrix4().makeRotationFromQuaternion(from.slerp(to, t)));
|
|
44
|
+
// Keep the framing anchor on its screen path even for an off-centre asset pivot.
|
|
45
|
+
const point = poses.reference ?? new THREE.Vector3();
|
|
46
|
+
const project = (matrix) => new THREE.Vector4(point.x, point.y, point.z, 1).applyMatrix4(matrix);
|
|
47
|
+
const start = project(sourceClip), end = project(targetClip), current = project(target);
|
|
48
|
+
const dx = THREE.MathUtils.lerp(start.x / start.w, end.x / end.w, t) - current.x / current.w;
|
|
49
|
+
const dy = THREE.MathUtils.lerp(start.y / start.w, end.y / end.w, t) - current.y / current.w;
|
|
50
|
+
target.premultiply(new THREE.Matrix4().makeTranslation(dx, dy, 0));
|
|
51
|
+
return target.multiply(modelWorld.clone().invert()).multiply(cameraWorld);
|
|
52
|
+
}
|
|
53
|
+
/** Lightweight catalog geometry sharing the stage's renderer and foreground canvas. */
|
|
54
|
+
export class CatalogSpatialElementLayer {
|
|
55
|
+
assets;
|
|
56
|
+
invalidate;
|
|
57
|
+
getRenderTargets() {
|
|
58
|
+
return [
|
|
59
|
+
...this.glass.getRenderTargets(),
|
|
60
|
+
...this.geometryFade.getRenderTargets(),
|
|
61
|
+
...(this.handoff?.blend?.getRenderTargets() ?? [])
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
scene = new THREE.Scene();
|
|
65
|
+
passes = 0;
|
|
66
|
+
getStats() {
|
|
67
|
+
return {
|
|
68
|
+
instances: this.actors.size,
|
|
69
|
+
detachedInstances: this.detachedInstances,
|
|
70
|
+
visible: [...this.actors.values()].filter((actor) => actor.root.visible).length,
|
|
71
|
+
passes: this.passes,
|
|
72
|
+
glass: this.glass.getStats(),
|
|
73
|
+
actors: [...this.actors.values()].map((actor) => ({
|
|
74
|
+
spatialElementId: actor.spatialElementId,
|
|
75
|
+
band: actor.band,
|
|
76
|
+
clip: actor.clip ? { ...actor.clip } : undefined,
|
|
77
|
+
opacity: this.exitOpacity * (actor.materials[0]?.material.opacity ?? 0),
|
|
78
|
+
materialOpacity: actor.materials[0]?.material.opacity ?? 0,
|
|
79
|
+
depthWrite: actor.materials[0]?.material.depthWrite
|
|
80
|
+
}))
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
glass = new CarouselGlassCompositor();
|
|
84
|
+
geometryFade = new CatalogGeometryFade();
|
|
85
|
+
handoffScene = new THREE.Scene();
|
|
86
|
+
camera = new THREE.PerspectiveCamera(45, 1, 1, 4000);
|
|
87
|
+
// The carousel sits ~2500 units from the lens. A near plane of 1 wastes depth
|
|
88
|
+
// precision and makes closely spaced CAD surfaces fight after the longer-lens change.
|
|
89
|
+
carouselCamera = new THREE.PerspectiveCamera(45, 1, 250, 6000);
|
|
90
|
+
carouselFog = new THREE.Fog(0xffffff, 2700, 4000);
|
|
91
|
+
handoffCamera = new THREE.PerspectiveCamera();
|
|
92
|
+
actors = new Map();
|
|
93
|
+
requests = new Set();
|
|
94
|
+
desired = new Set();
|
|
95
|
+
spatialElements = new Map();
|
|
96
|
+
loadingKeys = new Set();
|
|
97
|
+
failedKeys = new Set();
|
|
98
|
+
motion = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
99
|
+
pointer = { x: 0, y: 0, active: false };
|
|
100
|
+
handoff;
|
|
101
|
+
handoffPoint;
|
|
102
|
+
generation = 0;
|
|
103
|
+
disposed = false;
|
|
104
|
+
layoutDirty = true;
|
|
105
|
+
layoutObserver = new ResizeObserver(() => this.resize());
|
|
106
|
+
queueDirty = true;
|
|
107
|
+
lastScrollX = Number.NaN;
|
|
108
|
+
lastScrollY = Number.NaN;
|
|
109
|
+
lastTime = 0;
|
|
110
|
+
exitOpacity = 1;
|
|
111
|
+
transitionActive = false;
|
|
112
|
+
destinationSpatialElement;
|
|
113
|
+
destinationOccurrences = new Set();
|
|
114
|
+
detachedInstances = 0;
|
|
115
|
+
pointerMove = (event) => {
|
|
116
|
+
if (event.pointerType !== 'mouse' && event.pointerType !== 'pen')
|
|
117
|
+
return;
|
|
118
|
+
this.pointer.x = event.clientX;
|
|
119
|
+
this.pointer.y = event.clientY;
|
|
120
|
+
this.pointer.active = true;
|
|
121
|
+
this.invalidate();
|
|
122
|
+
};
|
|
123
|
+
pointerLeave = () => {
|
|
124
|
+
this.pointer.active = false;
|
|
125
|
+
this.invalidate();
|
|
126
|
+
};
|
|
127
|
+
resize = () => {
|
|
128
|
+
this.layoutDirty = true;
|
|
129
|
+
this.queueDirty = true;
|
|
130
|
+
this.invalidate();
|
|
131
|
+
};
|
|
132
|
+
motionChange = () => this.invalidate();
|
|
133
|
+
setPageBackground(value) {
|
|
134
|
+
this.scene.fog.color.set(value);
|
|
135
|
+
this.carouselFog.color.set(value);
|
|
136
|
+
this.invalidate();
|
|
137
|
+
}
|
|
138
|
+
constructor(assets, invalidate) {
|
|
139
|
+
this.assets = assets;
|
|
140
|
+
this.invalidate = invalidate;
|
|
141
|
+
this.scene.environmentIntensity = 0.5;
|
|
142
|
+
this.scene.fog = new THREE.Fog(0xffffff, 1200, 2500);
|
|
143
|
+
this.handoffScene.fog = this.scene.fog;
|
|
144
|
+
this.handoffScene.environmentIntensity = 0.5;
|
|
145
|
+
this.carouselCamera.position.z = 2500;
|
|
146
|
+
this.carouselCamera.updateMatrixWorld();
|
|
147
|
+
this.camera.position.z = 1000;
|
|
148
|
+
this.camera.updateMatrixWorld();
|
|
149
|
+
window.addEventListener('pointermove', this.pointerMove, { passive: true });
|
|
150
|
+
window.addEventListener('pointerleave', this.pointerLeave);
|
|
151
|
+
window.addEventListener('blur', this.pointerLeave);
|
|
152
|
+
window.addEventListener('resize', this.resize);
|
|
153
|
+
this.motion.addEventListener('change', this.motionChange);
|
|
154
|
+
window.addEventListener(CATALOG_POSE_CHANGED, this.motionChange);
|
|
155
|
+
}
|
|
156
|
+
async setSpatialElements(brandId, spatialElements) {
|
|
157
|
+
if (this.disposed)
|
|
158
|
+
return;
|
|
159
|
+
const generation = ++this.generation;
|
|
160
|
+
this.layoutObserver.disconnect();
|
|
161
|
+
const page = document.querySelector('[data-catalog-list]');
|
|
162
|
+
if (page) {
|
|
163
|
+
this.layoutObserver.observe(page);
|
|
164
|
+
for (const section of page.querySelectorAll('section'))
|
|
165
|
+
this.layoutObserver.observe(section);
|
|
166
|
+
}
|
|
167
|
+
for (const request of this.requests)
|
|
168
|
+
request.abort();
|
|
169
|
+
this.requests.clear();
|
|
170
|
+
this.loadingKeys.clear();
|
|
171
|
+
this.failedKeys.clear();
|
|
172
|
+
this.desired.clear();
|
|
173
|
+
this.spatialElements.clear();
|
|
174
|
+
for (const spatialElement of spatialElements) {
|
|
175
|
+
if (!spatialElement.stage)
|
|
176
|
+
continue;
|
|
177
|
+
const key = JSON.stringify([
|
|
178
|
+
getSpatialElementEntityKey(brandId, spatialElement.id),
|
|
179
|
+
spatialElement.occurrence ?? null
|
|
180
|
+
]);
|
|
181
|
+
this.desired.add(key);
|
|
182
|
+
this.spatialElements.set(key, { brandId, spatialElement });
|
|
183
|
+
}
|
|
184
|
+
for (const actor of this.actors.values()) {
|
|
185
|
+
actor.pose = this.spatialElements.get(actor.key)?.spatialElement.pose ?? actor.pose;
|
|
186
|
+
if (this.handoff && actor.rendered)
|
|
187
|
+
continue;
|
|
188
|
+
if (this.handoff?.actor !== actor &&
|
|
189
|
+
(!this.desired.has(actor.key) ||
|
|
190
|
+
JSON.stringify(actor.stage) !==
|
|
191
|
+
JSON.stringify(this.spatialElements.get(actor.key)?.spatialElement.stage)))
|
|
192
|
+
this.disposeActor(actor);
|
|
193
|
+
}
|
|
194
|
+
this.layoutDirty = true;
|
|
195
|
+
this.queueDirty = false;
|
|
196
|
+
await this.loadVisibleSpatialElements(generation);
|
|
197
|
+
this.invalidate();
|
|
198
|
+
}
|
|
199
|
+
async loadVisibleSpatialElements(generation) {
|
|
200
|
+
if (this.disposed || generation !== this.generation)
|
|
201
|
+
return;
|
|
202
|
+
const remaining = Math.min(2 - this.requests.size, 16 - this.actors.size - this.detachedInstances - this.requests.size);
|
|
203
|
+
if (remaining <= 0)
|
|
204
|
+
return;
|
|
205
|
+
const candidates = [...this.spatialElements.entries()]
|
|
206
|
+
.filter(([key, { brandId, spatialElement }]) => {
|
|
207
|
+
if (this.actors.has(key) || this.loadingKeys.has(key) || this.failedKeys.has(key))
|
|
208
|
+
return false;
|
|
209
|
+
const list = document.querySelector(`[data-catalog-list][data-brand-id="${CSS.escape(brandId)}"]`);
|
|
210
|
+
const slot = list?.querySelector(`[data-catalog-geometry][data-spatial-element-id="${CSS.escape(spatialElement.id)}"]${spatialElement.occurrence ? `[data-catalog-occurrence="${CSS.escape(spatialElement.occurrence)}"]` : ''}`);
|
|
211
|
+
const rect = slot?.getBoundingClientRect();
|
|
212
|
+
return (rect &&
|
|
213
|
+
rect.top < window.innerHeight + 300 &&
|
|
214
|
+
rect.bottom > -300 &&
|
|
215
|
+
rect.left < window.innerWidth &&
|
|
216
|
+
rect.right > 0);
|
|
217
|
+
})
|
|
218
|
+
.slice(0, remaining);
|
|
219
|
+
if (!candidates.length)
|
|
220
|
+
return;
|
|
221
|
+
await Promise.all(candidates.map(async ([key, { brandId, spatialElement }]) => {
|
|
222
|
+
if (!spatialElement.stage)
|
|
223
|
+
return;
|
|
224
|
+
const request = new AbortController();
|
|
225
|
+
this.requests.add(request);
|
|
226
|
+
this.loadingKeys.add(key);
|
|
227
|
+
const lease = this.assets.acquire(resolveSpatialElementLodPair(spatialElement.stage.glb, spatialElement.stage.lodPair)?.low ?? {
|
|
228
|
+
url: spatialElement.stage.glb,
|
|
229
|
+
format: 'glb',
|
|
230
|
+
revision: 'legacy-unversioned',
|
|
231
|
+
requirements: { decoders: ['draco'], extensions: [] }
|
|
232
|
+
}, { signal: request.signal });
|
|
233
|
+
let instance;
|
|
234
|
+
try {
|
|
235
|
+
instance = await lease.createInstance();
|
|
236
|
+
if (this.disposed || generation !== this.generation) {
|
|
237
|
+
instance.dispose();
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const actor = this.createActor(key, brandId, spatialElement.id, spatialElement.stage, instance);
|
|
241
|
+
actor.occurrence = spatialElement.occurrence;
|
|
242
|
+
actor.pose = spatialElement.pose;
|
|
243
|
+
this.actors.set(key, actor);
|
|
244
|
+
this.scene.add(actor.root);
|
|
245
|
+
this.layoutDirty = true;
|
|
246
|
+
this.invalidate();
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
instance?.dispose();
|
|
250
|
+
if (!(error instanceof DOMException && error.name === 'AbortError')) {
|
|
251
|
+
if (generation === this.generation)
|
|
252
|
+
this.failedKeys.add(key);
|
|
253
|
+
console.warn(`Catalog preview unavailable for ${spatialElement.id}`, error);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
finally {
|
|
257
|
+
lease.release();
|
|
258
|
+
this.requests.delete(request);
|
|
259
|
+
if (generation === this.generation)
|
|
260
|
+
this.loadingKeys.delete(key);
|
|
261
|
+
}
|
|
262
|
+
}));
|
|
263
|
+
await this.loadVisibleSpatialElements(generation);
|
|
264
|
+
}
|
|
265
|
+
update(renderer, environment, now) {
|
|
266
|
+
if (this.disposed)
|
|
267
|
+
return false;
|
|
268
|
+
const width = Math.max(window.innerWidth, 1);
|
|
269
|
+
const height = Math.max(window.innerHeight, 1);
|
|
270
|
+
this.camera.coordinateSystem = renderer.coordinateSystem;
|
|
271
|
+
this.camera.aspect = width / height;
|
|
272
|
+
this.camera.fov = THREE.MathUtils.radToDeg(2 * Math.atan(height / 2000));
|
|
273
|
+
this.camera.updateProjectionMatrix();
|
|
274
|
+
this.carouselCamera.coordinateSystem = renderer.coordinateSystem;
|
|
275
|
+
this.carouselCamera.aspect = width / height;
|
|
276
|
+
this.carouselCamera.fov = THREE.MathUtils.radToDeg(2 * Math.atan(height / 5000));
|
|
277
|
+
this.carouselCamera.updateProjectionMatrix();
|
|
278
|
+
this.scene.environment = environment;
|
|
279
|
+
this.handoffScene.environment = this.handoff?.sourceEnvironment ?? environment;
|
|
280
|
+
const scroll = getStageVisualScrollPosition();
|
|
281
|
+
if (scroll.scrollX !== this.lastScrollX || scroll.scrollY !== this.lastScrollY) {
|
|
282
|
+
this.lastScrollX = scroll.scrollX;
|
|
283
|
+
this.lastScrollY = scroll.scrollY;
|
|
284
|
+
this.queueDirty = true;
|
|
285
|
+
}
|
|
286
|
+
if (this.layoutDirty)
|
|
287
|
+
this.measureActors(scroll.scrollX, scroll.scrollY);
|
|
288
|
+
const delta = Math.min(this.lastTime ? (now - this.lastTime) / 1000 : 1 / 60, 0.05);
|
|
289
|
+
this.lastTime = now;
|
|
290
|
+
let animating = false;
|
|
291
|
+
this.glass.beginFrame();
|
|
292
|
+
for (const actor of this.actors.values()) {
|
|
293
|
+
if (this.handoff?.actor === actor)
|
|
294
|
+
continue;
|
|
295
|
+
if (this.handoff) {
|
|
296
|
+
// The outgoing DOM has been snapshotted. Keep these already-rendered
|
|
297
|
+
// spatialElements at their captured screen pose until the shared fade completes.
|
|
298
|
+
actor.root.visible = actor.rendered && actor.root.visible && this.exitOpacity > 0.001;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (!actor.card?.isConnected || !actor.slot?.isConnected) {
|
|
302
|
+
actor.root.visible = false;
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
const card = actor.cardRect;
|
|
306
|
+
const slot = actor.slotRect;
|
|
307
|
+
if (!card || !slot)
|
|
308
|
+
continue;
|
|
309
|
+
const dx = actor.scrollX - scroll.scrollX;
|
|
310
|
+
const dy = actor.scrollY - scroll.scrollY;
|
|
311
|
+
if (slot.top + dy > height + 700 || slot.top + dy + slot.height < -700) {
|
|
312
|
+
this.disposeActor(actor);
|
|
313
|
+
this.queueDirty = true;
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
actor.root.visible =
|
|
317
|
+
this.exitOpacity > 0.001 &&
|
|
318
|
+
slot.top + dy < height + 96 &&
|
|
319
|
+
slot.top + dy + slot.height > -96 &&
|
|
320
|
+
slot.left + dx < width &&
|
|
321
|
+
slot.left + dx + slot.width > 0;
|
|
322
|
+
if (!actor.root.visible)
|
|
323
|
+
continue;
|
|
324
|
+
if (actor.pose) {
|
|
325
|
+
const pose = actor.pose.read();
|
|
326
|
+
actor.band = pose.front ? 'front' : 'rear';
|
|
327
|
+
actor.root.visible &&= pose.visible;
|
|
328
|
+
applyCatalogMaterialOpacity(actor.materials, pose.opacity);
|
|
329
|
+
const compact = slot.width < 700;
|
|
330
|
+
// Anchor each coupled group at its spatialElement, so recession cannot pull neighbours together.
|
|
331
|
+
const x = slot.left + dx + slot.width * (pose.x - (compact ? 0 : 0.19));
|
|
332
|
+
const y = slot.top + dy + slot.height * pose.y;
|
|
333
|
+
const perspective = 1 - pose.depth / this.carouselCamera.position.z;
|
|
334
|
+
actor.root.matrix.makeTranslation((x - width / 2) * perspective, (height / 2 - y) * perspective, pose.depth);
|
|
335
|
+
actor.root.matrixWorldNeedsUpdate = true;
|
|
336
|
+
// One physical group transform for spatialElement, panel surface and DOM projection.
|
|
337
|
+
actor.tilt.scale.setScalar(perspective * (pose.size / 0.82));
|
|
338
|
+
actor.tilt.rotation.set(0, pose.yaw, 0);
|
|
339
|
+
actor.tilt.position.set(0, 0, 0);
|
|
340
|
+
actor.view.position.set(0, compact ? slot.height / 2 - 180 : 0, 0);
|
|
341
|
+
actor.view.scale.setScalar((Math.min(slot.width, compact ? 360 : slot.height) * 0.82) / (actor.radius * 2));
|
|
342
|
+
actor.root.updateMatrixWorld(true);
|
|
343
|
+
const hitTarget = actor.card.querySelector('.spatial-element-target');
|
|
344
|
+
if (hitTarget) {
|
|
345
|
+
// Project cached model bounds, not the framing sphere: empty foreground
|
|
346
|
+
// margins must not intercept clicks on visible neighbouring spatialElements.
|
|
347
|
+
let left = Infinity, top = Infinity, right = -Infinity, bottom = -Infinity;
|
|
348
|
+
const point = new THREE.Vector3();
|
|
349
|
+
for (const corner of actor.hitCorners) {
|
|
350
|
+
point.copy(corner).applyMatrix4(actor.view.matrixWorld).project(this.carouselCamera);
|
|
351
|
+
const px = ((point.x + 1) * width) / 2 - slot.left - dx;
|
|
352
|
+
const py = ((1 - point.y) * height) / 2 - slot.top - dy;
|
|
353
|
+
left = Math.min(left, px);
|
|
354
|
+
right = Math.max(right, px);
|
|
355
|
+
top = Math.min(top, py);
|
|
356
|
+
bottom = Math.max(bottom, py);
|
|
357
|
+
}
|
|
358
|
+
hitTarget.style.left = `${(left + right) / 2}px`;
|
|
359
|
+
hitTarget.style.top = `${(top + bottom) / 2}px`;
|
|
360
|
+
hitTarget.style.width = `${right - left}px`;
|
|
361
|
+
hitTarget.style.height = `${bottom - top}px`;
|
|
362
|
+
hitTarget.style.maxWidth = 'none';
|
|
363
|
+
}
|
|
364
|
+
const panel = actor.card.querySelector('.summary');
|
|
365
|
+
if (panel) {
|
|
366
|
+
const pw = panel.offsetWidth, ph = panel.offsetHeight;
|
|
367
|
+
const matrix = actor.tilt.matrixWorld
|
|
368
|
+
.clone()
|
|
369
|
+
.multiply(new THREE.Matrix4().makeTranslation(compact ? 0 : slot.width * 0.39, compact ? slot.height / 2 - 360 - ph / 2 : 0, 0));
|
|
370
|
+
const corners = [
|
|
371
|
+
[-pw / 2, ph / 2],
|
|
372
|
+
[pw / 2, ph / 2],
|
|
373
|
+
[pw / 2, -ph / 2],
|
|
374
|
+
[-pw / 2, -ph / 2]
|
|
375
|
+
].map(([x, y]) => {
|
|
376
|
+
const point = new THREE.Vector3(x, y, 0)
|
|
377
|
+
.applyMatrix4(matrix)
|
|
378
|
+
.project(this.carouselCamera);
|
|
379
|
+
return {
|
|
380
|
+
x: ((point.x + 1) * width) / 2 - slot.left - dx,
|
|
381
|
+
y: ((1 - point.y) * height) / 2 - slot.top - dy
|
|
382
|
+
};
|
|
383
|
+
});
|
|
384
|
+
panel.style.transform = getProjectiveCssMatrix3d(corners, pw, ph) ?? '';
|
|
385
|
+
recordCarouselPanel(panel, corners.map((point) => ({
|
|
386
|
+
x: point.x + slot.left + dx,
|
|
387
|
+
y: point.y + slot.top + dy
|
|
388
|
+
})), pw, ph);
|
|
389
|
+
const hidden = actor.card.style.visibility === 'hidden' || panel.style.visibility === 'hidden';
|
|
390
|
+
this.glass.panel(actor.card, matrix, pw, ph, hidden ? 0 : pose.panelOpacity * this.exitOpacity);
|
|
391
|
+
}
|
|
392
|
+
actor.clip = {
|
|
393
|
+
left: 0,
|
|
394
|
+
top: slot.top + dy,
|
|
395
|
+
width,
|
|
396
|
+
height: slot.height
|
|
397
|
+
};
|
|
398
|
+
if (this.isDestinationActor(actor))
|
|
399
|
+
actor.root.visible = false;
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
actor.tilt.scale.setScalar(1);
|
|
403
|
+
const centerX = card.left + dx + card.width / 2;
|
|
404
|
+
const centerY = card.top + dy + card.height / 2;
|
|
405
|
+
const px = this.pointer.x - centerX;
|
|
406
|
+
const py = this.pointer.y - centerY;
|
|
407
|
+
const distance = Math.hypot(Math.max(Math.abs(px) - card.width / 2, 0), Math.max(Math.abs(py) - card.height / 2, 0));
|
|
408
|
+
const influence = this.pointer.active && !this.motion.matches && !this.transitionActive
|
|
409
|
+
? getPanelPointerInfluence(distance, card.width, card.height)
|
|
410
|
+
: 0;
|
|
411
|
+
const rotation = getPanelPointerRotation(px / (card.width / 2), py / (card.height / 2), influence, card.width, card.height);
|
|
412
|
+
// CSS has a downward Y axis; use the same physical rotation as DETAIL panels.
|
|
413
|
+
const targets = [
|
|
414
|
+
-THREE.MathUtils.radToDeg(rotation.x),
|
|
415
|
+
THREE.MathUtils.radToDeg(rotation.y),
|
|
416
|
+
-influence * 8
|
|
417
|
+
];
|
|
418
|
+
const previous = [actor.rotationX, actor.rotationY, actor.lift];
|
|
419
|
+
const values = previous.map((value, index) => {
|
|
420
|
+
const next = this.motion.matches
|
|
421
|
+
? targets[index]
|
|
422
|
+
: THREE.MathUtils.damp(value, targets[index], 14, delta);
|
|
423
|
+
return Math.abs(next - targets[index]) < 0.01 ? targets[index] : next;
|
|
424
|
+
});
|
|
425
|
+
[actor.rotationX, actor.rotationY, actor.lift] = values;
|
|
426
|
+
animating ||= values.some((value, index) => value !== targets[index]);
|
|
427
|
+
actor.card.style.setProperty('--catalog-rotate-x', `${actor.rotationX}deg`);
|
|
428
|
+
actor.card.style.setProperty('--catalog-rotate-y', `${actor.rotationY}deg`);
|
|
429
|
+
actor.card.style.setProperty('--catalog-lift', `${actor.lift}px`);
|
|
430
|
+
setPanelLocalPerspectiveMatrix(actor.root.matrix, centerX - width / 2, height / 2 - centerY, 0, 1000);
|
|
431
|
+
actor.root.matrixWorldNeedsUpdate = true;
|
|
432
|
+
actor.tilt.rotation.set(-THREE.MathUtils.degToRad(actor.rotationX), THREE.MathUtils.degToRad(actor.rotationY), 0);
|
|
433
|
+
actor.tilt.position.y = -actor.lift;
|
|
434
|
+
actor.view.position.set(slot.left + slot.width / 2 - card.left - card.width / 2, card.top + card.height / 2 - slot.top - slot.height / 2, 0);
|
|
435
|
+
actor.view.scale.setScalar((Math.min(slot.width, slot.height) * 0.84) / (actor.radius * 2));
|
|
436
|
+
if (this.isDestinationActor(actor))
|
|
437
|
+
actor.root.visible = false;
|
|
438
|
+
}
|
|
439
|
+
if (this.queueDirty) {
|
|
440
|
+
this.queueDirty = false;
|
|
441
|
+
void this.loadVisibleSpatialElements(this.generation);
|
|
442
|
+
}
|
|
443
|
+
this.glass.endFrame();
|
|
444
|
+
return animating;
|
|
445
|
+
}
|
|
446
|
+
draw(renderer, band) {
|
|
447
|
+
this.passes++;
|
|
448
|
+
const width = window.innerWidth, height = window.innerHeight;
|
|
449
|
+
const all = [...this.actors.values()].filter((actor) => actor.root.visible && this.handoff?.actor !== actor);
|
|
450
|
+
for (const actor of all)
|
|
451
|
+
actor.root.visible = (actor.band ?? 'front') === band;
|
|
452
|
+
this.geometryFade.render(renderer, this.exitOpacity, () => {
|
|
453
|
+
renderer.clearDepth();
|
|
454
|
+
const shown = [...this.actors.values()].filter((actor) => actor.root.visible && this.handoff?.actor !== actor);
|
|
455
|
+
const clipped = shown.filter((actor) => actor.clip);
|
|
456
|
+
for (const actor of clipped)
|
|
457
|
+
actor.root.visible = false;
|
|
458
|
+
renderer.render(this.scene, this.camera);
|
|
459
|
+
if (clipped.length) {
|
|
460
|
+
const oldScissor = renderer.getScissor(new THREE.Vector4());
|
|
461
|
+
const oldTest = renderer.getScissorTest();
|
|
462
|
+
for (const actor of shown)
|
|
463
|
+
actor.root.visible = false;
|
|
464
|
+
// One submission per section viewport, with shared depth among its ring spatialElements.
|
|
465
|
+
const groups = new Map();
|
|
466
|
+
for (const actor of clipped) {
|
|
467
|
+
const key = JSON.stringify(actor.clip);
|
|
468
|
+
groups.set(key, [...(groups.get(key) ?? []), actor]);
|
|
469
|
+
}
|
|
470
|
+
for (const group of groups.values()) {
|
|
471
|
+
const rect = group[0].clip;
|
|
472
|
+
const left = Math.max(0, rect.left), top = Math.max(0, rect.top);
|
|
473
|
+
const right = Math.min(width, rect.left + rect.width), bottom = Math.min(height, rect.top + rect.height);
|
|
474
|
+
if (right <= left || bottom <= top)
|
|
475
|
+
continue;
|
|
476
|
+
renderer.setScissor(left, top, right - left, bottom - top);
|
|
477
|
+
renderer.setScissorTest(true);
|
|
478
|
+
for (const actor of group)
|
|
479
|
+
actor.root.visible = true;
|
|
480
|
+
const fog = this.scene.fog;
|
|
481
|
+
this.scene.fog = this.carouselFog;
|
|
482
|
+
try {
|
|
483
|
+
renderer.render(this.scene, this.carouselCamera);
|
|
484
|
+
}
|
|
485
|
+
finally {
|
|
486
|
+
this.scene.fog = fog;
|
|
487
|
+
}
|
|
488
|
+
for (const actor of group)
|
|
489
|
+
actor.root.visible = false;
|
|
490
|
+
}
|
|
491
|
+
renderer.setScissor(oldScissor);
|
|
492
|
+
renderer.setScissorTest(oldTest);
|
|
493
|
+
}
|
|
494
|
+
for (const actor of shown)
|
|
495
|
+
actor.root.visible = true;
|
|
496
|
+
for (const actor of this.actors.values()) {
|
|
497
|
+
if (actor.root.visible && this.handoff?.actor !== actor) {
|
|
498
|
+
actor.rendered = true;
|
|
499
|
+
actor.card?.setAttribute('data-catalog-model-ready', '');
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
for (const actor of all)
|
|
504
|
+
actor.root.visible = true;
|
|
505
|
+
if (band === 'front' && this.handoff)
|
|
506
|
+
this.renderHandoff(renderer);
|
|
507
|
+
}
|
|
508
|
+
/** Rear elements are the backdrop source, independent of DETAIL High/HDR ownership. */
|
|
509
|
+
hasCarousel() {
|
|
510
|
+
return [...this.actors.values()].some((actor) => Boolean(actor.pose));
|
|
511
|
+
}
|
|
512
|
+
renderRear(renderer) {
|
|
513
|
+
this.glass.render(renderer, this.carouselCamera, () => this.draw(renderer, 'rear'));
|
|
514
|
+
}
|
|
515
|
+
/** Warm the existing Low material passes in an offscreen preparation target. */
|
|
516
|
+
renderForPreparation(renderer) {
|
|
517
|
+
this.geometryFade.render(renderer, 0.5, () => renderer.render(this.scene, this.camera));
|
|
518
|
+
}
|
|
519
|
+
/** Applies only to outgoing list actors; the shared handoff geometry keeps its authored alpha. */
|
|
520
|
+
setExitOpacity(opacity, active = false) {
|
|
521
|
+
this.exitOpacity = Number.isFinite(opacity) ? Math.min(1, Math.max(0, opacity)) : 0;
|
|
522
|
+
this.transitionActive = active;
|
|
523
|
+
this.invalidate();
|
|
524
|
+
}
|
|
525
|
+
capture(spatialElementId, occurrence) {
|
|
526
|
+
const actor = [...this.actors.values()].find((item) => item.spatialElementId === spatialElementId &&
|
|
527
|
+
this.desired.has(item.key) &&
|
|
528
|
+
(occurrence
|
|
529
|
+
? item.occurrence === occurrence
|
|
530
|
+
: !item.occurrence || item.card?.hasAttribute('data-catalog-selected')));
|
|
531
|
+
if (!actor?.rendered || !actor.root.visible)
|
|
532
|
+
return false;
|
|
533
|
+
this.finishHandoff();
|
|
534
|
+
this.handoffPoint = undefined;
|
|
535
|
+
actor.model.updateWorldMatrix(true, true);
|
|
536
|
+
const camera = actor.pose ? this.carouselCamera : this.camera;
|
|
537
|
+
this.handoffScene.fog = actor.pose ? this.carouselFog : this.scene.fog;
|
|
538
|
+
camera.updateMatrixWorld();
|
|
539
|
+
const sourceModel = actor.model.matrixWorld.clone();
|
|
540
|
+
const sourceClip = normalizeSpatialElementClipMatrix(new THREE.Matrix4()
|
|
541
|
+
.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse)
|
|
542
|
+
.multiply(sourceModel), actor.referencePoint);
|
|
543
|
+
this.handoff = {
|
|
544
|
+
sourceEnvironmentIntensity: this.scene.environmentIntensity,
|
|
545
|
+
sourceEnvironment: this.scene.environment,
|
|
546
|
+
actor,
|
|
547
|
+
sourceClip,
|
|
548
|
+
sourceModel,
|
|
549
|
+
sourceCamera: camera.matrixWorld.clone()
|
|
550
|
+
};
|
|
551
|
+
applyCatalogMaterialOpacity(actor.materials, 1);
|
|
552
|
+
actor.root.removeFromParent();
|
|
553
|
+
this.handoffScene.add(actor.model);
|
|
554
|
+
actor.model.matrixAutoUpdate = false;
|
|
555
|
+
actor.model.matrix.copy(sourceModel);
|
|
556
|
+
this.invalidate();
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
/** Last submitted geometry position; diagnostics never advance animation or read DOM layout. */
|
|
560
|
+
setDestinationSpatialElement(spatialElementId) {
|
|
561
|
+
this.destinationSpatialElement = spatialElementId;
|
|
562
|
+
if (!spatialElementId)
|
|
563
|
+
this.destinationOccurrences.clear();
|
|
564
|
+
this.invalidate();
|
|
565
|
+
}
|
|
566
|
+
setDestinationOccurrences(endpoints) {
|
|
567
|
+
this.destinationOccurrences = new Set(endpoints.map((p) => JSON.stringify([p.spatialElementId, p.occurrence])));
|
|
568
|
+
this.invalidate();
|
|
569
|
+
}
|
|
570
|
+
isDestinationActor(actor) {
|
|
571
|
+
return (this.destinationOccurrences.has(JSON.stringify([actor.spatialElementId, actor.occurrence])) ||
|
|
572
|
+
(actor.spatialElementId === this.destinationSpatialElement &&
|
|
573
|
+
(!actor.occurrence || actor.card?.hasAttribute('data-catalog-selected'))));
|
|
574
|
+
}
|
|
575
|
+
getDestinationProjection(spatialElementId, occurrence) {
|
|
576
|
+
const actor = [...this.actors.values()].find((item) => item.spatialElementId === spatialElementId &&
|
|
577
|
+
(occurrence
|
|
578
|
+
? item.occurrence === occurrence
|
|
579
|
+
: !item.occurrence || item.card?.hasAttribute('data-catalog-selected')));
|
|
580
|
+
if (!actor?.slot?.isConnected)
|
|
581
|
+
return;
|
|
582
|
+
const rect = actor.slot.getBoundingClientRect();
|
|
583
|
+
if (rect.width <= 0 ||
|
|
584
|
+
rect.height <= 0 ||
|
|
585
|
+
(actor.pose
|
|
586
|
+
? rect.right <= 0 || rect.bottom <= 0 || rect.left >= innerWidth || rect.top >= innerHeight
|
|
587
|
+
: rect.left < 0 || rect.top < 0 || rect.right > innerWidth || rect.bottom > innerHeight))
|
|
588
|
+
return;
|
|
589
|
+
actor.model.updateWorldMatrix(true, true);
|
|
590
|
+
const camera = actor.pose ? this.carouselCamera : this.camera;
|
|
591
|
+
return {
|
|
592
|
+
environmentIntensity: this.scene.environmentIntensity,
|
|
593
|
+
fog: actor.pose ? this.carouselFog : this.scene.fog,
|
|
594
|
+
viewportClip: actor.clip ? { ...actor.clip } : undefined,
|
|
595
|
+
model: actor.model.matrixWorld.clone(),
|
|
596
|
+
camera: camera.matrixWorld.clone(),
|
|
597
|
+
clip: normalizeSpatialElementClipMatrix(new THREE.Matrix4()
|
|
598
|
+
.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse)
|
|
599
|
+
.multiply(actor.model.matrixWorld), new THREE.Vector3())
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
getHandoffPoint() {
|
|
603
|
+
return this.handoff && this.handoffPoint ? { ...this.handoffPoint } : null;
|
|
604
|
+
}
|
|
605
|
+
/** Detach the last submitted moving element without releasing the actor's Low instance. */
|
|
606
|
+
detachHandoff() {
|
|
607
|
+
const handoff = this.handoff;
|
|
608
|
+
if (!handoff)
|
|
609
|
+
return;
|
|
610
|
+
const actor = handoff.actor;
|
|
611
|
+
const model = actor.model;
|
|
612
|
+
model.updateWorldMatrix(true, true);
|
|
613
|
+
const camera = this.handoffPoint
|
|
614
|
+
? this.handoffCamera
|
|
615
|
+
: actor.pose
|
|
616
|
+
? this.carouselCamera
|
|
617
|
+
: this.camera;
|
|
618
|
+
camera.updateMatrixWorld();
|
|
619
|
+
const projection = {
|
|
620
|
+
fog: actor.pose ? this.carouselFog : this.scene.fog,
|
|
621
|
+
viewportClip: actor.clip ? { ...actor.clip } : undefined,
|
|
622
|
+
model: model.matrixWorld.clone(),
|
|
623
|
+
camera: camera.matrixWorld.clone(),
|
|
624
|
+
clip: normalizeSpatialElementClipMatrix(new THREE.Matrix4()
|
|
625
|
+
.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse)
|
|
626
|
+
.multiply(model.matrixWorld), new THREE.Vector3()),
|
|
627
|
+
environmentIntensity: this.handoffPoint
|
|
628
|
+
? this.handoffScene.environmentIntensity
|
|
629
|
+
: handoff.sourceEnvironmentIntensity
|
|
630
|
+
};
|
|
631
|
+
this.handoff = undefined;
|
|
632
|
+
if (this.actors.get(actor.key) === actor)
|
|
633
|
+
this.actors.delete(actor.key);
|
|
634
|
+
this.detachedInstances++;
|
|
635
|
+
let released = false;
|
|
636
|
+
return {
|
|
637
|
+
model,
|
|
638
|
+
projection,
|
|
639
|
+
referencePoint: actor.referencePoint.clone(),
|
|
640
|
+
environment: handoff.sourceEnvironment,
|
|
641
|
+
highEnvironment: handoff.highEnvironment,
|
|
642
|
+
release: () => {
|
|
643
|
+
if (!released) {
|
|
644
|
+
released = true;
|
|
645
|
+
this.detachedInstances--;
|
|
646
|
+
this.disposeActor(actor);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
setHandoffTarget(target) {
|
|
652
|
+
if (!this.handoff)
|
|
653
|
+
return;
|
|
654
|
+
this.handoff.target = target;
|
|
655
|
+
this.invalidate();
|
|
656
|
+
}
|
|
657
|
+
setHighHandoff(high, blend, progress, environment) {
|
|
658
|
+
if (this.handoff)
|
|
659
|
+
Object.assign(this.handoff, {
|
|
660
|
+
high,
|
|
661
|
+
blend,
|
|
662
|
+
blendProgress: progress,
|
|
663
|
+
highEnvironment: environment
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
finishHandoff() {
|
|
667
|
+
const handoff = this.handoff;
|
|
668
|
+
if (!handoff)
|
|
669
|
+
return;
|
|
670
|
+
this.handoff = undefined;
|
|
671
|
+
const actor = handoff.actor;
|
|
672
|
+
applyCatalogMaterialOpacity(actor.materials, 1);
|
|
673
|
+
if (this.desired.has(actor.key)) {
|
|
674
|
+
applyCatalogMaterialOpacity(actor.materials, 1);
|
|
675
|
+
actor.model.matrixAutoUpdate = true;
|
|
676
|
+
actor.model.updateMatrix();
|
|
677
|
+
actor.view.add(actor.model);
|
|
678
|
+
this.scene.add(actor.root);
|
|
679
|
+
this.layoutDirty = true;
|
|
680
|
+
}
|
|
681
|
+
else
|
|
682
|
+
this.disposeActor(actor);
|
|
683
|
+
for (const other of this.actors.values()) {
|
|
684
|
+
if (!this.desired.has(other.key))
|
|
685
|
+
this.disposeActor(other);
|
|
686
|
+
}
|
|
687
|
+
this.invalidate();
|
|
688
|
+
}
|
|
689
|
+
/** Crossfade the stationary Low overlay against the revealed background hero. */
|
|
690
|
+
setHandoffOpacity(opacity) {
|
|
691
|
+
if (this.handoff)
|
|
692
|
+
applyCatalogMaterialOpacity(this.handoff.actor.materials, opacity);
|
|
693
|
+
}
|
|
694
|
+
dispose() {
|
|
695
|
+
this.glass.dispose();
|
|
696
|
+
this.geometryFade.dispose();
|
|
697
|
+
if (this.disposed)
|
|
698
|
+
return;
|
|
699
|
+
this.disposed = true;
|
|
700
|
+
this.generation += 1;
|
|
701
|
+
for (const request of this.requests)
|
|
702
|
+
request.abort();
|
|
703
|
+
this.requests.clear();
|
|
704
|
+
this.handoff = undefined;
|
|
705
|
+
for (const actor of this.actors.values())
|
|
706
|
+
this.disposeActor(actor);
|
|
707
|
+
window.removeEventListener('pointermove', this.pointerMove);
|
|
708
|
+
window.removeEventListener('pointerleave', this.pointerLeave);
|
|
709
|
+
window.removeEventListener('blur', this.pointerLeave);
|
|
710
|
+
window.removeEventListener('resize', this.resize);
|
|
711
|
+
this.motion.removeEventListener('change', this.motionChange);
|
|
712
|
+
window.removeEventListener(CATALOG_POSE_CHANGED, this.motionChange);
|
|
713
|
+
this.layoutObserver.disconnect();
|
|
714
|
+
}
|
|
715
|
+
createActor(key, brandId, spatialElementId, stage, instance) {
|
|
716
|
+
const pair = resolveSpatialElementLodPair(stage.glb, stage.lodPair);
|
|
717
|
+
const rotation = pair ? undefined : stage.model?.rotation;
|
|
718
|
+
if (rotation)
|
|
719
|
+
instance.scene.rotation.set(instance.scene.rotation.x + (rotation.x ?? 0), instance.scene.rotation.y + (rotation.y ?? 0), instance.scene.rotation.z + (rotation.z ?? 0));
|
|
720
|
+
applyModelMaterialOverrides(instance.scene, stage.model?.materialOverrides);
|
|
721
|
+
const overrides = new Set();
|
|
722
|
+
const excluded = new Set(stage.model?.excludeMeshes ?? []);
|
|
723
|
+
instance.scene.traverse((object) => {
|
|
724
|
+
if (!isMesh(object))
|
|
725
|
+
return;
|
|
726
|
+
if (excluded.has(object.name))
|
|
727
|
+
object.visible = false;
|
|
728
|
+
if (stage.model?.materialOverrides?.[object.name])
|
|
729
|
+
getMeshMaterials(object).forEach((material) => overrides.add(material));
|
|
730
|
+
});
|
|
731
|
+
const sourceBounds = getMeshBounds(instance.scene, (mesh) => !excluded.has(mesh.name));
|
|
732
|
+
if (sourceBounds.isEmpty()) {
|
|
733
|
+
for (const material of overrides)
|
|
734
|
+
material.dispose();
|
|
735
|
+
throw new Error('Catalog asset contains no spatialElement geometry');
|
|
736
|
+
}
|
|
737
|
+
const referencePoint = sourceBounds.getCenter(new THREE.Vector3());
|
|
738
|
+
const model = new THREE.Group();
|
|
739
|
+
let bounds;
|
|
740
|
+
if (pair) {
|
|
741
|
+
bounds = prepareSpatialElementFrame(model, instance.scene, pair, stage.model ?? {});
|
|
742
|
+
referencePoint.set(0, 0, 0);
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
model.add(instance.scene);
|
|
746
|
+
centerAndScale(model, (mesh) => !excluded.has(mesh.name));
|
|
747
|
+
bounds = getMeshBounds(model, (mesh) => !excluded.has(mesh.name));
|
|
748
|
+
}
|
|
749
|
+
if (bounds.isEmpty()) {
|
|
750
|
+
for (const material of overrides)
|
|
751
|
+
material.dispose();
|
|
752
|
+
throw new Error('Catalog asset contains no spatialElement geometry');
|
|
753
|
+
}
|
|
754
|
+
const radius = Math.max(bounds.getBoundingSphere(new THREE.Sphere()).radius, 0.001);
|
|
755
|
+
const root = new THREE.Group();
|
|
756
|
+
root.matrixAutoUpdate = false;
|
|
757
|
+
const tilt = new THREE.Group();
|
|
758
|
+
const view = new THREE.Group();
|
|
759
|
+
view.quaternion.copy(getCameraOrbitQuaternion(stage.camera?.azimuth, stage.camera?.elevation).invert());
|
|
760
|
+
root.add(tilt);
|
|
761
|
+
tilt.add(view);
|
|
762
|
+
view.add(model);
|
|
763
|
+
const materials = captureCatalogMaterialOpacity(model);
|
|
764
|
+
applyCatalogMaterialOpacity(materials, 1);
|
|
765
|
+
return {
|
|
766
|
+
key,
|
|
767
|
+
brandId,
|
|
768
|
+
spatialElementId,
|
|
769
|
+
stage,
|
|
770
|
+
instance,
|
|
771
|
+
model,
|
|
772
|
+
root,
|
|
773
|
+
tilt,
|
|
774
|
+
view,
|
|
775
|
+
radius,
|
|
776
|
+
hitCorners: [bounds.min.x, bounds.max.x].flatMap((x) => [bounds.min.y, bounds.max.y].flatMap((y) => [bounds.min.z, bounds.max.z].map((z) => new THREE.Vector3(x, y, z)))),
|
|
777
|
+
referencePoint,
|
|
778
|
+
overrides,
|
|
779
|
+
materials,
|
|
780
|
+
scrollX: 0,
|
|
781
|
+
scrollY: 0,
|
|
782
|
+
rotationX: 0,
|
|
783
|
+
rotationY: 0,
|
|
784
|
+
lift: 0,
|
|
785
|
+
rendered: false
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
measureActors(scrollX, scrollY) {
|
|
789
|
+
if (this.handoff)
|
|
790
|
+
return;
|
|
791
|
+
const measured = [];
|
|
792
|
+
for (const actor of this.actors.values()) {
|
|
793
|
+
const list = document.querySelector(`[data-catalog-list][data-brand-id="${CSS.escape(actor.brandId)}"]`);
|
|
794
|
+
actor.slot =
|
|
795
|
+
list?.querySelector(`[data-catalog-geometry][data-spatial-element-id="${CSS.escape(actor.spatialElementId)}"]${actor.occurrence ? `[data-catalog-occurrence="${CSS.escape(actor.occurrence)}"]` : ''}`) ?? undefined;
|
|
796
|
+
actor.card =
|
|
797
|
+
actor.slot?.closest('[data-catalog-card], [data-carousel-spatial-element]') ??
|
|
798
|
+
undefined;
|
|
799
|
+
if (!actor.card || !actor.slot)
|
|
800
|
+
continue;
|
|
801
|
+
measured.push({ actor, previousTransform: actor.card.style.transform });
|
|
802
|
+
actor.card.style.transform = 'none';
|
|
803
|
+
}
|
|
804
|
+
// Batch neutral-pose writes, measurements, and restoration to avoid per-card layout thrashing.
|
|
805
|
+
for (const { actor } of measured) {
|
|
806
|
+
actor.cardRect = actor.card.getBoundingClientRect();
|
|
807
|
+
actor.slotRect = actor.slot.getBoundingClientRect();
|
|
808
|
+
actor.scrollX = scrollX;
|
|
809
|
+
actor.scrollY = scrollY;
|
|
810
|
+
}
|
|
811
|
+
for (const { actor, previousTransform } of measured)
|
|
812
|
+
actor.card.style.transform = previousTransform;
|
|
813
|
+
this.layoutDirty = false;
|
|
814
|
+
}
|
|
815
|
+
renderHandoff(renderer) {
|
|
816
|
+
const handoff = this.handoff;
|
|
817
|
+
const target = handoff.target;
|
|
818
|
+
// Otherwise Renderer would replace the custom projection on its first WebGPU draw.
|
|
819
|
+
this.handoffCamera.coordinateSystem = renderer.coordinateSystem;
|
|
820
|
+
if (target && target.camera.coordinateSystem !== renderer.coordinateSystem) {
|
|
821
|
+
target.camera.coordinateSystem = renderer.coordinateSystem;
|
|
822
|
+
target.camera.updateProjectionMatrix();
|
|
823
|
+
}
|
|
824
|
+
const progress = THREE.MathUtils.clamp(target?.progress ?? 0, 0, 1);
|
|
825
|
+
this.handoffScene.environmentIntensity = THREE.MathUtils.lerp(handoff.sourceEnvironmentIntensity, target?.environmentIntensity ?? 0.5, progress);
|
|
826
|
+
target?.model.updateWorldMatrix(true, true);
|
|
827
|
+
target?.camera.updateMatrixWorld();
|
|
828
|
+
const targetModel = target?.model.matrixWorld ?? handoff.sourceModel;
|
|
829
|
+
const targetCamera = target?.camera.matrixWorld ?? handoff.sourceCamera;
|
|
830
|
+
const targetClip = target
|
|
831
|
+
? normalizeSpatialElementClipMatrix(new THREE.Matrix4()
|
|
832
|
+
.multiplyMatrices(target.camera.projectionMatrix, target.camera.matrixWorldInverse)
|
|
833
|
+
.multiply(targetModel), handoff.actor.referencePoint)
|
|
834
|
+
: handoff.sourceClip;
|
|
835
|
+
const modelWorld = interpolatePose(handoff.sourceModel, targetModel, progress);
|
|
836
|
+
const cameraWorld = interpolatePose(handoff.sourceCamera, targetCamera, progress);
|
|
837
|
+
handoff.actor.model.matrix.copy(modelWorld);
|
|
838
|
+
handoff.actor.model.matrixWorldNeedsUpdate = true;
|
|
839
|
+
cameraWorld.decompose(this.handoffCamera.position, this.handoffCamera.quaternion, this.handoffCamera.scale);
|
|
840
|
+
this.handoffCamera.updateMatrixWorld();
|
|
841
|
+
getSpatialElementHandoffProjection(handoff.sourceClip, targetClip, progress, modelWorld, this.handoffCamera.matrixWorld, {
|
|
842
|
+
sourceModel: handoff.sourceModel,
|
|
843
|
+
sourceCamera: handoff.sourceCamera,
|
|
844
|
+
targetModel,
|
|
845
|
+
targetCamera,
|
|
846
|
+
reference: handoff.actor.referencePoint
|
|
847
|
+
}, this.handoffCamera.projectionMatrix);
|
|
848
|
+
this.handoffCamera.projectionMatrixInverse.copy(this.handoffCamera.projectionMatrix).invert();
|
|
849
|
+
renderer.clearDepth();
|
|
850
|
+
if (handoff.high && handoff.blend && (handoff.blendProgress ?? 0) > 0) {
|
|
851
|
+
const high = handoff.high;
|
|
852
|
+
const parent = high.parent;
|
|
853
|
+
const visibility = high.visible;
|
|
854
|
+
const children = [...handoff.actor.model.children];
|
|
855
|
+
const environment = this.handoffScene.environment;
|
|
856
|
+
handoff.actor.model.add(high);
|
|
857
|
+
try {
|
|
858
|
+
handoff.blend.render(renderer, (useHigh) => {
|
|
859
|
+
for (const child of children)
|
|
860
|
+
child.visible = !useHigh;
|
|
861
|
+
high.visible = useHigh;
|
|
862
|
+
this.handoffScene.environment = useHigh
|
|
863
|
+
? (handoff.highEnvironment ?? environment)
|
|
864
|
+
: environment;
|
|
865
|
+
renderer.clear();
|
|
866
|
+
renderer.render(this.handoffScene, this.handoffCamera);
|
|
867
|
+
}, false, handoff.blendProgress);
|
|
868
|
+
}
|
|
869
|
+
finally {
|
|
870
|
+
for (const child of children)
|
|
871
|
+
child.visible = true;
|
|
872
|
+
if (parent)
|
|
873
|
+
parent.add(high);
|
|
874
|
+
else
|
|
875
|
+
high.removeFromParent();
|
|
876
|
+
high.visible = visibility;
|
|
877
|
+
this.handoffScene.environment = environment;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
else
|
|
881
|
+
renderer.render(this.handoffScene, this.handoffCamera);
|
|
882
|
+
const point = handoff.actor.referencePoint
|
|
883
|
+
.clone()
|
|
884
|
+
.applyMatrix4(handoff.actor.model.matrixWorld)
|
|
885
|
+
.project(this.handoffCamera);
|
|
886
|
+
this.handoffPoint = {
|
|
887
|
+
x: ((point.x + 1) * window.innerWidth) / 2,
|
|
888
|
+
y: ((1 - point.y) * window.innerHeight) / 2
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
disposeActor(actor) {
|
|
892
|
+
actor.root.removeFromParent();
|
|
893
|
+
actor.model.removeFromParent();
|
|
894
|
+
actor.card?.removeAttribute('data-catalog-model-ready');
|
|
895
|
+
actor.card?.style.removeProperty('--catalog-rotate-x');
|
|
896
|
+
actor.card?.style.removeProperty('--catalog-rotate-y');
|
|
897
|
+
actor.card?.style.removeProperty('--catalog-lift');
|
|
898
|
+
for (const material of actor.overrides)
|
|
899
|
+
material.dispose();
|
|
900
|
+
actor.instance.dispose();
|
|
901
|
+
if (this.actors.get(actor.key) === actor)
|
|
902
|
+
this.actors.delete(actor.key);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
export function interpolatePose(source, target, progress) {
|
|
906
|
+
if (progress === 0)
|
|
907
|
+
return source.clone();
|
|
908
|
+
if (progress === 1)
|
|
909
|
+
return target.clone();
|
|
910
|
+
const position = new THREE.Vector3();
|
|
911
|
+
const rotation = new THREE.Quaternion();
|
|
912
|
+
const scale = new THREE.Vector3();
|
|
913
|
+
const targetPosition = new THREE.Vector3();
|
|
914
|
+
const targetRotation = new THREE.Quaternion();
|
|
915
|
+
const targetScale = new THREE.Vector3();
|
|
916
|
+
source.decompose(position, rotation, scale);
|
|
917
|
+
target.decompose(targetPosition, targetRotation, targetScale);
|
|
918
|
+
return new THREE.Matrix4().compose(position.lerp(targetPosition, progress), rotation.slerp(targetRotation, progress), scale.lerp(targetScale, progress));
|
|
919
|
+
}
|
|
920
|
+
//# sourceMappingURL=CatalogSpatialElementLayer.js.map
|