threepipe
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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