threepipe
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

script.ts 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {
  2. _testFinish, _testStart,
  3. Box3B,
  4. IObject3D,
  5. LoadingScreenPlugin,
  6. Mesh,
  7. Object3DWidgetsPlugin,
  8. PCFSoftShadowMap,
  9. PhysicalMaterial,
  10. PlaneGeometry,
  11. RenderTargetPreviewPlugin,
  12. SpotLight2,
  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 SpotLight2(0xffffff, 10))
  47. light.position.set(2, 2, 2)
  48. light.lookAt(0, 0, 0)
  49. light.angle = 0.5
  50. light.penumbra = 0.2
  51. light.distance = 5
  52. light.decay = 0.5
  53. light.castShadow = true
  54. light.shadowMapSize.setScalar(1024)
  55. light.shadowNear = 0.1
  56. light.shadowFar = 10
  57. light.shadowAspect = 1
  58. light.shadowFov = 45
  59. viewer.renderManager.renderer.shadowMap.type = PCFSoftShadowMap
  60. const rt = viewer.addPluginSync(RenderTargetPreviewPlugin)
  61. rt.addTarget(()=>light.shadow.map || undefined, 'shadow', true, true, true)
  62. const ui = viewer.addPluginSync(TweakpaneUiPlugin, true)
  63. ui.appendChild(light.uiConfig, {expanded: true})
  64. }
  65. _testStart()
  66. init().finally(_testFinish)