@liveroom-tech/react-immersive 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,10 +12,12 @@ import {
12
12
  material,
13
13
  ModelViewer,
14
14
  patchBindings,
15
+ patchSceneConfig,
15
16
  SimpleModelViewer,
16
17
  useObjectBinding,
17
18
  useObjectBindingIds,
18
19
  useObjectBindings,
20
+ useSceneConfig,
19
21
  useViewerActions,
20
22
  useViewerAnimations,
21
23
  useViewerCamera,
@@ -27,7 +29,7 @@ import {
27
29
  } from "@liveroom-tech/react-immersive";
28
30
  ```
29
31
 
30
- It also exports types for `ObjectBinding`, `ObjectBindingMaterial`, `ObjectBindingsController`, `ObjectActionEvent`, `SceneConfig`, `AnimationControls`, `CinematicConfig` / `CinematicWaypoint`, and related shapes used throughout this document.
32
+ It also exports types for `ObjectBinding`, `ObjectBindingMaterial`, `ObjectBindingsController`, `ObjectActionEvent`, `SceneConfig`, `SceneConfigPatch`, `SceneConfigController`, `AnimationControls`, `CinematicConfig` / `CinematicWaypoint`, and related shapes used throughout this document.
31
33
 
32
34
  `ModelViewer` provides:
33
35
 
@@ -334,7 +336,7 @@ If you want one state owner for binding patches, materials, and visibility, use
334
336
  const {
335
337
  objectBindings,
336
338
  setObjectBindings,
337
- patch,
339
+ updateObjectBindings,
338
340
  setMaterial,
339
341
  setBaseColor,
340
342
  resetMaterial,
@@ -356,7 +358,7 @@ const {
356
358
  />;
357
359
  ```
358
360
 
359
- `useObjectBindings` owns the state used by the viewer. Every setter uses a functional update, so consecutive material, visibility, and general patch calls in the same tick compose instead of overwriting each other.
361
+ `useObjectBindings` owns the state used by the viewer. Every setter uses a functional update, so consecutive material, visibility, and general binding updates in the same tick compose instead of overwriting each other.
360
362
 
361
363
  Object identifiers accepted by its methods can be:
362
364
 
@@ -367,7 +369,7 @@ Object identifiers accepted by its methods can be:
367
369
  The hook returns:
368
370
 
369
371
  - `objectBindings` and `setObjectBindings`
370
- - `patch` for any binding field or atomic edit batch
372
+ - `updateObjectBindings` for any binding field or atomic edit batch
371
373
  - `setMaterial`, `setBaseColor`, `resetMaterial`, and `getMaterial`
372
374
  - `hiddenObjects`: a derived map of hidden binding keys
373
375
  - `hiddenObjectIds`: the currently hidden binding IDs
@@ -375,6 +377,37 @@ The hook returns:
375
377
  - `isObjectHidden`
376
378
  - `clearHiddenObjects`
377
379
 
380
+ For scene-wide state, use `useSceneConfig`:
381
+
382
+ ```tsx
383
+ const {
384
+ sceneConfig,
385
+ setSceneConfig,
386
+ updateSceneConfig,
387
+ resetSceneConfig,
388
+ } = useSceneConfig(initialSceneConfig);
389
+
390
+ const enableUvChecker = () =>
391
+ updateSceneConfig({
392
+ model: { renderer: "uv-checker" },
393
+ lighting: { ambient: { intensity: 0.5 } },
394
+ });
395
+
396
+ <ModelViewer
397
+ modelUrl="/model.glb"
398
+ licenseKey="your-license-key"
399
+ objectBindings={objectBindings}
400
+ sceneConfig={sceneConfig}
401
+ />;
402
+
403
+ <button onClick={enableUvChecker}>Show UV checker</button>;
404
+ ```
405
+
406
+ Nested objects merge recursively, while arrays and tuples are replaced. Every
407
+ update uses a functional state updater, so consecutive calls compose. Use the
408
+ pure `patchSceneConfig(sceneConfig, patch)` utility when a store or parent owns
409
+ the scene state.
410
+
378
411
  If you want to keep hover state in sync with the viewer, the library also exports:
379
412
 
380
413
  ```tsx
package/dist/index.d.mts CHANGED
@@ -664,9 +664,10 @@ declare function useObjectBinding(objectBindings: Record<string, ObjectBinding>,
664
664
 
665
665
  declare function useObjectBindingIds(objectBindings: Record<string, ObjectBinding>): string[];
666
666
 
667
- type DeepPartial<T> = T extends (infer _U)[] ? T : T extends object ? {
667
+ type DeepPartial<T> = T extends readonly unknown[] ? T : T extends object ? {
668
668
  [K in keyof T]?: DeepPartial<T[K]>;
669
669
  } : T;
670
+
670
671
  type ObjectBindingPatch = DeepPartial<ObjectBinding>;
671
672
  type BindingEdit = {
672
673
  ids: string | string[];
@@ -689,7 +690,7 @@ type HiddenObjectsState = Record<string, boolean>;
689
690
  type ObjectBindingsController = {
690
691
  objectBindings: Record<string, ObjectBinding>;
691
692
  setObjectBindings: React.Dispatch<React.SetStateAction<Record<string, ObjectBinding>>>;
692
- patch: {
693
+ updateObjectBindings: {
693
694
  (objectId: string | string[], patch: ObjectBindingPatch): void;
694
695
  (edits: BindingEdit[]): void;
695
696
  };
@@ -714,6 +715,26 @@ type ObjectBindingsController = {
714
715
  */
715
716
  declare function useObjectBindings(initialBindings: Record<string, ObjectBinding> | (() => Record<string, ObjectBinding>)): ObjectBindingsController;
716
717
 
718
+ type SceneConfigPatch = DeepPartial<SceneConfig>;
719
+ /**
720
+ * Applies a nested scene-config patch without mutating either input. Objects
721
+ * are merged recursively, while arrays and tuples are replaced wholesale.
722
+ */
723
+ declare function patchSceneConfig(sceneConfig: SceneConfig, patch: SceneConfigPatch): SceneConfig;
724
+
725
+ type SceneConfigUpdate = SceneConfigPatch | ((current: SceneConfig) => SceneConfigPatch);
726
+ type SceneConfigController = {
727
+ sceneConfig: SceneConfig;
728
+ setSceneConfig: React.Dispatch<React.SetStateAction<SceneConfig>>;
729
+ updateSceneConfig: (update: SceneConfigUpdate) => void;
730
+ resetSceneConfig: () => void;
731
+ };
732
+ /**
733
+ * Owns scene-config state and applies nested patches through functional React
734
+ * updates, so consecutive calls in the same tick compose safely.
735
+ */
736
+ declare function useSceneConfig(initialSceneConfig: SceneConfig | (() => SceneConfig)): SceneConfigController;
737
+
717
738
  type ViewerHoverProps = {
718
739
  hoveredObjectBinding: ObjectBinding | null;
719
740
  handleHoveredObject: (binding: ObjectBinding | null) => void;
@@ -766,4 +787,4 @@ type ShareableViewerStateProps = {
766
787
  };
767
788
  declare function useShareableViewerState({ cameraState, setCameraState, objectBindings, onObjectBindingsChange, selectedObjectBinding, setSelectedObjectBinding, paramKey, debounceMs, autoSync, }: UseShareableViewerStateOptions): ShareableViewerStateProps;
768
789
 
769
- export { type AnimationClipInfo, type AnimationControls, type AnimationLoopMode, type AnimationPlaybackState, BindingBuilder, type BindingEdit, type CaptureImageOptions, type CinematicConfig, type CinematicWaypoint, type CustomObjectBindingDataPanelProps, type CustomSceneObjectsPanelProps, type HiddenObjectsState, type HomeCameraState, MATERIAL_BLENDING_MODES, MATERIAL_SIDES, ModelViewer, type ModelViewerProps, type ObjectActionEvent, type ObjectBinding, type ObjectBindingAction, type ObjectBindingMaterial, type ObjectBindingMaterialBlendingMode, type ObjectBindingMaterialSide, type ObjectBindingPatch, type ObjectBindingTextureSlot, type ObjectBindingsController, type SceneAnimationClipConfig, type SceneAnimationConfig, type SceneCinematicConfig, type SceneCinematicWaypoint, type SceneConfig, type SceneModelRenderer, SimpleModelViewer, type SimpleModelViewerProps, type ViewerActionsOptions, type ViewerActionsProps, type ViewerAnimationsProps, type ViewerCameraProps, type ViewerCameraState, type ViewerModelBounds, type ViewerModelProps, type ViewerReadyState, type ViewerSelectionProps, type XRScaleMode, material, patchBindings, useObjectBinding, useObjectBindingIds, useObjectBindings, useShareableViewerState, useViewerActions, useViewerAnimations, useViewerCamera, useViewerHover, useViewerModel, useViewerSelection };
790
+ export { type AnimationClipInfo, type AnimationControls, type AnimationLoopMode, type AnimationPlaybackState, BindingBuilder, type BindingEdit, type CaptureImageOptions, type CinematicConfig, type CinematicWaypoint, type CustomObjectBindingDataPanelProps, type CustomSceneObjectsPanelProps, type HiddenObjectsState, type HomeCameraState, MATERIAL_BLENDING_MODES, MATERIAL_SIDES, ModelViewer, type ModelViewerProps, type ObjectActionEvent, type ObjectBinding, type ObjectBindingAction, type ObjectBindingMaterial, type ObjectBindingMaterialBlendingMode, type ObjectBindingMaterialSide, type ObjectBindingPatch, type ObjectBindingTextureSlot, type ObjectBindingsController, type SceneAnimationClipConfig, type SceneAnimationConfig, type SceneCinematicConfig, type SceneCinematicWaypoint, type SceneConfig, type SceneConfigController, type SceneConfigPatch, type SceneConfigUpdate, type SceneModelRenderer, SimpleModelViewer, type SimpleModelViewerProps, type ViewerActionsOptions, type ViewerActionsProps, type ViewerAnimationsProps, type ViewerCameraProps, type ViewerCameraState, type ViewerModelBounds, type ViewerModelProps, type ViewerReadyState, type ViewerSelectionProps, type XRScaleMode, material, patchBindings, patchSceneConfig, useObjectBinding, useObjectBindingIds, useObjectBindings, useSceneConfig, useShareableViewerState, useViewerActions, useViewerAnimations, useViewerCamera, useViewerHover, useViewerModel, useViewerSelection };
package/dist/index.d.ts CHANGED
@@ -664,9 +664,10 @@ declare function useObjectBinding(objectBindings: Record<string, ObjectBinding>,
664
664
 
665
665
  declare function useObjectBindingIds(objectBindings: Record<string, ObjectBinding>): string[];
666
666
 
667
- type DeepPartial<T> = T extends (infer _U)[] ? T : T extends object ? {
667
+ type DeepPartial<T> = T extends readonly unknown[] ? T : T extends object ? {
668
668
  [K in keyof T]?: DeepPartial<T[K]>;
669
669
  } : T;
670
+
670
671
  type ObjectBindingPatch = DeepPartial<ObjectBinding>;
671
672
  type BindingEdit = {
672
673
  ids: string | string[];
@@ -689,7 +690,7 @@ type HiddenObjectsState = Record<string, boolean>;
689
690
  type ObjectBindingsController = {
690
691
  objectBindings: Record<string, ObjectBinding>;
691
692
  setObjectBindings: React.Dispatch<React.SetStateAction<Record<string, ObjectBinding>>>;
692
- patch: {
693
+ updateObjectBindings: {
693
694
  (objectId: string | string[], patch: ObjectBindingPatch): void;
694
695
  (edits: BindingEdit[]): void;
695
696
  };
@@ -714,6 +715,26 @@ type ObjectBindingsController = {
714
715
  */
715
716
  declare function useObjectBindings(initialBindings: Record<string, ObjectBinding> | (() => Record<string, ObjectBinding>)): ObjectBindingsController;
716
717
 
718
+ type SceneConfigPatch = DeepPartial<SceneConfig>;
719
+ /**
720
+ * Applies a nested scene-config patch without mutating either input. Objects
721
+ * are merged recursively, while arrays and tuples are replaced wholesale.
722
+ */
723
+ declare function patchSceneConfig(sceneConfig: SceneConfig, patch: SceneConfigPatch): SceneConfig;
724
+
725
+ type SceneConfigUpdate = SceneConfigPatch | ((current: SceneConfig) => SceneConfigPatch);
726
+ type SceneConfigController = {
727
+ sceneConfig: SceneConfig;
728
+ setSceneConfig: React.Dispatch<React.SetStateAction<SceneConfig>>;
729
+ updateSceneConfig: (update: SceneConfigUpdate) => void;
730
+ resetSceneConfig: () => void;
731
+ };
732
+ /**
733
+ * Owns scene-config state and applies nested patches through functional React
734
+ * updates, so consecutive calls in the same tick compose safely.
735
+ */
736
+ declare function useSceneConfig(initialSceneConfig: SceneConfig | (() => SceneConfig)): SceneConfigController;
737
+
717
738
  type ViewerHoverProps = {
718
739
  hoveredObjectBinding: ObjectBinding | null;
719
740
  handleHoveredObject: (binding: ObjectBinding | null) => void;
@@ -766,4 +787,4 @@ type ShareableViewerStateProps = {
766
787
  };
767
788
  declare function useShareableViewerState({ cameraState, setCameraState, objectBindings, onObjectBindingsChange, selectedObjectBinding, setSelectedObjectBinding, paramKey, debounceMs, autoSync, }: UseShareableViewerStateOptions): ShareableViewerStateProps;
768
789
 
769
- export { type AnimationClipInfo, type AnimationControls, type AnimationLoopMode, type AnimationPlaybackState, BindingBuilder, type BindingEdit, type CaptureImageOptions, type CinematicConfig, type CinematicWaypoint, type CustomObjectBindingDataPanelProps, type CustomSceneObjectsPanelProps, type HiddenObjectsState, type HomeCameraState, MATERIAL_BLENDING_MODES, MATERIAL_SIDES, ModelViewer, type ModelViewerProps, type ObjectActionEvent, type ObjectBinding, type ObjectBindingAction, type ObjectBindingMaterial, type ObjectBindingMaterialBlendingMode, type ObjectBindingMaterialSide, type ObjectBindingPatch, type ObjectBindingTextureSlot, type ObjectBindingsController, type SceneAnimationClipConfig, type SceneAnimationConfig, type SceneCinematicConfig, type SceneCinematicWaypoint, type SceneConfig, type SceneModelRenderer, SimpleModelViewer, type SimpleModelViewerProps, type ViewerActionsOptions, type ViewerActionsProps, type ViewerAnimationsProps, type ViewerCameraProps, type ViewerCameraState, type ViewerModelBounds, type ViewerModelProps, type ViewerReadyState, type ViewerSelectionProps, type XRScaleMode, material, patchBindings, useObjectBinding, useObjectBindingIds, useObjectBindings, useShareableViewerState, useViewerActions, useViewerAnimations, useViewerCamera, useViewerHover, useViewerModel, useViewerSelection };
790
+ export { type AnimationClipInfo, type AnimationControls, type AnimationLoopMode, type AnimationPlaybackState, BindingBuilder, type BindingEdit, type CaptureImageOptions, type CinematicConfig, type CinematicWaypoint, type CustomObjectBindingDataPanelProps, type CustomSceneObjectsPanelProps, type HiddenObjectsState, type HomeCameraState, MATERIAL_BLENDING_MODES, MATERIAL_SIDES, ModelViewer, type ModelViewerProps, type ObjectActionEvent, type ObjectBinding, type ObjectBindingAction, type ObjectBindingMaterial, type ObjectBindingMaterialBlendingMode, type ObjectBindingMaterialSide, type ObjectBindingPatch, type ObjectBindingTextureSlot, type ObjectBindingsController, type SceneAnimationClipConfig, type SceneAnimationConfig, type SceneCinematicConfig, type SceneCinematicWaypoint, type SceneConfig, type SceneConfigController, type SceneConfigPatch, type SceneConfigUpdate, type SceneModelRenderer, SimpleModelViewer, type SimpleModelViewerProps, type ViewerActionsOptions, type ViewerActionsProps, type ViewerAnimationsProps, type ViewerCameraProps, type ViewerCameraState, type ViewerModelBounds, type ViewerModelProps, type ViewerReadyState, type ViewerSelectionProps, type XRScaleMode, material, patchBindings, patchSceneConfig, useObjectBinding, useObjectBindingIds, useObjectBindings, useSceneConfig, useShareableViewerState, useViewerActions, useViewerAnimations, useViewerCamera, useViewerHover, useViewerModel, useViewerSelection };