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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import {
  2. _testFinish,
  3. _testStart,
  4. Color, generateUiConfig,
  5. LineGeometry2,
  6. LineMaterial2,
  7. LoadingScreenPlugin,
  8. MeshLine,
  9. PickingPlugin,
  10. ThreeViewer,
  11. } from 'threepipe'
  12. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  13. // Read more about the example - https://threepipe.org/notes/fat-lines
  14. async function init() {
  15. const viewer = new ThreeViewer({
  16. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  17. msaa: true,
  18. plugins: [LoadingScreenPlugin, PickingPlugin],
  19. dropzone: true,
  20. })
  21. viewer.scene.autoNearFarEnabled = false
  22. viewer.scene.backgroundColor = new Color(0x333333)
  23. const spiral = {
  24. radius: 1,
  25. height: 2,
  26. loops: 10,
  27. width: 5,
  28. }
  29. const line = new MeshLine(new LineGeometry2(), new LineMaterial2())
  30. line.material.color = new Color(0xffffff)
  31. line.material.vertexColors = true
  32. line.material.linewidth = 5 // pixels
  33. line.rotateX(Math.PI / 2)
  34. function updateSpiral() {
  35. const {positions, colors} = makeSpiral(spiral.radius, spiral.height, spiral.loops)
  36. line.geometry.setPositions(positions)
  37. line.geometry.setColors(colors)
  38. line.material.linewidth = spiral.width
  39. line.setDirty()
  40. }
  41. updateSpiral()
  42. viewer.scene.addObject(line)
  43. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  44. ui.setupPluginUi(PickingPlugin)
  45. ui.appendChild({
  46. type: 'folder',
  47. label: 'Spiral',
  48. children: generateUiConfig(spiral),
  49. onChange: updateSpiral,
  50. expanded: true,
  51. })
  52. ui.appendChild(line.uiConfig)
  53. }
  54. _testStart()
  55. init().finally(_testFinish)
  56. function makeSpiral(radius = 1, height = 2, loops = 10) {
  57. const positions: number[] = []
  58. const colors: number[] = []
  59. const segments = 1000
  60. const angleStep = Math.PI * 2 * loops / segments
  61. const heightStep = height / segments
  62. for (let i = 0; i <= segments; i++) {
  63. const angle = i * angleStep
  64. const x = radius * Math.cos(angle)
  65. const y = radius * Math.sin(angle)
  66. const z = i * heightStep - height / 2
  67. positions.push(x, y, z)
  68. // Color gradient from blue to red
  69. const colorValue = i / segments
  70. colors.push(colorValue, 0, 1 - colorValue) // RGB
  71. }
  72. return {positions, colors}
  73. }