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

1 год назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. ---
  2. prev:
  3. text: 'Editors in Threepipe'
  4. link: './editors'
  5. next:
  6. text: 'Viewer API'
  7. link: './viewer-api'
  8. ---
  9. # Features
  10. Threepipe comes packed with a asset manager, render pipeline, serialization setup, material extensions, UI configurations and bundles many plugins, that can be added with a single line of code to provide a variety of features listed below. In a custom application it’s possible to tree-shake the bundle by picking the plugins that are required.
  11. ## File Formats
  12. ThreePipe Asset Manager supports the import of the following file formats out of the box:
  13. * **Models**: gltf, glb, obj+mtl, fbx, drc
  14. * **Materials**: mat, pmat, bmat (json based), registered material template slugs
  15. * **Images**: webp, png, jpeg, jpg, svg, ico, avif, hdr, exr
  16. * **Misc**: json, vjson, zip, txt
  17. Plugins can add additional formats:
  18. * Models
  19. * 3dm - Using [Rhino3dmLoadPlugin](../plugin/Rhino3dmLoadPlugin)
  20. * ply - Using [PLYLoadPlugin](../plugin/PLYLoadPlugin)
  21. * usdz - Using [USDZLoadPlugin](../plugin/USDZLoadPlugin)
  22. * stl - Using [STLLoadPlugin](../plugin/STLLoadPlugin)
  23. * ktx - Using [KTXLoadPlugin](../plugin/KTXLoadPlugin)
  24. * ktx2 - Using [KTX2LoadPlugin](../plugin/KTX2LoadPlugin)
  25. Plugins to support more model formats are available in the package [@threepipe/plugins-extra-importers](#threepipeplugins-extra-importers) including .3ds,
  26. .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
  27. ### Loading files
  28. All the file formats can be easily loaded using the `viewer.load` method.
  29. ```typescript
  30. const objectGlb = await viewer.load<IObject3D>('https://example.com/file.glb')
  31. const texture = await viewer.load<ITexture>('https://example.com/texture.png')
  32. const material = await viewer.load<PhysicalMaterial>('https://example.com/material.pmat')
  33. const json = await viewer.load<any>('https://example.com/file.json')
  34. ```
  35. This method internally uses the [AssetManager](https://threepipe.org/docs/classes/AssetManager.html) to load files and returns a promise that resolves to the loaded object.
  36. Check the [Loading Files](./loading-files) guide for more details and how to load different file types.
  37. - [3D models](./loading-files#3d-models)
  38. - [Materials](./loading-files#materials)
  39. - [Images/Textures](./loading-files#imagestextures)
  40. - [zip files](./loading-files#zip-files)
  41. - [txt, json files](./loading-files#txt-json-files)
  42. - [Data URLs](./loading-files#data-urls)
  43. - [Local files, File and Blob](./loading-files#local-files-file-and-blob)
  44. - [Background, Environment maps](./loading-files#background-environment-maps)
  45. - [SVG strings](./loading-files#svg-strings)
  46. ### Exporting files
  47. Threepipe has built-in support for exporting some file types like glb, exr, images(textures, render targets), , materials, json(viewer/scene configuration and plugin configurations).
  48. To export files, several helpers are provided - [`viewer.export()`](https://threepipe.org/docs/classes/ThreeViewer.html#export) and [`viewer.exportScene()`](https://threepipe.org/docs/classes/ThreeViewer.html#exportScene).
  49. ```typescript
  50. const blob = await viewer.exportScene({viewerConfig: true})
  51. const blob1 = await viewer.export(object, {exportExt: 'glb', embedUrlImages: true})
  52. const blob2 = await viewer.export(material)
  53. const blob3 = await viewer.export(texture)
  54. const blob4 = await viewer.export(dataTexture)
  55. const blob5 = await viewer.export(renderTarget)
  56. ```
  57. Check the [Exporting Files](./exporting-files) guide for more details and how to export different file types.
  58. - [Exporting 3D models](./exporting-files#exporting-3d-models)
  59. - [Exporting Materials](./exporting-files#exporting-materials)
  60. - [Exporting Canvas Images](./exporting-files#exporting-canvas-images)
  61. - [Exporting Images/Textures](./exporting-files#exporting-imagestextures)
  62. - [Exporting Render Targets](./exporting-files#exporting-render-targets)
  63. ## Plugin System
  64. Threepipe includes a plugin system for adding additional features to the viewer in a modular way.
  65. All plugins follow the same basic structure, independent of the logic, with the API to add and remove plugins being always consistent (and one-liner). This makes it easy to debug, bundle, tree-shake, serialisation/deserialisation and extend functionality to the 3d viewer. It is also recommended to keep individual plugins small and handle one specific functionality.
  66. Plugins can be dependant on other plugins. These dependencies are automatically resolved and added to the viewer at runtime. eg. `SSAOPlugin` depends on `GBufferPlugin` to get the depth and normal data. So, when `SSAOPlugin` is added to the viewer, it automatically adds `GBufferPlugin` before that (if not added already).
  67. The plugins can be added synchronously or asynchronously using `viewer.addPluginSync` and `viewer.addPlugin` methods respectively.
  68. It is recommended to create custom plugins for reusable features, as they provide built-in features for ui configuration, serialization, integration with editors etc and are easy to manage and tree-shake in the code.
  69. Check out the list of plugins in the [Core Plugin](./core-plugins) and [@threepipe Packages](./threepipe-packages) pages.
  70. To create new plugins, simply implement the `IViewerPlugin` interface or extend the [AViewerPluginSync](https://threepipe.org/docs/classes/AViewerPluginSync.html) or [AViewerPluginAsync](https://threepipe.org/docs/classes/AViewerPluginAsync.html) classes.
  71. Read more about the [Plugin System](./plugin-system) on it's page.
  72. ## Render pipeline
  73. Threepipe includes a [RenderManager](https://threepipe.org/docs/classes/RenderManager.html) for managing the composition pipeline, and provides helpers for rendering and render target management.
  74. The `RenderManager` includes an [EffectComposer](https://threejs.org/docs/#api/en/postprocessing/EffectComposer) from three.js for rendering passes and a [WebGLRenderer](https://threejs.org/docs/#api/en/renderers/WebGLRenderer) for rendering, but the pass management and sorting is managed by the `RenderManager` itself. It inherits from [RenderTargetManager](https://threepipe.org/docs/classes/RenderTargetManager.html) which provides utilities for creating, tracking and destroying dedicated and temporary render targets.
  75. The main render pipeline supports progressive rendering and is fully configurable. Plugins and applications can add custom passes, effects, and shaders to the pipeline.
  76. By default, the render pipeline includes 2 passes - [RenderPass](https://threejs.org/docs/#api/en/postprocessing/RenderPass) for rendering the scene hierarchy and [ScreenPass](https://threejs.org/docs/#api/en/postprocessing/ShaderPass) for rendering the final output on the canvas.
  77. Plugins like [GBufferPlugin](https://threepipe.org/docs/classes/GBufferPlugin.html), [SSAOPlugin](https://threepipe.org/docs/classes/SSAOPlugin.html), [TonemapPlugin](https://threepipe.org/docs/classes/TonemapPlugin.html), etc interact and extend the render pipeline by adding custom passes to the render pipeline and material extensions to the material manager.
  78. Check the [Render Pipeline](./render-pipeline) guide for more details about render targets and how to add custom passes.
  79. ## Material Extension
  80. Threepipe includes a Material extension system along with a material manager.
  81. The material manager is used to register materials and material extensions.
  82. The material extensions can extend any material in the scene, or any plugin/pass with additional uniforms, defines, shader snippets and provides hooks.
  83. The material extensions are automatically applied to all materials in the scene that are compatible,
  84. when the extension is registered or when the material(the object its assigned to) is added to the scene.
  85. Threepipe includes several built-in materials like [PhysicalMaterial](https://threepipe.org/docs/classes/PhysicalMaterial.html), [UnlitMaterial](https://threepipe.org/docs/classes/UnlitMaterial.html), [ExtendedShaderMaterial](https://threepipe.org/docs/classes/ExtendedShaderMaterial.html), [LegacyPhongMaterial](https://threepipe.org/docs/classes/LegacyPhongMaterial.html), that include support for extending the material. Any existing three.js material can be made extendable, check the `ShaderPass2` class for a simple example that adds support for material extension to three.js ShaderPass.
  86. Several Plugins create and register material extensions to add different kinds of rendering features over the standard three.js materials like [ClearcoatTintPlugin](https://threepipe.org/docs/classes/ClearcoatTintPlugin.html), [SSAOPlugin](https://threepipe.org/docs/classes/SSAOPlugin.html), [CustomBumpMapPlugin](https://threepipe.org/docs/classes/CustomBumpMapPlugin.html), [AnisotropyPlugin](https://threepipe.org/docs/classes/AnisotropyPlugin.html), [FragmentClippingExtensionPlugin](https://threepipe.org/docs/classes/FragmentClippingExtensionPlugin.html), etc. They also provide uiConfig that can be used to dynamically generate UI or the material extensions.
  87. Some plugins also expose their material extensions to be used by other passes/plugins to access properties like buffers, synced uniforms, defines etc. Like [GBufferPlugin](https://threepipe.org/docs/classes/GBufferPlugin.html), [DepthBufferPlugin](https://threepipe.org/docs/classes/DepthBufferPlugin.html), [NormalBufferPlugin](https://threepipe.org/docs/classes/NormalBufferPlugin.html), etc.
  88. Read more and check a sample plugin in the [Material Extension](./material-extension) guide.
  89. ## UI Configuration
  90. Almost all of the classes and plugins in Threepipe include [uiconfig.js](https://repalash.com/uiconfig.js/) support and can be used to create configuration UIs, 3d configurators and even full-editors.
  91. The UIs are automatically generated based on the configuration object under `.uiConfig` property on all objects. These are of type [UiObjectConfig](https://repalash.com/uiconfig.js/interfaces/UiObjectConfig.html).
  92. In some classes, the ui configs are also generated using typescript decorators.
  93. The `uiConfig` is also added to all three.js objects and materials when they are added to the scene.
  94. The UIs can be generated at runtime using any of the UI plugins like [TweakpaneUIPlugin](#threepipeplugin-tweakpane), [BlueprintJsUiPlugin](#threepipeplugin-blueprintjs)
  95. An example showing how to create a UI for a material
  96. ```typescript
  97. const ui = viewer.addPluginSync(TweakpaneUiPlugin)
  98. const object = viewer.scene.getObjectByName('objectName');
  99. const material = object.material as PhysicalMaterial;
  100. ui.appendChild(material.uiConfig)
  101. ```
  102. See it in action: https://threepipe.org/examples/#material-uiconfig/
  103. Check more examples showing [Viewer UI](https://threepipe.org/examples/#viewer-uiconfig/), [Scene UI](https://threepipe.org/examples/#scene-uiconfig/), [Object UI](https://threepipe.org/examples/#object-uiconfig/), [Camera UI](https://threepipe.org/examples/#camera-uiconfig/)
  104. ::: info
  105. [TweakpaneEditorPlugin](#threepipeplugin-tweakpane-editor) further uses the Tweakpane configuration panel along with various plugins to create an 3d editor.
  106. :::
  107. Custom UI configuration can be created to generate custom UI for the editor or tweaking.
  108. This can be done by using typescript decorators or defining the UI in javascript as a [UiObjectConfig](https://repalash.com/uiconfig.js/interfaces/UiObjectConfig.html) object.
  109. Read more and check a sample in the [UI Configuration](./ui-config) guide.
  110. ## Serialization
  111. Easy serialization of all threepipe and most three.js objects are supported out of the box using the Asset Manager.
  112. Fine control over serialization is also supported
  113. using the [ThreeSerialization](https://threepipe.org/docs/classes/ThreeSerialization.html) class
  114. Call `ThreeSerialization.serialize` on any object to serialize it.
  115. and `ThreeSerialization.deserialize` to deserialize the serialized object.
  116. This is done by performing a nested serialization of all the properties of the object.
  117. It's possible to implement custom serializers for custom types and classes and is done for three.js primitives,
  118. objects and plugins in threepipe
  119. ```typescript
  120. const vec = new Vector3()
  121. const serialized = ThreeSerialization.serialize(vec)
  122. const deserialized = ThreeSerialization.deserialize(serialized)
  123. // deserialized will be an instance of Vector3
  124. ```
  125. ::: tip
  126. For any high-level usage, don't use the `ThreeSerialization` class directly. Use the `viewer.export` and `viewer.import` methods or other methods to save and load configurations that's available in the plugins and the viewer.
  127. :::
  128. Read more and check samples in the [Serialization](./serialization) guide.