fenomas / noa

Experimental voxel game engine.
MIT License
611 stars 87 forks source link

Uncaught TypeError: this._scene.enableDepthRenderer is not a function #128

Closed csf30816 closed 4 years ago

csf30816 commented 4 years ago
Uncaught TypeError: this._scene.enableDepthRenderer is not a function

when trying to add DoF using the DefaultRenderingPipeline I get that error.

const {
    DefaultRenderingPipeline
} = require("@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline");
const pipeline = new DefaultRenderingPipeline(
    null,
    false,
    scene,
    scene.cameras
);

pipeline.depthOfFieldEnabled = true;
pipeline.depthOfFieldBlurLevel = 1;
pipeline.depthOfField.focusDistance = 2000
pipeline.depthOfField.focalLength = 45;
pipeline.depthOfField.fStop = 1.4;

pipeline.samples = 4;
fenomas commented 4 years ago

Hi, this is nothing to do with noa, it has to do with Babylon's move to ES6 modules (for the sake of tree shaking).

The short answer is you need to import a babylon component that enables the feature you want, and then (asynchronously afterwards) set up noa, which creates the babylon scene, and then you can set up DOF

import('@babylonjs/core/Rendering/depthRendererSceneComponent').then(() => {
    // initialize noa
    var scene = noa.rendering.getScene()
    // set up DOF
})

You're probably thinking "wait how do I know which Babylon library I need to import for which feature?" and the answer is, I don't know, I found the answer this BJS forum post. Probably Babylon needs better error messages for stuff like this.

csf30816 commented 4 years ago

Ah, thank you. I had some errors with tree shaking earlier that I resolved. I just didn't think this was the same problem. Thanks!

As for finding the right module I just search in the BJS GitHub repo for files.