threepipe
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

script.ts 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {
  2. _testFinish,
  3. Box3B,
  4. DirectionalLight2,
  5. IObject3D,
  6. LoadingScreenPlugin,
  7. Mesh,
  8. Object3DWidgetsPlugin,
  9. PCFSoftShadowMap,
  10. PhysicalMaterial,
  11. PlaneGeometry,
  12. RenderTargetPreviewPlugin,
  13. ThreeViewer,
  14. Vector3,
  15. } from 'threepipe'
  16. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  17. async function init() {
  18. const viewer = new ThreeViewer({
  19. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  20. msaa: true,
  21. dropzone: {
  22. allowedExtensions: ['gltf', 'glb', 'hdr', 'obj', 'fbx', 'bin', 'png', 'jpeg', 'webp', 'jpg', 'exr'],
  23. addOptions: {
  24. disposeSceneObjects: true,
  25. autoSetEnvironment: true, // when hdr/exr is dropped
  26. },
  27. },
  28. plugins: [Object3DWidgetsPlugin, LoadingScreenPlugin],
  29. })
  30. // viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 10))
  31. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/fbx/Samba Dancing.fbx', {
  32. autoCenter: true,
  33. autoScale: true,
  34. })
  35. const ground = new Mesh(
  36. new PlaneGeometry(100, 100)
  37. .rotateX(-Math.PI / 2)
  38. .translate(0, new Box3B().expandByObject(result!).getSize(new Vector3()).y / -2, 0),
  39. new PhysicalMaterial({
  40. color: '#ffffff',
  41. })
  42. )
  43. ground.castShadow = false
  44. ground.receiveShadow = true
  45. viewer.scene.addObject(ground)
  46. const light = viewer.scene.addObject(new DirectionalLight2(0xffffff, 4))
  47. light.position.set(2, 2, 2)
  48. light.lookAt(0, 0, 0)
  49. light.castShadow = true
  50. light.shadowMapSize.setScalar(1024)
  51. light.shadowNear = 0.1
  52. light.shadowFar = 10
  53. light.shadowFrustum = 4
  54. viewer.renderManager.renderer.shadowMap.type = PCFSoftShadowMap
  55. const rt = viewer.addPluginSync(RenderTargetPreviewPlugin)
  56. rt.addTarget(()=>light.shadow.map || undefined, 'shadow', true, true, true)
  57. const ui = viewer.addPluginSync(TweakpaneUiPlugin, true)
  58. ui.appendChild(light.uiConfig, {expanded: true})
  59. }
  60. init().finally(_testFinish)