lo-th / phy

Physics for three. Game engine
https://lo-th.github.io/phy/
MIT License
498 stars 42 forks source link

relative paths for phy init not respected. #35

Open ubernaut opened 1 month ago

ubernaut commented 1 month ago

I ran into this problem when trying to deploy to github pages, which puts everything in a subdirectory with the name of your project ie:

https://ubernaut.github.io/simple-template/

you should be able to pass in a relative path (like './') so compact would be resolved at:

https://ubernaut.github.io/simple-template/compact

instead, it will insist on trying to find it here:

https://ubernaut.github.io/compact/

this doesn't work, phy will fail to find the physics hex files in compact if they aren't at the root of your url's path:

phy.init({
    type: "physx",
    worker: true,
    compact: true,
    scene: scene,
    renderer: renderer,
    callback: physicsReady,
    path: './'

  });

workaround: You can pass in an explicit path and it does correctly prefix the dependencies so set an env variable in your package script for the path you want to use. like this (start is for local dev where it can run at root, and build is for gh pages):


  "scripts": {
    "test": "",
    "start": "export stpath='./'; parcel --https index.html",
    "build": "export stpath='/simple-template/'; parcel build index.html --public-url /simple-template/"
  },

then reference the variable in the init

  phy.init({
    type: "physx",
    worker: true,
    compact: true,
    scene: scene,
    renderer: renderer,
    callback: physicsReady,
    path: process.env.stpath
  });
lo-th commented 1 month ago

ok i will look that thank's for the moment copy compact folder to public if you use vite