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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {
  2. _testFinish,
  3. ClearcoatTintPlugin,
  4. IObject3D,
  5. LoadingScreenPlugin,
  6. PhysicalMaterial,
  7. ThreeViewer,
  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. plugins: [LoadingScreenPlugin],
  15. })
  16. const clearcoatTint = viewer.addPluginSync(ClearcoatTintPlugin)
  17. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  18. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr', {
  19. setBackground: true,
  20. })
  21. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  22. autoCenter: true,
  23. autoScale: true,
  24. })
  25. const model = result?.getObjectByName('node_damagedHelmet_-6514')
  26. const materials = (model?.materials || []) as PhysicalMaterial[]
  27. for (const material of materials) {
  28. material.clearcoat = 1
  29. // add initial properties
  30. ClearcoatTintPlugin.AddClearcoatTint(material, {
  31. tintColor: '#ff0000',
  32. thickness: 1,
  33. })
  34. // set properties like this or from the UI
  35. // material.userData._clearcoatTint!.tintColor = '#ff0000'
  36. // Add extra clearcoat tint 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(clearcoatTint.materialExtension.getUiConfig?.(material), {expanded: true})
  41. ui.appendChild(config)
  42. }
  43. }
  44. init().finally(_testFinish)