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 5.4KB

1 개월 전
1 개월 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import {
  2. _testFinish,
  3. _testStart,
  4. IObject3D,
  5. LoadingScreenPlugin,
  6. PhysicalMaterial,
  7. SSAAPlugin,
  8. ThreeViewer,
  9. } from 'threepipe'
  10. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  11. // @ts-expect-error todo fix
  12. import {BloomPlugin, TemporalAAPlugin} from '@threepipe/webgi-plugins'
  13. async function init() {
  14. const viewer = new ThreeViewer({
  15. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  16. debug: true,
  17. msaa: false,
  18. rgbm: false,
  19. zPrepass: false,
  20. renderScale: 1,
  21. // rgbm: false,
  22. maxHDRIntensity: 8,
  23. dropzone: {
  24. addOptions: {
  25. disposeSceneObjects: true,
  26. },
  27. },
  28. plugins: [LoadingScreenPlugin, SSAAPlugin, TemporalAAPlugin],
  29. })
  30. const bloom = viewer.addPluginSync(BloomPlugin)
  31. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  32. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr', {
  33. setBackground: true,
  34. })
  35. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  36. autoCenter: true,
  37. autoScale: true,
  38. })
  39. const model = result?.getObjectByName('node_damagedHelmet_-6514')
  40. const ms = viewer.assetManager.materials.getAllMaterials()
  41. // viewer.assetManager.materials.exportMaterial(ms[0])
  42. console.log(ms)
  43. const materail = new PhysicalMaterial({
  44. 'metadata': {
  45. 'version': 4.6,
  46. 'type': 'Material',
  47. 'generator': 'Material.toJSON',
  48. },
  49. 'uuid': '82d03dfe-a6b8-4d10-94bb-002435fb11af',
  50. 'type': 'MeshStandardMaterial2',
  51. 'name': 'black',
  52. 'color': 13355979,
  53. 'roughness': 0.711963684287597,
  54. 'metalness': 0.5432713428027529,
  55. 'sheen': 0,
  56. 'sheenColor': 0,
  57. 'sheenRoughness': 1,
  58. 'emissive': 0,
  59. 'specularIntensity': 1,
  60. 'specularColor': 16777215,
  61. 'clearcoat': 0,
  62. 'clearcoatRoughness': 0,
  63. 'iridescence': 0,
  64. 'iridescenceIOR': 1.3,
  65. 'iridescenceThicknessRange': [
  66. 100,
  67. 400,
  68. ],
  69. 'anisotropy': 0,
  70. 'anisotropyRotation': 0,
  71. 'map': '2006c0db-c059-438d-baf4-ee6b89095f22',
  72. 'bumpMap': '2006c0db-c059-438d-baf4-ee6b89095f22',
  73. 'bumpScale': 0.009999999999999981,
  74. 'roughnessMap': '2006c0db-c059-438d-baf4-ee6b89095f22',
  75. 'envMapIntensity': 1,
  76. 'reflectivity': 0.49999999999999983,
  77. 'transmission': 0,
  78. 'thickness': 0,
  79. 'attenuationDistance': 0,
  80. 'attenuationColor': 16777215,
  81. 'side': 2,
  82. 'depthFunc': 3,
  83. 'depthTest': true,
  84. 'depthWrite': true,
  85. 'colorWrite': true,
  86. 'stencilWrite': false,
  87. 'stencilWriteMask': 255,
  88. 'stencilFunc': 519,
  89. 'stencilRef': 0,
  90. 'stencilFuncMask': 255,
  91. 'stencilFail': 7680,
  92. 'stencilZFail': 7680,
  93. 'stencilZPass': 7680,
  94. 'fog': false,
  95. 'userData': {
  96. 'gltfExtensions': {},
  97. '_9c068557-570d-46f4-9c6d-f106319ed7f1_version': 66,
  98. '_triplanarMapping': {
  99. 'enable': true,
  100. 'scaleFactor': 2.6021818714306635,
  101. 'blendFactor': 1,
  102. 'offsetFactor': 0,
  103. },
  104. 'uuid': '82d03dfe-a6b8-4d10-94bb-002435fb11af',
  105. },
  106. 'textures': [
  107. {
  108. 'metadata': {
  109. 'version': 4.6,
  110. 'type': 'Texture',
  111. 'generator': 'Texture.toJSON',
  112. },
  113. 'uuid': '2006c0db-c059-438d-baf4-ee6b89095f22',
  114. 'name': '',
  115. 'image': '45a746eb-0369-414b-bc32-359ea8296101',
  116. 'mapping': 300,
  117. 'channel': 0,
  118. 'repeat': [
  119. 1,
  120. 1,
  121. ],
  122. 'offset': [
  123. 0,
  124. 0,
  125. ],
  126. 'center': [
  127. 0,
  128. 0,
  129. ],
  130. 'rotation': 0,
  131. 'wrap': [
  132. 1000,
  133. 1000,
  134. ],
  135. 'format': 1023,
  136. 'internalFormat': null,
  137. 'type': 1009,
  138. 'colorSpace': 'srgb-linear',
  139. 'encoding': 3000,
  140. 'minFilter': 1008,
  141. 'magFilter': 1006,
  142. 'anisotropy': 1,
  143. 'flipY': false,
  144. 'generateMipmaps': true,
  145. 'premultiplyAlpha': false,
  146. 'unpackAlignment': 4,
  147. 'userData': {
  148. 'rootPath': '/files/source/carbon_2_91262f99f0.jpg',
  149. },
  150. },
  151. ],
  152. 'images': [],
  153. })
  154. // viewer.assetManager.materials.exportMaterial(materail)
  155. console.log(materail)
  156. // viewer.assetManager.materials.applyMaterial(materail, 'Material_MR')
  157. const materials = (model?.materials || []) as PhysicalMaterial[]
  158. ui.setupPluginUi(bloom)
  159. for (const material of materials) {
  160. ui.appendChild(material.uiConfig)
  161. }
  162. bloom.pass!.intensity = 3
  163. bloom.pass!.threshold = 1
  164. // viewer.scene.background = null
  165. // bloom.pass!.bloomDebug = true
  166. }
  167. _testStart()
  168. init().then(_testFinish)