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 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {
  2. _testFinish,
  3. Box3B,
  4. DirectionalLight,
  5. IObject3D,
  6. Mesh,
  7. PCFSoftShadowMap,
  8. PhysicalMaterial,
  9. PlaneGeometry,
  10. RenderTargetPreviewPlugin,
  11. ThreeViewer,
  12. Vector3,
  13. } from 'threepipe'
  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. })
  26. // viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 10))
  27. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/fbx/Samba Dancing.fbx', {
  28. autoCenter: true,
  29. autoScale: true,
  30. })
  31. const ground = new Mesh(
  32. new PlaneGeometry(100, 100)
  33. .rotateX(-Math.PI / 2)
  34. .translate(0, new Box3B().expandByObject(result!).getSize(new Vector3()).y / -2, 0),
  35. new PhysicalMaterial({
  36. color: '#ffffff',
  37. })
  38. )
  39. ground.castShadow = false
  40. ground.receiveShadow = true
  41. viewer.scene.addObject(ground)
  42. const directionalLight = viewer.scene.addObject(new DirectionalLight(0xffffff, 4))
  43. directionalLight.position.set(2, 2, 2)
  44. directionalLight.lookAt(0, 0, 0)
  45. directionalLight.castShadow = true
  46. directionalLight.shadow.mapSize.setScalar(1024)
  47. directionalLight.shadow.camera.near = 0.1
  48. directionalLight.shadow.camera.far = 10
  49. directionalLight.shadow.camera.top = 2
  50. directionalLight.shadow.camera.bottom = -2
  51. directionalLight.shadow.camera.left = -2
  52. directionalLight.shadow.camera.right = 2
  53. viewer.renderManager.renderer.shadowMap.type = PCFSoftShadowMap
  54. const rt = viewer.addPluginSync(RenderTargetPreviewPlugin)
  55. rt.addTarget(()=>directionalLight.shadow.map || undefined, 'shadow', true, true, true)
  56. }
  57. init().then(_testFinish)