Skip to content

Help using pnextThreeLoader with react #126

Description

@mikisf

I'm trying to use this library with my react project but I'm struggling to make it work.
The first issue I run into was the error: "window is not defined", which I was able to solve it by importing the component dynamically without server side rendering, doing it like so:

const PNextThreeLoader = dynamic(
  () => import("../components/PNextThreeLoader"),
  {
    ssr: false,
  }
);

After, I tried loading the example pointcloud like this:

useEffect(() => {
    if (sceneVar === undefined) return;
    const baseUrl = "https://cdn.rawgit.com/potree/potree/develop/pointclouds/lion_takanawa/";
    potreeVar
        .loadPointCloud("cloud.js", (url) => `${baseUrl}${url}`)
        .then((pco) => {
            console.log(pco);
            sceneVar.add(pco);
            potreeVar.updatePointClouds([pco], cameraVar, rendererVar);
            rendererVar.render(sceneVar, cameraVar);
        });
}, [sceneVar]);

but I'm not able to see the lion and there is no error in the console.
I've created a sandbox so you can test it: https://codesandbox.io/p/github/mikisf/pNextThreeLoaderReact/draft/hopeful-silence?file=/components/PNextThreeLoader.js:64,3-76,18&workspaceId=9764f67d-193b-4747-b7a4-e67f33e4cfb2
Or in this github repo: https://github.com/mikisf/pNextThreeLoaderReact
Thanks in advance ;)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions