threepipe
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

script.ts 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {
  2. _testFinish,
  3. Box3B,
  4. DirectionalLight2,
  5. IObject3D,
  6. Mesh,
  7. Object3DWidgetsPlugin,
  8. PCFSoftShadowMap,
  9. PhysicalMaterial,
  10. PlaneGeometry,
  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 DirectionalLight2(0xffffff, 4))
  46. light.position.set(2, 2, 2)
  47. light.lookAt(0, 0, 0)
  48. light.castShadow = true
  49. light.shadow.mapSize.setScalar(1024)
  50. light.shadow.camera.near = 0.1
  51. light.shadow.camera.far = 10
  52. light.shadow.camera.top = 2
  53. light.shadow.camera.bottom = -2
  54. light.shadow.camera.left = -2
  55. light.shadow.camera.right = 2
  56. viewer.renderManager.renderer.shadowMap.type = PCFSoftShadowMap
  57. const rt = viewer.addPluginSync(RenderTargetPreviewPlugin)
  58. rt.addTarget(()=>light.shadow.map || undefined, 'shadow', true, true, true)
  59. const ui = viewer.addPluginSync(TweakpaneUiPlugin, true)
  60. ui.appendChild(light.uiConfig, {expanded: true})
  61. }
  62. init().finally(_testFinish)