@neurodyn/react-model-viewer 0.0.3 → 0.0.4

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.
Files changed (2) hide show
  1. package/dist/index.js +39 -0
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -6778,6 +6778,43 @@ function getModelViewerApiError(error) {
6778
6778
  if (402 === status) return 'payment-required';
6779
6779
  return null;
6780
6780
  }
6781
+ const RECOVERY_STORAGE_KEY = 'vizbl-model-viewer-blank-canvas-recovery';
6782
+ const RENDER_CHECK_DELAY_MS = 2000;
6783
+ const SAMPLE_SIZE = 64;
6784
+ const NON_ZERO_CHANNEL_THRESHOLD = 8;
6785
+ function scheduleBlankCanvasRecovery(modelViewerEl) {
6786
+ window.setTimeout(()=>{
6787
+ if (isCanvasBlank(modelViewerEl) && !hasAlreadyRecovered()) {
6788
+ markRecovered();
6789
+ window.location.reload();
6790
+ }
6791
+ }, RENDER_CHECK_DELAY_MS);
6792
+ }
6793
+ function hasAlreadyRecovered() {
6794
+ try {
6795
+ return '1' === window.sessionStorage.getItem(RECOVERY_STORAGE_KEY);
6796
+ } catch {
6797
+ return false;
6798
+ }
6799
+ }
6800
+ function markRecovered() {
6801
+ try {
6802
+ window.sessionStorage.setItem(RECOVERY_STORAGE_KEY, '1');
6803
+ } catch {}
6804
+ }
6805
+ function isCanvasBlank(modelViewerEl) {
6806
+ const canvas = modelViewerEl.shadowRoot?.querySelector('canvas.show');
6807
+ if (!canvas || 0 === canvas.width || 0 === canvas.height) return false;
6808
+ const gl = canvas.getContext('webgl2') ?? canvas.getContext('webgl');
6809
+ if (!gl) return false;
6810
+ const size = Math.min(SAMPLE_SIZE, canvas.width, canvas.height);
6811
+ const x = Math.max(0, Math.floor((canvas.width - size) / 2));
6812
+ const y = Math.max(0, Math.floor((canvas.height - size) / 2));
6813
+ const pixels = new Uint8Array(size * size * 4);
6814
+ gl.readPixels(x, y, size, size, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
6815
+ for(let i = 0; i < pixels.length; i += 4)if (pixels[i] > NON_ZERO_CHANNEL_THRESHOLD || pixels[i + 1] > NON_ZERO_CHANNEL_THRESHOLD || pixels[i + 2] > NON_ZERO_CHANNEL_THRESHOLD || pixels[i + 3] > NON_ZERO_CHANNEL_THRESHOLD) return false;
6816
+ return true;
6817
+ }
6781
6818
  const ModelViewerContext = /*#__PURE__*/ createContext(null);
6782
6819
  function ModelViewerProvider({ children, tinuuid, apiKey, appClipBundleId, arExperience, apiBaseUrl, legacyApiBaseUrl, mode, initialWidgetSessionToken, handoffUrl, hid, launchAr, layout, background, sizeType, viewerSurface }) {
6783
6820
  const { object, material, error, isLoading, setMaterialHid: setObjectMaterialHid, widgetSession } = useObjectData(tinuuid, hid, {
@@ -6865,6 +6902,7 @@ function ModelViewerProvider({ children, tinuuid, apiKey, appClipBundleId, arExp
6865
6902
  };
6866
6903
  const handleLoad = ()=>{
6867
6904
  setIsModelLoading(false);
6905
+ scheduleBlankCanvasRecovery(modelViewerEl);
6868
6906
  };
6869
6907
  const handleError = ()=>{
6870
6908
  setIsModelLoading(false);
@@ -7799,6 +7837,7 @@ function ModelViewerContainer({ showDialogCloseButton = false }) {
7799
7837
  arScale: "fixed",
7800
7838
  shadowIntensity: 1,
7801
7839
  interactionPromptThreshold: 100,
7840
+ loading: "eager",
7802
7841
  children: [
7803
7842
  /*#__PURE__*/ jsx("div", {
7804
7843
  slot: "progress-bar"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@neurodyn/react-model-viewer",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -36,7 +36,7 @@
36
36
  "radix-ui": "1.4.3",
37
37
  "react-shadow": "^20.6.0",
38
38
  "tailwind-merge": "3.4.0",
39
- "three": "^0.185.1"
39
+ "three": "0.182.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@microsoft/api-extractor": "^7.58.0",