-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import {WebGLRenderer} from 'three'; | ||
|
||
const DEFAULT_WIDTH = 320; | ||
const DEFAULT_HEIGHT = 240; | ||
|
||
export class ThreeMultiViewRenderer { | ||
#views = new Map(); | ||
#lastViewId = 0; | ||
|
||
constructor({provideContext, onDestroy}) { | ||
const [, setMultiViewRenderer] = provideContext('multiViewRenderer', this); | ||
|
||
onDestroy(() => { | ||
setMultiViewRenderer(null); | ||
}); | ||
|
||
this.canvas = new OffscreenCanvas(DEFAULT_WIDTH, DEFAULT_HEIGHT); | ||
|
||
// XXX how we can set webgl-renderer parameters? | ||
this.renderer = new WebGLRenderer({canvas: this.canvas}); | ||
this.renderer.setScissorTest(true); | ||
|
||
console.log('ThreeMultiViewRenderer created', this); | ||
} | ||
|
||
createView(width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT) { | ||
const viewId = ++this.#lastViewId; | ||
const view = {viewId, width, height, viewport: [0, 0, width, height], scene: null, camera: null}; | ||
this.#views.set(viewId, view); | ||
return view; | ||
} | ||
|
||
renderView(view) { | ||
if (view?.scene == null || view?.camera == null) return; | ||
if (!(view.width > 0 && view.height > 0)) return; | ||
if (!(view.viewport[2] > 0 && view.viewport[3] > 0)) return; | ||
if (this.#views.has(view.viewId) === false) { | ||
throw new Error(`not my view: ${view.viewId}`); | ||
} | ||
|
||
this.updateSize(); | ||
|
||
this.renderer.setScissor(0, 0, view.width, view.height); | ||
this.renderer.setViewport(...view.viewport); | ||
this.renderer.render(view.scene, view.camera); | ||
} | ||
|
||
destroyView(view) { | ||
const viewId = typeof view === 'number' ? view : view.viewId; | ||
this.#views.delete(viewId); | ||
} | ||
|
||
updateSize() { | ||
let width = DEFAULT_WIDTH; | ||
let height = DEFAULT_HEIGHT; | ||
for (const view of this.#views.values()) { | ||
width = Math.max(width, view.width); | ||
height = Math.max(height, view.height); | ||
} | ||
if (this.canvas.width === width && this.canvas.height === height) return; | ||
this.renderer.setSize(width, height, false); | ||
} | ||
|
||
onDestroy() { | ||
this.renderer.dispose(); | ||
this.renderer = null; | ||
console.log('ThreeMultiViewRenderer destroyed', this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function ThreeRenderView(/* {useContext, onDestroy, provideContext} */) { | ||
// TODO implement ThreeRenderView | ||
// | ||
// - useContext('canvas'); | ||
// - create bitmapdrawingcontext2d.. | ||
// - useContext('canvasSize'); | ||
// - useContext('multiViewRenderer'); | ||
// - create render-view with multiViewRenderer.createView() | ||
// - onRenderFrame() - call multiViewRenderer.renderView(view) and copy webgl-canvas-content to our canvas | ||
// | ||
// maybe not here but in another shadow-object: | ||
// - provideContext('three.scene'); | ||
// - provideContext('three.camera'); | ||
// - setCamera(...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
export class VfxCtxCanvas { | ||
constructor({useProperty, provideContext}) { | ||
constructor({useProperty, useContext}) { | ||
const getBar = useProperty('bar'); | ||
|
||
getBar((val) => { | ||
console.log('[VfxCtxCanvas] bar changed to', val); | ||
console.debug('[VfxCtxCanvas] bar changed to', val); | ||
}); | ||
|
||
console.debug('[VfxCtxCanvas] bar is initially set to', getBar()); | ||
|
||
// ---- | ||
|
||
provideContext('multiViewRenderer', this); | ||
useContext('multiViewRenderer')((val) => { | ||
console.log('[VfxCtxCanvas] multiViewRenderer context set to', val); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.