threepipe
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

script.ts 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import {
  2. _testFinish,
  3. BoxGeometry,
  4. Color,
  5. LoadingScreenPlugin,
  6. Mesh,
  7. PhysicalMaterial,
  8. PopmotionPlugin,
  9. ThreeViewer,
  10. Vector3,
  11. } from 'threepipe'
  12. import {createSimpleButtons} from '../examples-utils/simple-bottom-buttons.js'
  13. async function init() {
  14. const viewer = new ThreeViewer({
  15. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  16. renderScale: 'auto',
  17. plugins: [LoadingScreenPlugin],
  18. })
  19. const popmotion = viewer.addPluginSync(PopmotionPlugin)
  20. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  21. const cube = viewer.scene.addObject(new Mesh(
  22. new BoxGeometry(1, 1, 1),
  23. new PhysicalMaterial({color: 0xff0000})
  24. ))
  25. let isMovedUp = false
  26. createSimpleButtons({
  27. ['Move Up/Down']: async(btn) => {
  28. btn.disabled = true
  29. await popmotion.animateTargetAsync(cube, 'position', {
  30. to: cube.position.clone().add(new Vector3(0, isMovedUp ? -1 : 1, 0)),
  31. duration: 500, // ms
  32. onComplete: () => isMovedUp = !isMovedUp,
  33. onUpdate: () => cube.setDirty(),
  34. })
  35. btn.disabled = false
  36. },
  37. ['Rotate +90deg']: async(btn) => {
  38. btn.disabled = true
  39. await popmotion.animateAsync({
  40. from: cube.rotation.y,
  41. to: cube.rotation.y + Math.PI / 2,
  42. duration: 500,
  43. onUpdate: (v) => {
  44. cube.rotation.y = v
  45. cube.setDirty()
  46. },
  47. })
  48. btn.disabled = false
  49. },
  50. ['Change Color']: async(btn)=>{
  51. btn.disabled = true
  52. await popmotion.animateAsync({
  53. from: '#' + cube.material.color.getHexString(),
  54. to: '#' + new Color().setHSL(Math.random(), 1, 0.5).getHexString(),
  55. duration: 500,
  56. onUpdate: (v) => {
  57. cube.material.color.set(v)
  58. cube.material.setDirty()
  59. },
  60. })
  61. btn.disabled = false
  62. },
  63. })
  64. }
  65. init().finally(_testFinish)