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

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