threepipe
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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,
  34. ProgressivePlugin,
  35. RenderTargetPreviewPlugin,
  36. Rhino3dmLoadPlugin,
  37. SSAAPlugin,
  38. SSAOPlugin,
  39. STLLoadPlugin,
  40. ThreeFirstPersonControlsPlugin,
  41. ThreeViewer,
  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. async function init() {
  55. const viewer = new ThreeViewer({
  56. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  57. renderScale: 'auto',
  58. msaa: true,
  59. rgbm: true,
  60. zPrepass: false, // set it to true if you only have opaque objects in the scene to get better performance.
  61. dropzone: { // this can also be set to true and configured by getting a reference to the DropzonePlugin
  62. // allowedExtensions: ['gltf', 'glb', 'hdr', 'bin', 'png', 'jpeg', 'webp', 'jpg', 'exr', 'fbx', 'obj'], // only allow these file types. If undefined, all files are allowed.
  63. addOptions: {
  64. disposeSceneObjects: true, // auto dispose of old scene objects
  65. autoSetEnvironment: true, // when hdr is dropped
  66. autoSetBackground: true, // when any image is dropped
  67. autoCenter: true, // auto center the object
  68. autoScale: true, // auto scale according to radius
  69. autoScaleRadius: 2,
  70. // license: 'Imported from dropzone', // Any license to set on imported objects
  71. importConfig: true, // import config from file
  72. },
  73. },
  74. })
  75. await viewer.addPlugins([
  76. LoadingScreenPlugin,
  77. new ProgressivePlugin(),
  78. new SSAAPlugin(),
  79. GLTFAnimationPlugin,
  80. PickingPlugin,
  81. new TransformControlsPlugin(false),
  82. EditorViewWidgetPlugin,
  83. CameraViewPlugin,
  84. ViewerUiConfigPlugin,
  85. ClearcoatTintPlugin,
  86. FragmentClippingExtensionPlugin,
  87. NoiseBumpMaterialPlugin,
  88. CustomBumpMapPlugin,
  89. new ParallaxMappingPlugin(false),
  90. GLTFKHRMaterialVariantsPlugin,
  91. VirtualCamerasPlugin,
  92. // new SceneUiConfigPlugin(), // this is already in ViewerUiPlugin
  93. new GBufferPlugin(HalfFloatType, true, true, true),
  94. // new DepthBufferPlugin(HalfFloatType, false, false),
  95. // new NormalBufferPlugin(HalfFloatType, false),
  96. new RenderTargetPreviewPlugin(false),
  97. new FrameFadePlugin(),
  98. new HDRiGroundPlugin(false, true),
  99. new VignettePlugin(false),
  100. new ChromaticAberrationPlugin(false),
  101. new FilmicGrainPlugin(false),
  102. new SSAOPlugin(UnsignedByteType, 1),
  103. KTX2LoadPlugin,
  104. KTXLoadPlugin,
  105. PLYLoadPlugin,
  106. Rhino3dmLoadPlugin,
  107. STLLoadPlugin,
  108. USDZLoadPlugin,
  109. BlendLoadPlugin,
  110. Object3DWidgetsPlugin,
  111. Object3DGeneratorPlugin,
  112. GaussianSplattingPlugin,
  113. ContactShadowGroundPlugin,
  114. CanvasSnapshotPlugin,
  115. DeviceOrientationControlsPlugin,
  116. PointerLockControlsPlugin,
  117. ThreeFirstPersonControlsPlugin,
  118. InteractionPromptPlugin,
  119. // new MeshOptSimplifyModifierPlugin(false, document.head), // will auto-initialize on first use.
  120. new GLTFMeshOptDecodePlugin(true, document.head),
  121. // new BasicSVGRendererPlugin(false, true),
  122. ...extraImportPlugins,
  123. MaterialConfiguratorPlugin,
  124. SwitchNodePlugin,
  125. AWSClientPlugin,
  126. ])
  127. const hemiLight = viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 5), {addToRoot: true})
  128. hemiLight.name = 'Hemisphere Light'
  129. await viewer.setEnvironmentMap(getUrlQueryParam('env') ?? 'https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  130. const model = getUrlQueryParam('m') || getUrlQueryParam('model')
  131. if (model) {
  132. await viewer.load(model)
  133. const promptDiv = document.getElementById('prompt-div')!
  134. promptDiv.style.display = 'none'
  135. }
  136. const dropzone = viewer.getPlugin(DropzonePlugin)!
  137. dropzone.addEventListener('drop', (e: any) => {
  138. if (!e.assets?.length) return // no assets imported
  139. console.log('Dropped Event:', e)
  140. const promptDiv = document.getElementById('prompt-div')!
  141. promptDiv.style.display = 'none'
  142. })
  143. }
  144. init().finally(_testFinish)