threepipe
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

script.ts 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import {
  2. _testFinish,
  3. CameraViewPlugin,
  4. CanvasSnapshotPlugin,
  5. ChromaticAberrationPlugin,
  6. ClearcoatTintPlugin,
  7. ContactShadowGroundPlugin,
  8. CustomBumpMapPlugin,
  9. DeviceOrientationControlsPlugin,
  10. DropzonePlugin,
  11. EditorViewWidgetPlugin,
  12. FilmicGrainPlugin,
  13. FragmentClippingExtensionPlugin,
  14. FrameFadePlugin,
  15. GBufferPlugin,
  16. getUrlQueryParam,
  17. GLTFAnimationPlugin,
  18. GLTFKHRMaterialVariantsPlugin,
  19. GLTFMeshOptDecodePlugin,
  20. HalfFloatType,
  21. HDRiGroundPlugin,
  22. HemisphereLight,
  23. InteractionPromptPlugin,
  24. KTX2LoadPlugin,
  25. KTXLoadPlugin,
  26. LoadingScreenPlugin,
  27. NoiseBumpMaterialPlugin,
  28. Object3DGeneratorPlugin,
  29. Object3DWidgetsPlugin,
  30. ParallaxMappingPlugin,
  31. PickingPlugin,
  32. PLYLoadPlugin,
  33. PointerLockControlsPlugin, PopmotionPlugin,
  34. ProgressivePlugin,
  35. RenderTargetPreviewPlugin,
  36. Rhino3dmLoadPlugin,
  37. SSAAPlugin,
  38. SSAOPlugin,
  39. STLLoadPlugin,
  40. ThreeFirstPersonControlsPlugin,
  41. ThreeViewer, TransformAnimationPlugin,
  42. TransformControlsPlugin,
  43. UnsignedByteType,
  44. USDZLoadPlugin,
  45. ViewerUiConfigPlugin,
  46. VignettePlugin,
  47. VirtualCamerasPlugin,
  48. } from 'threepipe'
  49. import {GaussianSplattingPlugin} from '@threepipe/plugin-gaussian-splatting'
  50. import {MaterialConfiguratorPlugin, SwitchNodePlugin} from '@threepipe/plugin-configurator'
  51. import {BlendLoadPlugin} from '@threepipe/plugin-blend-importer'
  52. import {extraImportPlugins} from '@threepipe/plugins-extra-importers'
  53. import {AWSClientPlugin} from '@threepipe/plugin-network'
  54. // @ts-expect-error todo fix import
  55. import {BloomPlugin, DepthOfFieldPlugin, SSContactShadowsPlugin, SSReflectionPlugin, TemporalAAPlugin, VelocityBufferPlugin, SSGIPlugin, AnisotropyPlugin} from '@threepipe/webgi-plugins'
  56. async function init() {
  57. const viewer = new ThreeViewer({
  58. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  59. renderScale: 'auto',
  60. msaa: true,
  61. rgbm: true,
  62. zPrepass: false, // set it to true if you only have opaque objects in the scene to get better performance.
  63. dropzone: { // this can also be set to true and configured by getting a reference to the DropzonePlugin
  64. // allowedExtensions: ['gltf', 'glb', 'hdr', 'bin', 'png', 'jpeg', 'webp', 'jpg', 'exr', 'fbx', 'obj'], // only allow these file types. If undefined, all files are allowed.
  65. addOptions: {
  66. disposeSceneObjects: true, // auto dispose of old scene objects
  67. autoSetEnvironment: true, // when hdr is dropped
  68. autoSetBackground: true, // when any image is dropped
  69. autoCenter: true, // auto center the object
  70. autoScale: true, // auto scale according to radius
  71. autoScaleRadius: 2,
  72. // license: 'Imported from dropzone', // Any license to set on imported objects
  73. importConfig: true, // import config from file
  74. },
  75. },
  76. })
  77. await viewer.addPlugins([
  78. LoadingScreenPlugin,
  79. PopmotionPlugin,
  80. new ProgressivePlugin(),
  81. new SSAAPlugin(),
  82. GLTFAnimationPlugin,
  83. TransformAnimationPlugin,
  84. new GBufferPlugin(HalfFloatType, true, true, true),
  85. PickingPlugin,
  86. new TransformControlsPlugin(false),
  87. // OutlinePlugin,
  88. EditorViewWidgetPlugin,
  89. CameraViewPlugin,
  90. ViewerUiConfigPlugin,
  91. ClearcoatTintPlugin,
  92. FragmentClippingExtensionPlugin,
  93. NoiseBumpMaterialPlugin,
  94. CustomBumpMapPlugin,
  95. AnisotropyPlugin,
  96. new ParallaxMappingPlugin(false),
  97. GLTFKHRMaterialVariantsPlugin,
  98. VirtualCamerasPlugin,
  99. // new SceneUiConfigPlugin(), // this is already in ViewerUiPlugin
  100. new RenderTargetPreviewPlugin(false),
  101. new FrameFadePlugin(),
  102. new HDRiGroundPlugin(false, true),
  103. new VignettePlugin(false),
  104. new ChromaticAberrationPlugin(false),
  105. new FilmicGrainPlugin(false),
  106. new SSAOPlugin(UnsignedByteType, 1),
  107. SSReflectionPlugin,
  108. new SSContactShadowsPlugin(false),
  109. new DepthOfFieldPlugin(false),
  110. BloomPlugin,
  111. TemporalAAPlugin,
  112. new VelocityBufferPlugin(UnsignedByteType, false),
  113. new SSGIPlugin(UnsignedByteType, 1, false),
  114. KTX2LoadPlugin,
  115. KTXLoadPlugin,
  116. PLYLoadPlugin,
  117. Rhino3dmLoadPlugin,
  118. STLLoadPlugin,
  119. USDZLoadPlugin,
  120. BlendLoadPlugin,
  121. Object3DWidgetsPlugin,
  122. Object3DGeneratorPlugin,
  123. GaussianSplattingPlugin,
  124. ContactShadowGroundPlugin,
  125. CanvasSnapshotPlugin,
  126. DeviceOrientationControlsPlugin,
  127. PointerLockControlsPlugin,
  128. ThreeFirstPersonControlsPlugin,
  129. InteractionPromptPlugin,
  130. // new MeshOptSimplifyModifierPlugin(false, document.head), // will auto-initialize on first use.
  131. new GLTFMeshOptDecodePlugin(true, document.head),
  132. // new BasicSVGRendererPlugin(false, true),
  133. ...extraImportPlugins,
  134. MaterialConfiguratorPlugin,
  135. SwitchNodePlugin,
  136. AWSClientPlugin,
  137. ])
  138. const hemiLight = viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 5), {addToRoot: true})
  139. hemiLight.name = 'Hemisphere Light'
  140. await viewer.setEnvironmentMap(getUrlQueryParam('env') ?? 'https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  141. const model = getUrlQueryParam('m') || getUrlQueryParam('model')
  142. if (model) {
  143. await viewer.load(model)
  144. const promptDiv = document.getElementById('prompt-div')!
  145. promptDiv.style.display = 'none'
  146. }
  147. const dropzone = viewer.getPlugin(DropzonePlugin)!
  148. dropzone.addEventListener('drop', (e: any) => {
  149. if (!e.assets?.length) return // no assets imported
  150. console.log('Dropped Event:', e)
  151. const promptDiv = document.getElementById('prompt-div')!
  152. promptDiv.style.display = 'none'
  153. })
  154. }
  155. init().finally(_testFinish)