threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {_testFinish, _testStart, CameraViewPlugin, HDRiGroundPlugin, LoadingScreenPlugin, ThreeViewer} from 'threepipe'
  2. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  3. async function init() {
  4. const viewer = new ThreeViewer({
  5. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  6. msaa: true,
  7. dropzone: {
  8. allowedExtensions: ['gltf', 'glb', 'hdr', 'bin', 'png', 'jpeg', 'webp', 'jpg', 'exr'],
  9. addOptions: {
  10. disposeSceneObjects: true,
  11. autoSetEnvironment: true, // when hdr is dropped
  12. autoSetBackground: true,
  13. },
  14. },
  15. plugins: [CameraViewPlugin, LoadingScreenPlugin],
  16. })
  17. const hdriGround = viewer.addPluginSync(HDRiGroundPlugin)
  18. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr', {
  19. setBackground: true,
  20. })
  21. await viewer.load('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  22. autoCenter: true,
  23. autoScale: true,
  24. autoScaleRadius: 10,
  25. })
  26. viewer.scene.background = 'environment' // this is not really required since setBackground is also set to true above
  27. hdriGround.worldRadius = 50
  28. hdriGround.tripodHeight = 10
  29. const bounds = viewer.scene.getBounds(true, true)
  30. bounds.getCenter(hdriGround.originPosition)
  31. hdriGround.originPosition.y -= (bounds.max.y - bounds.min.y) / 2
  32. hdriGround.enabled = true
  33. console.log(hdriGround)
  34. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  35. ui.setupPluginUi(HDRiGroundPlugin)
  36. await viewer.fitToView(undefined, 2.5)
  37. }
  38. _testStart()
  39. init().finally(_testFinish)