threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plugin-svg-renderer.md 4.3KB

1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ---
  2. prev:
  3. text: '@threepipe/plugin-gaussian-splatting'
  4. link: './plugin-gaussian-splatting'
  5. next:
  6. text: '@threepipe/plugin-3d-tiles-renderer'
  7. link: './plugin-3d-tiles-renderer'
  8. ---
  9. # @threepipe/plugin-svg-renderer
  10. Exports [ThreeSVGRendererPlugin](https://threepipe.org/plugins/svg-renderer/docs/classes/ThreeSVGRendererPlugin.html) and [BasicSVGRendererPlugin](https://threepipe.org/plugins/svg-renderer/docs/classes/BasicSVGRendererPlugin.html) which provide support for rendering the 3d scene as [SVG(Scalable Vector Graphics)](https://developer.mozilla.org/en-US/docs/Web/SVG). The generated SVG is compatible with browser rendering and other software like figma, illustrator etc.
  11. [Example](https://threepipe.org/examples/#three-svg-renderer/) —
  12. [Source Code](https://github.com/repalash/threepipe/blob/master/plugins/svg-renderer/src/index.ts) —
  13. [API Reference](https://threepipe.org/plugins/svg-renderer/docs) —
  14. [GPLv3 License](https://github.com/repalash/threepipe/blob/master/plugins/svg-renderer/LICENSE)
  15. [![NPM Package](https://img.shields.io/npm/v/@threepipe/plugin-network.svg)](https://www.npmjs.com/package/@threepipe/plugin-svg-renderer)
  16. ```bash
  17. npm install @threepipe/plugin-svg-renderer
  18. ```
  19. ::: warning Note
  20. This is still a WIP. API might change a bit
  21. :::
  22. `ThreeSVGRendererPlugin` uses [`three-svg-renderer`](https://github.com/repalash/threepipe/blob/master/plugins/svg-renderer/src/three-svg-renderer), which is a modified version of [three-svg-renderer](https://www.npmjs.com/package/three-svg-renderer) (GPLV3 Licenced).
  23. The plugin renderers meshes in the viewer scene to svg objects by computing polygons and contours of the geometry in view space. Check [LokiResearch/three-svg-renderer](https://github.com/LokiResearch/three-svg-renderer?tab=readme-ov-file#references) for more details.
  24. In the modified version that is used here, support for some types of geometries is added and a rendered image in screen-space is used to create raster fill images for paths along with some other small changes. Check out the [Example](https://threepipe.org/examples/#three-svg-renderer/) for demo. See also [svg-geometry-playground example](https://threepipe.org/examples/#svg-geometry-playground/) for usage with other plugins `PickingPlugin`, `TransformControlsPlugin` and `GeometryGeneratorPlugin`.
  25. Note that this does not support all the features of three.js and may not work with all types of materials and geometries. Check the examples for a list of sample models that do and don't work.
  26. `BasicSVGRendererPlugin` is a sample plugin using [SVGRenderer](https://threejs.org/docs/index.html?q=svg#examples/en/renderers/SVGRenderer) from three.js addons. This renders all triangles in the scene to separate svg paths. Check the three.js docs for more details. Check out the [Example](https://threepipe.org/examples/#basic-svg-renderer/) for demo.
  27. ```typescript
  28. import {ThreeViewer} from 'threepipe'
  29. import {ThreeSVGRendererPlugin} from '@threepipe/plugin-svg-renderer'
  30. const viewer = new ThreeViewer({
  31. ...,
  32. rgbm: false, // this is required
  33. })
  34. const svgRender = viewer.addPluginSync(ThreeSVGRendererPlugin)
  35. svgRender.autoRender = true // automatically render when camera or any object changes.
  36. svgRender.autoMakeSvgObjects = true // automatically create SVG objects for all meshes in the scene.
  37. // svgRender.makeSVGObject(object) // manually create SVG object for an object. (if autoMakeSvgObjects is false)
  38. // Now load or generate any 3d model. Make sure its not very big. And the meshes are optimized.
  39. const model = await viewer.load<IOBject3D>('path/to/file.glb')
  40. // clear the background of the viewer
  41. viewer.scene.backgroundColor = null
  42. viewer.scene.background = null
  43. // disable damping to get better experience.
  44. viewer.scene.mainCamera.controls!.enableDamping = false
  45. // hide the canvas to see the underlying svg node.
  46. // note: do not set the display to none or remove the canvas as OrbitControls and other plugins might still be tracking the canvas.
  47. viewer.canvas.style.opacity = '0'
  48. // 3d pipeline can also be disabled like this if `drawImageFills` is `false` to get better performance. Do this only after loading the model.
  49. // await viewer.doOnce('postFrame') // wait for the first frame to be rendered (for autoScale etc)
  50. // viewer.renderManager.autoBuildPipeline = false
  51. // viewer.renderManager.pipeline = [] // this will disable main viewer rendering
  52. ```