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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. # ThreePipe
  2. A new way to work with three.js, 3D models and rendering on the web.
  3. [ThreePipe](https://threepipe.org/) —
  4. [Github](https://github.com/repalash/threepipe) —
  5. [Examples](https://threepipe.org/examples/) —
  6. [API Reference](https://threepipe.org/docs/) —
  7. [WebGi](https://webgi.xyz/docs/)
  8. [![NPM Package](https://img.shields.io/npm/v/threepipe.svg)](https://www.npmjs.com/package/threepipe)
  9. [![Discord Server](https://img.shields.io/discord/956788102473584660?label=Discord&logo=discord)](https://discord.gg/apzU8rUWxY)
  10. [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/license/apache-2-0/)
  11. [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/repalash.svg?style=social&label=Follow%20%40repalash)](https://twitter.com/repalash)
  12. ThreePipe is a 3D framework built on top of [three.js](https://threejs.org/) in TypeScript with a focus on rendering quality, modularity and extensibility.
  13. Key features include:
  14. - Simple, intuitive API for creating 3D model viewers/configurators/editors on web pages, with many built-in presets for common workflows and use-cases.
  15. - Companion [editor](https://threepipe.org/examples/tweakpane-editor/) to create, edit and configure 3D scenes in the browser.
  16. - Modular architecture that allows you to easily extend the viewer, scene objects, materials, shaders, rendering, post-processing and serialization with custom functionality.
  17. - Simple plugin system along with a rich library of built-in plugins that allows you to easily add new features to the viewer.
  18. - [uiconfig](https://github.com/repalash/uiconfig.js) compatibility to automatically generate configuration UIs in the browser.
  19. - Modular rendering pipeline with built-in deferred rendering, post-processing, RGBM HDR rendering, etc.
  20. - Material extension framework to modify/inject/build custom shader code into existing materials at runtime from plugins.
  21. - Extendable asset import, export and management pipeline with built-in support for gltf, glb, obj+mtl, fbx, materials(pmat/bmat), json, zip, png, jpeg, svg, webp, ktx2, ply, 3dm and many more.
  22. - Automatic serialization of all viewer and plugin settings in GLB(with custom extensions) and JSON formats.
  23. - Automatic disposal of all three.js resources with built-in reference management.
  24. ## Examples
  25. Code samples and demos covering various usecases and test are present in the [examples](./examples/) folder.
  26. Try them: https://threepipe.org/examples/
  27. View the source code by pressing the code button on the top left of the example page.
  28. To make changes and run the example, click on the CodePen button on the top right of the source code.
  29. ## Getting Started
  30. ### Installation
  31. ```bash
  32. npm install threepipe
  33. ```
  34. ### Loading a 3D Model
  35. First, create a canvas element in your HTML page:
  36. ```html
  37. <canvas id="three-canvas" style="width: 800px; height: 600px;"></canvas>
  38. ```
  39. Then, import the viewer and create a new instance:
  40. ```typescript
  41. import {ThreeViewer, IObject3D} from 'threepipe'
  42. // Create a viewer
  43. const viewer = new ThreeViewer({canvas: document.getElementById('three-canvas') as HTMLCanvasElement})
  44. // Load an environment map
  45. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  46. // Load a model
  47. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  48. autoCenter: true,
  49. autoScale: true,
  50. })
  51. ```
  52. That's it! You should now see a 3D model on your page.
  53. The 3D model can be opened in the [editor](TODO) to view and edit the scene settings, objects, materials, lights, cameras, post-processing, etc. and exported as a GLB file. All settings are automatically serialized and saved in the GLB file, which can be loaded into the viewer. Any plugins used in the editor can be added to the viewer to add the same functionality. The plugin data is automatically loaded(if the plugin is added) when the model is added to the scene.
  54. The viewer initializes with a Scene, Camera, Camera controls(Orbit Controls), several importers, exporters and a default rendering pipeline. Additional functionality can be added with plugins.
  55. Check out the GLTF Load example to see it in action or to check the JS equivalent code: https://threepipe.org/examples/gltf-load/
  56. Check out the [Plugins](#plugins) section below to learn how to add additional functionality to the viewer.
  57. ## License
  58. The core framework([src](https://github.com/repalash/threepipe/tree/master/src), [dist](https://github.com/repalash/threepipe/tree/master/dist), [examples](https://github.com/repalash/threepipe/tree/master/examples) folders) and any [plugins](https://github.com/repalash/threepipe/tree/master/plugins) without a separate license are under the [Apache 2.0 license](https://github.com/repalash/threepipe/tree/master/LICENSE).
  59. Some plugins(in the [plugins](https://github.com/repalash/threepipe/tree/master/plugins) folder) might have different licenses. Check the individual plugin documentation and the source folder/files for more details.
  60. ## Status
  61. The project is in `alpha` stage and under active development. Many features will be added but the core API will not change significantly in future releases.
  62. Check out [WebGi](https://webgi.xyz/) for an advanced tailor-made solution for e-commerce, jewelry, automobile, apparel, furniture etc.
  63. ## Documentation
  64. Check the list of all functions, classes and types in the [API Reference Docs](https://threepipe.org/docs/).
  65. ## WebGi
  66. Check out WebGi - Premium Photo-realistic 3D rendering framework and tools for web applications and online commerce along with custom modules and rendering solutions for e-commerce, jewelry, automobile, apparel, furniture and other retail applications.
  67. [Homepage](https://webgi.xyz/) &mdash; [Docs](https://webgi.xyz/docs/)
  68. [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/repalash.svg?style=social&label=Follow%20%40pixotronics)](https://twitter.com/pixotronics)
  69. ## Contributing
  70. Contributions to ThreePipe are welcome and encouraged! Feel free to open issues and pull requests on the GitHub repository.
  71. ## File Formats
  72. ThreePipe Asset Manager supports the import of the following file formats out of the box:
  73. * Models:
  74. * gltf, glb
  75. * obj, mtl
  76. * fbx
  77. * drc
  78. * Materials
  79. * mat, pmat, bmat (json based), registered material template slugs
  80. * Images
  81. * webp, png, jpeg, jpg, svg, ico
  82. * hdr, exr
  83. * ktx2, ktx, dds, pvr
  84. * Misc
  85. * json, vjson
  86. * zip
  87. * txt
  88. Plugins can add additional formats:
  89. * Models
  90. * 3dm - Using [Rhino3dmLoadPlugin](#Rhino3dmLoadPlugin)
  91. ## Plugins
  92. ThreePipe has a simple plugin system that allows you to easily add new features to the viewer. Plugins can be added to the viewer using the `addPlugin` and `addPluginSync` methods. The plugin system is designed to be modular and extensible. Plugins can be added to the viewer at any time and can be removed using the `removePlugin` and `removePluginSync` methods.
  93. ### TonemapPlugin
  94. todo: image
  95. Example: https://threepipe.org/examples/#tonemap-plugin/
  96. Source Code: [src/plugins/postprocessing/TonemapPlugin.ts](./src/plugins/postprocessing/TonemapPlugin.ts)
  97. API Reference: [TonemapPlugin](https://threepipe.org/docs/classes/TonemapPlugin.html)
  98. TonemapPlugin adds a post-processing material extension to the ScreenPass in render manager
  99. that applies tonemapping to the color. The tonemapping operator can be changed
  100. by setting the `toneMapping` property of the plugin. The default tonemapping operator is `ACESFilmicToneMapping`.
  101. Other Tonemapping properties can be like `exposure`, `contrast` and `saturation`
  102. TonemapPlugin is added by default in ThreeViewer unless `tonemap` is set to `false` in the options.
  103. ### DropzonePlugin
  104. todo: image
  105. Example: https://threepipe.org/examples/#dropzone-plugin/
  106. Source Code: [src/plugins/interaction/DropzonePlugin.ts](./src/plugins/interaction/DropzonePlugin.ts)
  107. API Reference: [DropzonePlugin](https://threepipe.org/docs/classes/DropzonePlugin.html)
  108. DropzonePlugin adds support for drag and drop of local files to automatically import, process and load them into the viewer.
  109. DropzonePlugin can be added by default in ThreeViewer
  110. by setting the `dropzone` property to `true` or an object of `DropzonePluginOptions` in the options.
  111. ```typescript
  112. import {DropzonePlugin, ThreeViewer} from 'threepipe'
  113. const viewer = new ThreeViewer({
  114. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  115. dropzone: true, // just set to true to enable drag drop functionatility in the viewer
  116. })
  117. ```
  118. To set custom options,
  119. pass an object of [DropzonePluginOptions](https://threepipe.org/docs/interfaces/DropzonePluginOptions.html) type to the `dropzone` property.
  120. ```typescript
  121. import {DropzonePlugin, ThreeViewer} from 'threepipe'
  122. const viewer = new ThreeViewer({
  123. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  124. dropzone: { // this can also be set to true and configured by getting a reference to the DropzonePlugin
  125. allowedExtensions: ['gltf', 'glb', 'hdr', 'png', 'jpg', 'json', 'fbx', 'obj'], // only allow these file types. If undefined, all files are allowed.
  126. addOptions: {
  127. disposeSceneObjects: true, // auto dispose of old scene objects
  128. autoSetEnvironment: true, // when hdr is dropped
  129. autoSetBackground: true, // when any image is dropped
  130. autoCenter: true, // auto center the object
  131. autoScale: true, // auto scale according to radius
  132. autoScaleRadius: 2,
  133. license: 'Imported from dropzone', // Any license to set on imported objects
  134. importConfig: true, // import config from file
  135. },
  136. // check more options in the DropzonePluginOptions interface
  137. },
  138. })
  139. ```
  140. ### DepthBufferPlugin
  141. todo: image
  142. Example: https://threepipe.org/examples/#depth-buffer-plugin/
  143. Source Code: [src/plugins/pipeline/DepthBufferPlugin.ts](./src/plugins/pipeline/DepthBufferPlugin.ts)
  144. API Reference: [DepthBufferPlugin](https://threepipe.org/docs/classes/DepthBufferPlugin.html)
  145. Depth Buffer Plugin adds a pre-render pass to the render manager and renders a depth buffer to a target. The render target can be accessed by other plugins throughout the rendering pipeline to create effects like depth of field, SSAO, SSR, etc.
  146. ```typescript
  147. import {ThreeViewer, DepthBufferPlugin} from 'threepipe'
  148. const viewer = new ThreeViewer({...})
  149. const depthPlugin = viewer.addPluginSync(new DepthBufferPlugin(HalfFloatType))
  150. const depthTarget = depthPlugin.target;
  151. // Use the depth target by accesing `depthTarget.texture`.
  152. ```
  153. The depth values are based on camera near far values, which are controlled automatically by the viewer. To manually specify near, far values and limits, it can be set in the camera userData. Check the [example](https://threepipe.org/examples/#depth-buffer-plugin/) for more details.
  154. ### NormalBufferPlugin
  155. todo: image
  156. Example: https://threepipe.org/examples/#normal-buffer-plugin/
  157. Source Code: [src/plugins/pipeline/NormalBufferPlugin.ts](./src/plugins/pipeline/NormalBufferPlugin.ts)
  158. API Reference: [NormalBufferPlugin](https://threepipe.org/docs/classes/NormalBufferPlugin.html)
  159. Normal Buffer Plugin adds a pre-render pass to the render manager and renders a normal buffer to a target. The render target can be accessed by other plugins throughout the rendering pipeline to create effects like SSAO, SSR, etc.
  160. Note: Use [`DepthNormalBufferPlugin`](#DepthNormalBufferPlugin) if using both `DepthBufferPlugin` and `NormalBufferPlugin` to render both depth and normal buffers in a single pass.
  161. ```typescript
  162. import {ThreeViewer, NormalBufferPlugin} from 'threepipe'
  163. const viewer = new ThreeViewer({...})
  164. const normalPlugin = viewer.addPluginSync(new NormalBufferPlugin())
  165. const normalTarget = normalPlugin.target;
  166. // Use the normal target by accessing `normalTarget.texture`.
  167. ```
  168. ### DepthNormalBufferPlugin
  169. todo
  170. ### RenderTargetPreviewPlugin
  171. todo: image
  172. Example: https://threepipe.org/examples/#render-target-preview/
  173. Source Code: [src/plugins/ui/RenderTargetPreviewPlugin.ts](./src/plugins/ui/RenderTargetPreviewPlugin.ts)
  174. API Reference: [RenderTargetPreviewPlugin](https://threepipe.org/docs/classes/RenderTargetPreviewPlugin.html)
  175. RenderTargetPreviewPlugin is a useful development and debugging plugin that renders any registered render-target to the screen in small collapsable panels.
  176. ```typescript
  177. import {ThreeViewer, RenderTargetPreviewPlugin, NormalBufferPlugin} from 'threepipe'
  178. const viewer = new ThreeViewer({...})
  179. const normalPlugin = viewer.addPluginSync(new NormalBufferPlugin(HalfFloatType))
  180. const previewPlugin = viewer.addPluginSync(new RenderTargetPreviewPlugin())
  181. // Show the normal buffer in a panel
  182. previewPlugin.addTarget(()=>normalPlugin.target, 'normal', false, false)
  183. ```
  184. ### Rhino3dmLoadPlugin
  185. Example: https://threepipe.org/examples/#rhino3dm-load/
  186. Source Code: [src/plugins/import/Rhino3dmLoadPlugin.ts](./src/plugins/import/Rhino3dmLoadPlugin.ts)
  187. API Reference: [Rhino3dmLoadPlugin](https://threepipe.org/docs/classes/Rhino3dmLoadPlugin.html)
  188. Adds support for loading .3dm files generated by [Rhino 3D](https://www.rhino3d.com/). This plugin includes some changes with how 3dm files are loaded in three.js. The changes are around loading layer and primitive properties when set as reference in the 3dm files.
  189. ## Additional Plugins
  190. Additional plugins can be found in the [plugins](plugins/) directory.
  191. These add support for integrating with other libraries, adding new features, and other functionality with different licenses.
  192. ### Tweakpane Ui plugin
  193. todo: image
  194. Example: https://threepipe.org/examples/#viewer-uiconfig/
  195. Source Code: [plugins/tweakpane/src/TweakpaneUiPlugin.ts](plugins/tweakpane/src/TweakpaneUiPlugin.ts)
  196. API Reference: [TweakpaneUiPlugin](https://threepipe.org/plugins/tweakpane/docs/classes/TweakpaneUiPlugin.html)
  197. NPM: `npm install @threepipe/plugin-tweakpane`
  198. CDN: https://threepipe.org/plugins/tweakpane/dist/index.mjs
  199. TweakpaneUiPlugin adds support for using [uiconfig-tweakpane](https://github.com/repalash/uiconfig-tweakpane)
  200. to create a configuration UI in applications using the [Tweakpane](https://cocopon.github.io/tweakpane/) library.
  201. The plugin takes the [uiconfig](https://github.com/repalash/uiconfig.js)
  202. that's defined in the viewer and all the objects to automatically render a UI in the browser.
  203. ```typescript
  204. import {IObject3D, ThreeViewer, TonemapPlugin} from 'threepipe'
  205. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  206. const viewer = new ThreeViewer({...})
  207. // Add the plugin
  208. const plugin = viewer.addPluginSync(new TweakpaneUiPlugin(true)) // true to show expanded the UI by default
  209. // Add the UI for the viewer
  210. plugin.appendChild(viewer.uiConfig)
  211. // Add UI for some plugins
  212. plugin.setupPlugins(TonemapPlugin, DropzonePlugin)
  213. ```
  214. ### Tweakpane Editor Plugin
  215. todo: image
  216. Example: https://threepipe.org/examples/#tweakpane-editor/
  217. Source Code: [plugins/tweakpane-editor/src/TweakpaneEditorPlugin.ts](plugins/tweakpane-editor/src/TweakpaneEditorPlugin.ts)
  218. API Reference: [TweakpaneEditorPlugin](https://threepipe.org/plugins/tweakpane-editor/docs/classes/TweakpaneEditorPlugin.html)
  219. NPM: `npm install @threepipe/plugin-tweakpane-editor`
  220. CDN: https://threepipe.org/plugins/tweakpane-editor/dist/index.mjs
  221. TweakpaneEditorPlugin uses TweakpaneUiPlugin to create an editor for editing viewer,
  222. plugins, model and material configurations in the browser.
  223. ```typescript
  224. import {IObject3D, ThreeViewer, TonemapPlugin} from 'threepipe'
  225. import {TweakpaneEditorPlugin} from '@threepipe/plugin-tweakpane-editor'
  226. const viewer = new ThreeViewer({...})
  227. viewer.addPluginSync(new TweakpaneUiPlugin(true))
  228. const editor = viewer.addPluginSync(new TweakpaneEditorPlugin())
  229. // Add some plugins to the viewer
  230. await viewer.addPlugins([
  231. new ViewerUiConfigPlugin(),
  232. // new SceneUiConfigPlugin(), // this is already in ViewerUiPlugin
  233. new DepthBufferPlugin(HalfFloatType, true, true),
  234. new NormalBufferPlugin(HalfFloatType, false),
  235. new RenderTargetPreviewPlugin(false),
  236. ])
  237. // Load the plugin UI in the editor and tweakpane ui with categories.
  238. editor.loadPlugins({
  239. ['Viewer']: [ViewerUiConfigPlugin, SceneUiConfigPlugin, DropzonePlugin, FullScreenPlugin],
  240. ['GBuffer']: [DepthBufferPlugin, NormalBufferPlugin],
  241. ['Post-processing']: [TonemapPlugin],
  242. ['Debug']: [RenderTargetPreviewPlugin],
  243. })
  244. ```