x3dom / x3dom

X3DOM. A framework for integrating and manipulating X3D scenes as HTML5/DOM elements.
http://x3dom.org
Other
813 stars 271 forks source link

x3dom.refresh is undefined after async loading in NextJS #1237

Closed mbritton closed 1 year ago

mbritton commented 1 year ago

System: MacOS Monterey x3dom version: 1.8.1

Expected behavior: x3dom.refresh is accessible after the dependency loads. Actual: Unhandled Runtime Error: refresh is not a function.

Thanks for the excellent 3D toolset. I'm loading x3dom in a NextJS component to display an .x3d file loaded in from a headless CMS. The first time it's accessed, the model appears. Any time I return to the route, however, the model does not appear.

I've read how people use x3dom.refresh() after the model loads in some use cases. In this case, I get an error.

import { useEffect, useState } from "react";

export async function x3DLoad() {
  return await import("x3dom");
}

export default function Visualizer() {

  useEffect(() => {
    x3DLoad().then((x3d) => {
      x3d.refresh(); <-- TypeError: x3d.refresh is not a function
    });
  }, []);

  return (
    <div className={styles.visualizerWrapper}>
      <div className={styles.visualizer}>
        <x3d is="x3d" width="100%" height="100%">
          <scene is="x3d">
            <inline
              is="x3d"
              nameSpaceName="myScene"
              mapDEFToID="true"
              url="https://prismic-io.s3.amazonaws.com/compleat/8ea368f1-d682-4709-aca2-0f5bd7b2e2ff_3dspiral.x3d"
            ></inline>
          </scene>
        </x3d>
      </div>
    </div>
  );
}

Any advice would be appreciated!

Mike

andreasplesch commented 1 year ago

It may be necessary to provide to try the latest dev version and also to post a live example to be able to develop some insight.

Also, .refresh() may be a typo since such a function is not available. Perhaps you had x3dom.reload() in mind ? It is used with the x3dom global.

brutzman commented 1 year ago

Of potential relevance two new X3D4 fields autoRefresh and autoRefreshTimeLimit are part of 9.3.2 X3DUrlObject https://www.web3d.org/specifications/X3Dv4Draft/ISO-IEC19775-1v4-DIS/Part01/components/networking.html#X3DUrlObject

X3DUrlObject {
  SFTime   [in,out] autoRefresh          0.0    [0,∞)
  SFTime   [in,out] autoRefreshTimeLimit 3600.0 [0,∞)
  SFString [in,out] description          ""
  SFBool   [in,out] load                 TRUE
  MFString [in,out] url                  []     [URI]
}
andreasplesch commented 1 year ago

Unfortunately, autorefresh is not yet implemented in x3dom.