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.8KB

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