threepipe
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

script.ts 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {
  2. _testFinish,
  3. Box3B,
  4. IObject3D,
  5. Mesh,
  6. Object3DWidgetsPlugin,
  7. PhysicalMaterial,
  8. PlaneGeometry,
  9. RectAreaLight2,
  10. ThreeViewer,
  11. Vector3,
  12. } from 'threepipe'
  13. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  14. async function init() {
  15. const viewer = new ThreeViewer({
  16. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  17. msaa: true,
  18. dropzone: {
  19. allowedExtensions: ['gltf', 'glb', 'hdr', 'obj', 'fbx', 'bin', 'png', 'jpeg', 'webp', 'jpg', 'exr'],
  20. addOptions: {
  21. disposeSceneObjects: true,
  22. autoSetEnvironment: true, // when hdr/exr is dropped
  23. },
  24. },
  25. plugins: [Object3DWidgetsPlugin],
  26. })
  27. // viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 10))
  28. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/ShadowmappableMesh.glb', {
  29. autoCenter: true,
  30. autoScale: true,
  31. })
  32. const ground = new Mesh(
  33. new PlaneGeometry(100, 100)
  34. .rotateX(-Math.PI / 2)
  35. .translate(0, new Box3B().expandByObject(result!).getSize(new Vector3()).y / -2, 0),
  36. new PhysicalMaterial({
  37. color: '#ffffff',
  38. })
  39. )
  40. viewer.scene.addObject(ground)
  41. const light = viewer.scene.addObject(new RectAreaLight2(0xffffff, 4))
  42. light.position.set(2, 4, 0)
  43. light.lookAt(0, 4, 0)
  44. light.width = 2
  45. light.height = 10
  46. const ui = viewer.addPluginSync(TweakpaneUiPlugin, true)
  47. ui.appendChild(light.uiConfig, {expanded: true})
  48. }
  49. init().then(_testFinish)