threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import {
  2. _testFinish,
  3. AViewerPluginSync,
  4. DepthBufferPlugin,
  5. DropzonePlugin,
  6. FullScreenPlugin,
  7. HalfFloatType,
  8. IObject3D,
  9. NormalBufferPlugin,
  10. RenderTargetPreviewPlugin,
  11. ThreeViewer,
  12. TweakpaneUiPlugin,
  13. UnsignedByteType,
  14. } from 'threepipe'
  15. import {TweakpaneEditorPlugin} from '@threepipe/plugins/ui/tweakpane-editor'
  16. class ViewerUiConfig extends AViewerPluginSync<''> {
  17. static readonly PluginType = 'ViewerUiConfig'
  18. enabled = true
  19. toJSON: any = undefined
  20. constructor(viewer: ThreeViewer) {
  21. super()
  22. this._viewer = viewer
  23. this.uiConfig = viewer.uiConfig
  24. }
  25. }
  26. async function init() {
  27. const viewer = new ThreeViewer({
  28. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  29. msaa: false,
  30. dropzone: {
  31. addOptions: {
  32. clearSceneObjects: false,
  33. },
  34. },
  35. })
  36. viewer.addPluginSync(new TweakpaneUiPlugin(true))
  37. const editor = viewer.addPluginSync(new TweakpaneEditorPlugin())
  38. await viewer.addPlugins([
  39. new ViewerUiConfig(viewer),
  40. new DepthBufferPlugin(UnsignedByteType, false, false),
  41. new NormalBufferPlugin(HalfFloatType, false),
  42. new RenderTargetPreviewPlugin(false),
  43. ])
  44. const rt = viewer.getOrAddPluginSync(RenderTargetPreviewPlugin)
  45. rt.addTarget(viewer.getPlugin(DepthBufferPlugin)?.target, 'depth', false, false, false)
  46. rt.addTarget(viewer.getPlugin(NormalBufferPlugin)?.target, 'normal', false, true, false)
  47. editor.loadPlugins({
  48. ['Viewer']: [ViewerUiConfig, DropzonePlugin, FullScreenPlugin],
  49. ['GBuffer']: [DepthBufferPlugin, NormalBufferPlugin],
  50. ['Debug']: [RenderTargetPreviewPlugin],
  51. })
  52. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr', {
  53. setBackground: true,
  54. })
  55. await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  56. autoCenter: true,
  57. autoScale: true,
  58. })
  59. // const model = result?.getObjectByName('node_damagedHelmet_-6514')
  60. // const config = model?.uiConfig
  61. // if (config) ui.appendChild(config)
  62. }
  63. init().then(_testFinish)