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.

plugin-svg-renderer.md 4.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ---
  2. prev:
  3. text: '@threepipe/plugin-gaussian-splatting'
  4. link: './plugin-gaussian-splatting'
  5. next: false
  6. ---
  7. # @threepipe/plugin-svg-renderer
  8. 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.
  9. [Example](https://threepipe.org/examples/#three-svg-renderer/) —
  10. [Source Code](https://github.com/repalash/threepipe/blob/master/plugins/svg-renderer/src/index.ts) —
  11. [API Reference](https://threepipe.org/plugins/svg-renderer/docs) —
  12. [GPLv3 License](https://github.com/repalash/threepipe/blob/master/plugins/svg-renderer/LICENSE)
  13. [![NPM Package](https://img.shields.io/npm/v/@threepipe/plugin-network.svg)](https://www.npmjs.com/package/@threepipe/plugin-svg-renderer)
  14. ```bash
  15. npm install @threepipe/plugin-svg-renderer
  16. ```
  17. ::: warning Note
  18. This is still a WIP. API might change a bit
  19. :::
  20. `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).
  21. 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.
  22. 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`.
  23. 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.
  24. `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.
  25. ```typescript
  26. import {ThreeViewer} from 'threepipe'
  27. import {ThreeSVGRendererPlugin} from '@threepipe/plugin-svg-renderer'
  28. const viewer = new ThreeViewer({
  29. ...,
  30. rgbm: false, // this is required
  31. })
  32. const svgRender = viewer.addPluginSync(ThreeSVGRendererPlugin)
  33. svgRender.autoRender = true // automatically render when camera or any object changes.
  34. svgRender.autoMakeSvgObjects = true // automatically create SVG objects for all meshes in the scene.
  35. // svgRender.makeSVGObject(object) // manually create SVG object for an object. (if autoMakeSvgObjects is false)
  36. // Now load or generate any 3d model. Make sure its not very big. And the meshes are optimized.
  37. const model = await viewer.load<IOBject3D>('path/to/file.glb')
  38. // clear the background of the viewer
  39. viewer.scene.backgroundColor = null
  40. viewer.scene.background = null
  41. // disable damping to get better experience.
  42. viewer.scene.mainCamera.controls!.enableDamping = false
  43. // hide the canvas to see the underlying svg node.
  44. // note: do not set the display to none or remove the canvas as OrbitControls and other plugins might still be tracking the canvas.
  45. viewer.canvas.style.opacity = '0'
  46. // 3d pipeline can also be disabled like this if `drawImageFills` is `false` to get better performance. Do this only after loading the model.
  47. // await viewer.doOnce('postFrame') // wait for the first frame to be rendered (for autoScale etc)
  48. // viewer.renderManager.autoBuildPipeline = false
  49. // viewer.renderManager.pipeline = [] // this will disable main viewer rendering
  50. ```