threepipe
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

script.ts 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {
  2. _testFinish, _testStart,
  3. BufferGeometry,
  4. BufferGeometry2,
  5. Color,
  6. GLTFLoader2,
  7. IMaterial,
  8. IObject3D,
  9. LineSegmentsGeometry,
  10. LineSegmentsGeometry2,
  11. LoadingScreenPlugin,
  12. Object3D,
  13. ThreeViewer,
  14. } from 'threepipe'
  15. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  16. // Read more about the example - https://threepipe.org/notes/gltf-mesh-lines
  17. async function init() {
  18. const viewer = new ThreeViewer({
  19. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  20. msaa: true,
  21. plugins: [LoadingScreenPlugin],
  22. dropzone: true,
  23. })
  24. viewer.scene.autoNearFarEnabled = false
  25. GLTFLoader2.UseMeshLines = true
  26. viewer.scene.backgroundColor = new Color(0x333333)
  27. // await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  28. const obj1 = await viewer.load<IObject3D>('https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Assets/refs/heads/main/Models/MeshPrimitiveModes/glTF/MeshPrimitiveModes.gltf', {
  29. autoScale: true,
  30. autoCenter: true,
  31. useMeshLines: true,
  32. })
  33. const obj2 = await viewer.load<IObject3D>('https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Assets/refs/heads/main/Models/MeshPrimitiveModes/glTF/MeshPrimitiveModes.gltf', {
  34. autoScale: true,
  35. autoCenter: true,
  36. useMeshLines: false,
  37. })
  38. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  39. const mats: IMaterial[] = []
  40. const o1: IObject3D[] = []
  41. const o2: IObject3D[] = []
  42. const p1 = viewer.scene.addObject(new Object3D()).translateY(0.75)
  43. const p2 = viewer.scene.addObject(new Object3D()).translateY(-0.75)
  44. p1.scale.setScalar(0.6)
  45. p2.scale.setScalar(0.6)
  46. obj1?.traverse(o=>{
  47. if (o.materials?.[0].isLineMaterial) {
  48. mats.push(o.materials[0])
  49. o1.push(o)
  50. }
  51. })
  52. obj2?.traverse(o=>{
  53. if (o.materials?.[0].isUnlitLineMaterial) {
  54. mats.push(o.materials[0])
  55. o2.push(o)
  56. }
  57. })
  58. o1.forEach(o=>p1.add(o))
  59. o2.forEach(o=>p2.add(o))
  60. obj1?.dispose(true)
  61. obj2?.dispose(true)
  62. mats.map(m=>{
  63. if (!m.appliedMeshes.size) return
  64. m.linewidth = 10
  65. ui.appendChild(m.uiConfig)
  66. })
  67. console.log(LineSegmentsGeometry)
  68. console.log(LineSegmentsGeometry2)
  69. console.log(BufferGeometry)
  70. console.log(BufferGeometry2)
  71. }
  72. _testStart()
  73. init().finally(_testFinish)