threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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