threepipe
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

script.ts 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {
  2. _testFinish, _testStart,
  3. FragmentClippingExtensionPlugin,
  4. IObject3D,
  5. LoadingScreenPlugin,
  6. PhysicalMaterial,
  7. ThreeViewer,
  8. Vector4,
  9. } from 'threepipe'
  10. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  11. async function init() {
  12. const viewer = new ThreeViewer({
  13. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  14. msaa: true,
  15. plugins: [LoadingScreenPlugin],
  16. })
  17. const fragmentClipping = viewer.addPluginSync(FragmentClippingExtensionPlugin)
  18. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  19. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr', {
  20. setBackground: true,
  21. })
  22. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  23. autoCenter: true,
  24. autoScale: true,
  25. })
  26. const model = result?.getObjectByName('node_damagedHelmet_-6514')
  27. const materials = (model?.materials || []) as PhysicalMaterial[]
  28. for (const material of materials) {
  29. FragmentClippingExtensionPlugin.AddFragmentClipping(material, {
  30. clipPosition: new Vector4(0.5, 0.5, 0, 0),
  31. clipParams: new Vector4(0.1, 0.05, 0, 1),
  32. })
  33. // set properties like this or from the UI
  34. // material.userData._fragmentClipping!.clipPosition.set(0, 0, 0, 0)
  35. // material.setDirty()
  36. // Add extra fragment clipping extension ui mapped to this material.
  37. // This is also added inside the material ui by default by the material extension automatically.
  38. const config = material.uiConfig
  39. if (!config) continue
  40. ui.appendChild(fragmentClipping.materialExtension.getUiConfig?.(material), {expanded: true})
  41. ui.appendChild(config)
  42. }
  43. }
  44. _testStart()
  45. init().finally(_testFinish)