Babylon.js: EdgeRenderer side-effect, es6 modules and TreeShaking error

Created on 26 Apr 2019  路  5Comments  路  Source: BabylonJS/Babylon.js

If I Implement my IEdgesRenderer without using the existing EdgeRenderer, the file "Rendering/edgesRenderer.js" get stripped by webpack tree-shaking.

As a consequence, the side-effects in this file which adds enableEdgesRendering and disableEdgesRendering methods to the AbstractMesh class get stripped as well.

So trying to call enableEdgesRendering causes an exception this.mesh.enableEdgesRendering is not a function

You might think of a way to fix that if possible.

Workaround :

I can disable the tree-shaking for this file by adding this line :
export class DisableTreeShaking extends EdgesRenderer {}

modules

All 5 comments

Pinging @sebavan

another workaround is to import the file directly :
import '@babylonjs/core/Rendering/edgesRenderer'

Actually enableEdgesRendering and disableEdgesRendering are creating the EdgesRenderer object itself without relying on the interface there would be of no use with you custom implementation of IEdgesRenderer.

importing IEdgesRenderer would not result in embedding the entire file as it is only an interface but it is true it would result in having the typings available for enableEdgesRendering and disableEdgesRendering.

I guess it left us only one option:

  • Moving the interface out of the file to prevent typings being available while the side effects have not run.

This way you could create your own edge renderer and instead of relying on enable/disable you would simply call new CustomEdgeRenderer(mesh) and customEdgeRenderer.dispose()

Would that work for you ?

Actually I'm using both a custom EdgeRenderer and the babylon EdgeRenderer for some mesh, so the exception happened when I was calling enableEdgesRendering to turn on the babylon EdgeRenderer.

Having the interface in its own file might do the job, if typescript prompts me to import the file that contains the side-effect when I try to call enableEdgesRendering

Fixed by adding the error message

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fmmoret picture fmmoret  路  28Comments

deltakosh picture deltakosh  路  39Comments

maxime1992 picture maxime1992  路  17Comments

innerground picture innerground  路  59Comments

sebavan picture sebavan  路  49Comments