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

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