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.

script.ts 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {
  2. _testFinish,
  3. IObject3D,
  4. LoadingScreenPlugin,
  5. PhysicalMaterial,
  6. PickingPlugin,
  7. SSAAPlugin,
  8. ThreeViewer,
  9. Vector3,
  10. } from 'threepipe'
  11. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  12. // @ts-expect-error todo fix
  13. import {BloomPlugin, DepthOfFieldPlugin} from '@threepipe/webgi-plugins'
  14. async function init() {
  15. const viewer = new ThreeViewer({
  16. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  17. msaa: true,
  18. // rgbm: false,
  19. plugins: [LoadingScreenPlugin, SSAAPlugin, BloomPlugin, PickingPlugin],
  20. })
  21. const dofPlugin = viewer.addPluginSync(DepthOfFieldPlugin)
  22. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  23. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr', {
  24. setBackground: true,
  25. })
  26. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/kira.glb', {
  27. autoCenter: true,
  28. autoScale: true,
  29. autoScaleRadius: 15,
  30. })
  31. const model = result?.getObjectByName('node_damagedHelmet_-6514')
  32. const materials = (model?.materials || []) as PhysicalMaterial[]
  33. ui.setupPluginUi(dofPlugin)
  34. for (const material of materials) {
  35. ui.appendChild(material.uiConfig)
  36. }
  37. const target = new Vector3(3.8885332252383376, -1.7116614197503317, 5.3296364320040475)
  38. dofPlugin.setFocalPoint(target, false, true)
  39. dofPlugin.enableEdit = true
  40. viewer.scene.mainCamera.target.copy(target)
  41. viewer.scene.mainCamera.position.set(0, 0, -5)
  42. viewer.scene.mainCamera.setDirty()
  43. }
  44. init().then(_testFinish)