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