|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import {
- _testFinish,
- AViewerPluginSync,
- DepthBufferPlugin,
- DropzonePlugin,
- FullScreenPlugin,
- HalfFloatType,
- IObject3D,
- NormalBufferPlugin,
- RenderTargetPreviewPlugin,
- ThreeViewer,
- UnsignedByteType,
- } from 'threepipe'
- import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
- import {TweakpaneEditorPlugin} from '@threepipe/plugin-tweakpane-editor'
-
- class ViewerUiConfig extends AViewerPluginSync<''> {
- static readonly PluginType = 'ViewerUiConfig'
- enabled = true
- toJSON: any = undefined
- constructor(viewer: ThreeViewer) {
- super()
- this._viewer = viewer
- this.uiConfig = viewer.uiConfig
- }
- }
- async function init() {
-
- const viewer = new ThreeViewer({
- canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
- msaa: false,
- dropzone: {
- addOptions: {
- clearSceneObjects: false,
- },
- },
- })
-
- viewer.addPluginSync(new TweakpaneUiPlugin(true))
- const editor = viewer.addPluginSync(new TweakpaneEditorPlugin())
-
- await viewer.addPlugins([
- new ViewerUiConfig(viewer),
- new DepthBufferPlugin(UnsignedByteType, false, false),
- new NormalBufferPlugin(HalfFloatType, false),
- new RenderTargetPreviewPlugin(false),
- ])
-
- const rt = viewer.getOrAddPluginSync(RenderTargetPreviewPlugin)
- rt.addTarget(viewer.getPlugin(DepthBufferPlugin)?.target, 'depth', false, false, false)
- rt.addTarget(viewer.getPlugin(NormalBufferPlugin)?.target, 'normal', false, true, false)
-
- editor.loadPlugins({
- ['Viewer']: [ViewerUiConfig, DropzonePlugin, FullScreenPlugin],
- ['GBuffer']: [DepthBufferPlugin, NormalBufferPlugin],
- ['Debug']: [RenderTargetPreviewPlugin],
- })
-
- await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr', {
- setBackground: true,
- })
- await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
- autoCenter: true,
- autoScale: true,
- })
-
- // const model = result?.getObjectByName('node_damagedHelmet_-6514')
- // const config = model?.uiConfig
- // if (config) ui.appendChild(config)
-
- }
-
- init().then(_testFinish)
|