threepipe
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {
  2. _testFinish, _testStart,
  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. _testStart()
  45. init().finally(_testFinish)