pex-gl / pex-renderer

Physically based renderer (PBR) and scene graph for PEX.
https://pex-gl.github.io/pex-renderer/examples/index.html
MIT License
234 stars 16 forks source link

Add activeCamera to renderer #239

Closed vorg closed 1 year ago

vorg commented 4 years ago

Currently all cameras are rendered all the time if enabled

index.js#L1158

cameras
    .filter((camera) => camera.enabled)

Sometimes it would be useful to have 2 or more cameras and switch between them without disabling them. E.g. debug fly camera looking at main camera from 3rd person point of view to debug FoV and near/far clipping planes defining main camera's frustum.

How this could be implemented?

// render using only selected camera
renderer.activeCamera = debugMode ? debugCamera : mainCamera

// render all cameras
renderer.activeCamera = null
debugCamera.enabled = false //prevent drawing debug view

Why not simply enable / disable cameras? E.g.:

debugCamera.enabled = true
mainCamera.enabled = false

Doing this would also hide mainCamera helpers so debugging it from 3rd person point of view would be impossible.

dmnsgn commented 1 year ago

v4: renderEngine.render accepts a list of entities and cameraEntities to mix and match