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.

script.ts 1.7KB

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