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

gltf-mesh-lines.md 3.2KB

11 месяцев назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ---
  2. prev:
  3. text: 'Fat Lines'
  4. link: './fat-lines'
  5. next:
  6. text: 'Setting Background Color and Images'
  7. link: './scene-background'
  8. aside: false
  9. ---
  10. # GLTF Mesh Lines: Fat Lines in glTF
  11. [GLTF Mesh Lines Example](https://threepipe.org/examples/#gltf-mesh-lines/)
  12. <iframe src="https://threepipe.org/examples/gltf-mesh-lines/" style="width:100%;min-height:600px;border:none;" loading="lazy" title="GLTF Mesh Lines Example"></iframe>
  13. See Also: [Fat Lines Example](https://threepipe.org/examples/#fat-lines/)
  14. See Also: [Fat Line Spiral Example](https://threepipe.org/examples/#fat-line-spiral/)
  15. If you've ever tried to render thick ("fat") lines in three.js, especially when importing models from GLTF files, you know it can be surprisingly tricky. By default, three.js only supports 1-pixel wide lines due to WebGL limitations. This makes it difficult to achieve visually appealing, stylized, or technical line renderings directly from imported models.
  16. The standard `THREE.Line` and `THREE.LineSegments` classes rely on basic WebGL line rendering, which is limited to a width of 1 pixel on most platforms. As a result, creating thick lines for wireframes, outlines, or technical illustrations is not possible out of the box.
  17. To work around this, three.js provides the [Line2, LineMaterial](https://threejs.org/docs/#examples/en/lines/Line2) classes in three.js addons.
  18. These render lines as thin meshes, allowing for customizable widths, colors, and other properties.
  19. The `threepipe` framework extends this further by providing an option to automatically use these advanced line types for all lines imported from GLTF files.
  20. You can enable this feature globally by setting:
  21. ```ts
  22. GLTFLoader2.UseMeshLines = true;
  23. ```
  24. ::: danger WARNING
  25. Lines imported this way may not export correctly when using the glTF exporter, as the mesh-based lines are not standard GLTF lines. This may change in later versions of three.js or threepipe.
  26. Only enable the feature when using `threepipe` as a viewer.
  27. :::
  28. Once the feature is enabled, glTF files with lines will be imported using `Line2` and `LineMaterial2` instead of the default line classes.
  29. This can be controlled per-glTF file during load with the `useMeshLines` option:
  30. ```ts
  31. const obj = await viewer.load('model.gltf', {
  32. useMeshLines: false,
  33. });
  34. ```
  35. When enabled, all lines in the imported GLTF will use `Line2`/`LineMaterial2`, allowing you to set properties like `linewidth` (yes, it's all lowercase)
  36. ```ts
  37. material.linewidth = 10;
  38. ```
  39. > **Note:** The resolution of the line is set automatically based on the render size, so `linewidth` is always in pixels. If you want the line width to attenuate with distance (i.e., be in world units), you can set the `worldUnits` flag on the material to `true`.
  40. ## API Documentation
  41. - `MeshLine` - https://threepipe.org/docs/classes/MeshLine.html
  42. - `MeshLineSegments` - https://threepipe.org/docs/classes/MeshLineSegments.html
  43. - `LineMaterial2`/`MeshLineMaterial` - https://threepipe.org/docs/classes/LineMaterial2.html
  44. - `GLTFLoader2` - https://threepipe.org/docs/classes/GLTFLoader2.html
  45. - three.js `LineMaterial` - https://threejs.org/docs/?q=line#examples/en/lines/LineMaterial
  46. - three.js `Line2` - https://threejs.org/docs/?q=line#examples/en/lines/Line2