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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import {
  2. _testFinish, _testStart,
  3. DropzonePlugin,
  4. EditorViewWidgetPlugin,
  5. GBufferPlugin,
  6. GLTFAnimationPlugin,
  7. IObject3D,
  8. LoadingScreenPlugin,
  9. PickingPlugin,
  10. ThreeViewer,
  11. TransformControlsPlugin,
  12. } from 'threepipe'
  13. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  14. import {ThreeSVGRendererPlugin} from '@threepipe/plugin-svg-renderer'
  15. async function init() {
  16. const viewer = new ThreeViewer({
  17. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  18. msaa: false,
  19. rgbm: false,
  20. // zPrepass: true,
  21. tonemap: false,
  22. plugins: [GBufferPlugin, PickingPlugin, TransformControlsPlugin, LoadingScreenPlugin], /* TransformControlsPlugin */ // todo: transform controls doesnt work when selected object is in a parent.
  23. dropzone: {
  24. autoAdd: true,
  25. addOptions: {
  26. disposeSceneObjects: true,
  27. },
  28. },
  29. })
  30. viewer.addPluginSync(new EditorViewWidgetPlugin('bottom-left', 128))
  31. viewer.renderEnabled = false
  32. viewer.addPluginSync(new ThreeSVGRendererPlugin(true))
  33. viewer.addPluginSync(GLTFAnimationPlugin)// .autoplayOnLoad = true
  34. // viewer.scene.addObject(new DirectionalLight2(0xffffff, 1).rotateZ(0.5).rotateX(0.5))
  35. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  36. const models = [
  37. // working/sort of working
  38. 'https://threejs.org/examples/models/gltf/Horse.glb',
  39. 'https://demo-assets.pixotronics.com/pixo/gltf/jewlr1.glb',
  40. 'https://demo-assets.pixotronics.com/pixo/gltf/engagement_ring.glb',
  41. 'https://threejs.org/examples/models/gltf/Flamingo.glb',
  42. 'https://threejs.org/examples/models/gltf/ShadowmappableMesh.glb',
  43. 'https://threejs.org/examples/models/gltf/BoomBox.glb',
  44. 'https://cdn.jsdelivr.net/gh/LokiResearch/three-svg-renderer/resources/pig.gltf',
  45. 'https://cdn.jsdelivr.net/gh/LokiResearch/three-svg-renderer/resources/vincent.gltf', // https://studio.blender.org/characters/5718a967c379cf04929a4247/v1/
  46. 'https://threejs.org/examples/models/fbx/Samba Dancing.fbx',
  47. 'https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf',
  48. 'https://threejs.org/examples/models/obj/male02/male02.obj',
  49. 'https://threejs.org/examples/models/gltf/kira.glb', // slow
  50. // to test
  51. 'https://cdn.jsdelivr.net/gh/KhronosGroup/glTF-Sample-Assets/Models/WaterBottle/glTF-Draco/WaterBottle.gltf',
  52. 'https://cdn.jsdelivr.net/gh/KhronosGroup/glTF-Sample-Assets/Models/MaterialsVariantsShoe/glTF/MaterialsVariantsShoe.gltf',
  53. // not working/very slow
  54. 'https://threejs.org/examples/models/gltf/Soldier.glb',
  55. 'https://threejs.org/examples/models/gltf/LittlestTokyo.glb',
  56. 'https://threejs.org/examples/models/gltf/ferrari.glb',
  57. ]
  58. await viewer.load<IObject3D>(models[0], {
  59. autoCenter: true,
  60. autoScale: true,
  61. })
  62. viewer.scene.backgroundColor = null
  63. viewer.scene.background = null
  64. viewer.scene.mainCamera.controls!.enableDamping = false
  65. viewer.renderEnabled = true
  66. // waiting because we need to render pipeline once to autoscale?
  67. await viewer.doOnce('postFrame')
  68. // optionally disable rendering. but its required if drawImageFills option is enabled
  69. // viewer.renderManager.autoBuildPipeline = false
  70. // viewer.renderManager.pipeline = [] // this will disable main viewer rendering
  71. // make canvas transparent to hide it. We still need pointer events so dont set display to none
  72. // viewer.canvas.style.opacity = '0'
  73. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  74. ui.setupPlugins(ThreeSVGRendererPlugin)
  75. ui.setupPlugins(GLTFAnimationPlugin, PickingPlugin, DropzonePlugin)
  76. }
  77. _testStart()
  78. init().finally(_testFinish)