iTowns / itowns

A Three.js-based framework written in Javascript/WebGL for visualizing 3D geospatial data
http://www.itowns-project.org
Other
1.11k stars 299 forks source link

Bug when we use custom renderer with potree point cloud #2142

Closed ketourneau closed 1 year ago

ketourneau commented 1 year ago

We try to use itowns in a vite project to display potree point cloud but we got error:

Capture d’écran 2023-07-17 à 15 41 08

Error appears when we pass custom renderer to itowns view.

const customRenderer = new THREE.WebGLRenderer();
const customCamera = new THREE.PerspectiveCamera(...);
...

const view = new itowns.View('EPSG:3946', viewerDiv, {
    camera: { cameraThree: customCamera },
    renderer: customRenderer,
});

I made a codesanbox to reproduce the issue here

jailln commented 1 year ago

And yet your code works in an itowns example. The error appears when importing fragment shaders (which is done in the point clouds shaders in itowns). I'm not familiar with vite but maybe it's not supported with vite and you need to use a plugin like this one ?

Desplandis commented 1 year ago

I manage to reproduce your issue locally. From the warning on the console, it seems that Multiple instances of Three.js [are] being imported.

Three.js glsl prepocessor resolves include directives from the ShaderChunk object. When imported, itowns appends its own "chunks" of glsl (e.g. itowns/WebGL2_pars_vertex) to its three's instance ShaderChunk. If your project and itowns import different instances of three, such chunks would not be available to your project's three instance leading to such error.

I suspect that vite, when bundling, duplicates the three dependency.