threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {
  2. _testFinish,
  3. IObject3D,
  4. Mesh,
  5. PerspectiveCamera2,
  6. PhysicalMaterial,
  7. PlaneGeometry,
  8. PopmotionPlugin,
  9. ProgressivePlugin,
  10. Texture,
  11. ThreeViewer,
  12. VirtualCamerasPlugin,
  13. } from 'threepipe'
  14. async function init() {
  15. const viewer = new ThreeViewer({
  16. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  17. debug: true,
  18. plugins: [new ProgressivePlugin(16)],
  19. })
  20. const virtualCameras = viewer.addPluginSync(VirtualCamerasPlugin)
  21. const popmotion = viewer.addPluginSync(PopmotionPlugin)
  22. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  23. await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  24. autoCenter: true,
  25. autoScale: true,
  26. })
  27. const plane = new Mesh(
  28. new PlaneGeometry(5, 5)
  29. .translate(0, 0, -4),
  30. new PhysicalMaterial({
  31. color: '#ffffff',
  32. })
  33. )
  34. plane.castShadow = false
  35. plane.receiveShadow = true
  36. viewer.scene.addObject(plane)
  37. const camera = new PerspectiveCamera2('', viewer.canvas, false, 45, 1)
  38. camera.position.set(0, 0, 5)
  39. camera.target.set(0, 0.25, 0)
  40. camera.userData.autoLookAtTarget = true
  41. camera.near = 1
  42. camera.far = 10
  43. camera.setDirty()
  44. const vCam = virtualCameras.addCamera(camera)
  45. plane.material.map = vCam.target.texture as Texture
  46. popmotion.animate({
  47. from: 0,
  48. to: 1,
  49. repeat: Infinity,
  50. duration: 6000,
  51. onUpdate: (v)=>{
  52. // Set camera position xz in a circle around the target
  53. const angle = v * Math.PI * 2 + Math.PI / 2
  54. const radius = 5
  55. camera.position.set(Math.cos(angle) * radius, 0, Math.sin(angle) * radius)
  56. camera.setDirty()
  57. viewer.setDirty() // since camera is not in the scene
  58. },
  59. })
  60. }
  61. init().then(_testFinish)