How to use pc objects like Vec3 in other javascript modules?

I’m working on my engine-only project. I want to split functionality into classes insize javascript modules.
These modules also need to have access to pc objects like the Vec3 and its methods.

How to define the import for this?

I guess I can import everything from pc using:

import * as pc from "playcanvas-stable.js";

Is that correct?
And how to import only one object like pc.Vec3?

Is that as simple as this?:

import { Vec3 } from "playcanvas-stable.js";

you should import playcanvas from npm, here is an example of how this could be set up:

The question was not how to import playcanvas, but how to import objects from playcanvas to be used inside other javascript modules.

(BTW, playcanvas is running inside a website, so it is imported like this:

 <script src="./javascript/playcanvas/playcanvas-stable.js"></script>


If you load a script like you do using a script tag, than you don’t need to import part of it as the whole PlayCanvas is available already, in memory. You can just use pc.Vec3 for example.

Importing makes sense if you do not load the whole PlayCanvas script, but want to load individual modules of it. And that’s what the model-viewer I linked does.

1 Like

Ok, thx. That is interesting. I will take a look.