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

3 лет назад
3 лет назад
2 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  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. # Table of Contents
  30. - [ThreePipe](#threepipe)
  31. - [Examples](#examples)
  32. - [Table of Contents](#table-of-contents)
  33. - [Getting Started](#getting-started)
  34. - [HTML/JS Quickstart (CDN)](#htmljs-quickstart-cdn)
  35. - [NPM/YARN Package](#npmyarn)
  36. - [Installation](#installation)
  37. - [Loading a 3D Model](#loading-a-3d-model)
  38. - [License](#license)
  39. - [Status](#status)
  40. - [Documentation (API Reference)](#documentation)
  41. - [WebGi](#webgi)
  42. - [Contributing](#contributing)
  43. - [Features](#features)
  44. - [File Formats](#file-formats)
  45. - [Loading files](#loading-files)
  46. - [3D models](#3d-models)
  47. - [Materials](#materials)
  48. - [Images/Textures](#imagestextures)
  49. - [zip files](#zip-files)
  50. - [txt, json files](#txt-json-files)
  51. - [Data URLs](#data-urls)
  52. - [Local files, File and Blob](#local-files-file-and-blob)
  53. - [Background, Environment maps](#background-environment-maps)
  54. - [SVG strings](#svg-strings)
  55. - [Plugins](#threepipe-plugins)
  56. - [TonemapPlugin](#tonemapplugin) - Add tonemap to the final screen pass
  57. - [DropzonePlugin](#dropzoneplugin) - Drag and drop local files to import and load
  58. - [ProgressivePlugin](#progressiveplugin) - Post-render pass to blend the last frame with the current frame
  59. - [DepthBufferPlugin](#depthbufferplugin) - Pre-rendering of depth buffer
  60. - [NormalBufferPlugin](#normalbufferplugin) - Pre-rendering of normal buffer
  61. - [GBufferPlugin](#depthnormalbufferplugin) - Pre-rendering of depth and normal buffers in a single pass buffer
  62. - [GLTFAnimationPlugin](#gltfanimationplugin) - Add support for playing and seeking gltf animations
  63. - [PopmotionPlugin](#popmotionplugin) - Integrates with popmotion.io library for animation/tweening
  64. - [RenderTargetPreviewPlugin](#rendertargetpreviewplugin) - Preview any render target in a UI panel over the canvas
  65. - [FrameFadePlugin](#framefadeplugin) - Post-render pass to smoothly fade to a new rendered frame over time
  66. - [Rhino3dmLoadPlugin](#rhino3dmloadplugin) - Add support for loading .3dm files
  67. - [PLYLoadPlugin](#plyloadplugin) - Add support for loading .ply files
  68. - [STLLoadPlugin](#stlloadplugin) - Add support for loading .stl files
  69. - [KTX2LoadPlugin](#ktx2loadplugin) - Add support for loading .ktx2 files
  70. - [KTXLoadPlugin](#ktxloadplugin) - Add support for loading .ktx files
  71. - [Packages](#threepipe-packages)
  72. - [@threepipe/plugin-tweakpane](#threepipeplugin-tweakpane) Tweakpane UI Plugin
  73. - [@threepipe/plugin-tweakpane-editor](#threepipeplugin-tweakpane-editor) - Tweakpane Editor Plugin
  74. ## Getting Started
  75. ### HTML/JS Quickstart (CDN)
  76. ```html
  77. <canvas id="three-canvas" style="width: 800px; height: 600px;"></canvas>
  78. <script type="module">
  79. import {ThreeViewer} from 'https://threepipe.org/dist/index.mjs'
  80. const viewer = new ThreeViewer({canvas: document.getElementById('three-canvas')})
  81. // Load an environment map
  82. const envPromise = viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  83. const modelPromise = viewer.load('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  84. autoCenter: true,
  85. autoScale: true,
  86. })
  87. Promise.all([envPromise, modelPromise]).then(([env, model])=>{
  88. console.log('Loaded', model, env, viewer)
  89. })
  90. </script>
  91. ```
  92. Check it in action: https://threepipe.org/examples/#html-sample/
  93. ### NPM/YARN
  94. ### Installation
  95. ```bash
  96. npm install threepipe
  97. ```
  98. ### Loading a 3D Model
  99. First, create a canvas element in your HTML page:
  100. ```html
  101. <canvas id="three-canvas" style="width: 800px; height: 600px;"></canvas>
  102. ```
  103. Then, import the viewer and create a new instance:
  104. ```typescript
  105. import {ThreeViewer, IObject3D} from 'threepipe'
  106. // Create a viewer
  107. const viewer = new ThreeViewer({canvas: document.getElementById('three-canvas') as HTMLCanvasElement})
  108. // Load an environment map
  109. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  110. // Load a model
  111. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  112. autoCenter: true,
  113. autoScale: true,
  114. })
  115. ```
  116. That's it! You should now see a 3D model on your page.
  117. 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.
  118. 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.
  119. Check out the GLTF Load example to see it in action or to check the JS equivalent code: https://threepipe.org/examples/#gltf-load/
  120. Check out the [Plugins](#plugins) section below to learn how to add additional functionality to the viewer.
  121. ## License
  122. 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 Free [Apache 2.0 license](https://github.com/repalash/threepipe/tree/master/LICENSE).
  123. 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.
  124. ## Status
  125. 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.
  126. Check out [WebGi](https://webgi.xyz/) for an advanced tailor-made solution for e-commerce, jewelry, automobile, apparel, furniture etc.
  127. ## Documentation
  128. Check the list of all functions, classes and types in the [API Reference Docs](https://threepipe.org/docs/).
  129. ## WebGi
  130. 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.
  131. [Homepage](https://webgi.xyz/) &mdash; [Docs](https://webgi.xyz/docs/)
  132. [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/repalash.svg?style=social&label=Follow%20%40pixotronics)](https://twitter.com/pixotronics)
  133. ## Contributing
  134. Contributions to ThreePipe are welcome and encouraged! Feel free to open issues and pull requests on the GitHub repository.
  135. # Features
  136. ## File Formats
  137. ThreePipe Asset Manager supports the import of the following file formats out of the box:
  138. * Models:
  139. * gltf, glb
  140. * obj, mtl
  141. * fbx
  142. * drc
  143. * Materials
  144. * mat, pmat, bmat (json based), registered material template slugs
  145. * Images
  146. * webp, png, jpeg, jpg, svg, ico, avif
  147. * hdr, exr
  148. * Misc
  149. * json, vjson
  150. * zip
  151. * txt
  152. Plugins can add additional formats:
  153. * Models
  154. * 3dm - Using [Rhino3dmLoadPlugin](#Rhino3dmLoadPlugin)
  155. * ply - Using [PLYLoadPlugin](#PLYLoadPlugin)
  156. * stl - Using [STLLoadPlugin](#STLLoadPlugin)
  157. * ktx - Using [KTXLoadPlugin](#KTXLoadPlugin)
  158. * ktx2 - Using [KTX2LoadPlugin](#KTX2LoadPlugin)
  159. ## Loading files
  160. ThreePipe uses the [AssetManager](https://threepipe.org/docs/classes/AssetManager.html) to load files.
  161. The AssetManager has support for loading files from URLs, local files and data URLs.
  162. The AssetManager also adds support for loading files from a zip archive. The zip files are automatically unzipped, and the files are loaded from the zip archive.
  163. [viewer.load()](https://threepipe.org/docs/classes/ThreeViewer.html#load) is a high-level wrapper for loading files from the AssetManager.
  164. It automatically adds the loaded object to the scene and returns a promise that resolves to the loaded object,
  165. the materials are also automatically registered to the material manager.
  166. If the purpose is not to add files to the scene then [viewer.assetManager.importer.import()](https://threepipe.org/docs/classes/AssetImporter.html#import) method can be used
  167. to import files from the `AssetImporter`.
  168. viewer.assetManager.loadImported()](https://threepipe.org/docs/classes/AssetManager.html#loadImported)
  169. can then be called to load the imported files after any processing.
  170. The `viewer.load()`, `viewer.assetManager.addAsset()`
  171. and `viewer.assetManager.addAssetSingle()` methods perform combination of `import` and `loadImported`.
  172. ### 3D models
  173. The 3d models are added to `viewer.scene.modelRoot` on `viewer.load` unless some option is specified.
  174. ```typescript
  175. const objectGlb = await viewer.load<IObject3D>('https://example.com/file.glb')
  176. const objectFbx = await viewer.load<IObject3D>('https://example.com/file.fbx')
  177. const objectObj = await viewer.load<IObject3D>('https://example.com/file.obj') // .mtl referenced in obj is automatically loaded
  178. // ... load any 3d model file as an object
  179. ```
  180. Here, we are casting to [IObject3D](https://threepipe.org/docs/interfaces/IObject3D.html) type
  181. to get the proper type and autocomplete for the object.
  182. `IObject3D` inherits [Object3D](https://threejs.org/docs/#api/en/core/Object3D) from three.js and adds some additional properties.
  183. For JavaScript, the type can be omitted.
  184. ```javascript
  185. const objectGlb = await viewer.load('https://example.com/file.glb')
  186. ```
  187. When loading models, several options can be passed to automatically process the model first time, like `autoScale`, `autoCenter`, `addToRoot` etc. Check [AddObjectOptions](https://threepipe.org/docs/interfaces/AddObjectOptions.html) and [ImportAddOptions](https://threepipe.org/docs/interfaces/ImportAddOptions.html) for more details.
  188. ### Materials
  189. The materials downloaded as PMAT/BMAT/JSON etc from threepipe,
  190. webgi or the editor can be loaded
  191. and registered with the [MaterialManager](https://threepipe.org/docs/classes/MaterialManager)
  192. using the `viewer.load` method.
  193. Custom material types can also be registered by plugins(like dmat for diamonds), which can also be loaded automatically using the `viewer.load` method.
  194. ```typescript
  195. const pMaterial = await viewer.load<PhysicalMaterial>('https://example.com/file.pmat')
  196. const bMaterial = await viewer.load<UnlitMaterial>('https://example.com/file.bmat')
  197. // ... load any material file as a material
  198. ```
  199. Casting to [PhysicalMaterial](https://threepipe.org/docs/classes/PhysicalMaterial) or [UnlitMaterial](https://threepipe.org/docs/classes/UnlitMaterial) is optional but recommended to get the proper type and autocomplete for the material.
  200. To assign the material on any object, set it to `object.material`
  201. ```typescript
  202. // find a loaded mesh in the scene
  203. const object = viewer.scene.getObjectByName('objectName');
  204. // assign the material
  205. object.material = pMaterial;
  206. ```
  207. To copy the properties without changing the material reference, use `material.copy()` or `material.setValues()` methods.
  208. ```typescript
  209. object.material.copy(pMaterial);
  210. ```
  211. TODO: add examples for material load and copy
  212. ### Images/Textures
  213. Images can be loaded using the `viewer.load` method.
  214. There is built-in support for loading all image formats supported by the browser (webp, png, jpeg, jpg, svg, ico, avif) and hdr, exr, hdr.png formats for all browsers.
  215. More formats like ktx2, ktx, etc. can be added using plugins.
  216. ```typescript
  217. const texture = await viewer.load<ITexture>('https://example.com/file.png')
  218. // ... load any image file as a texture
  219. ```
  220. Casting to [ITexture](https://threepipe.org/docs/interfaces/ITexture.html) is optional
  221. but recommended to get the proper type and autocomplete for the texture.
  222. It inherits from three.js [Texture](https://threejs.org/docs/#api/en/textures/Texture) and adds some additional properties.
  223. To assign the texture on any material, set it to `material.map`
  224. ```typescript
  225. // find a loaded mesh in the scene
  226. const object = viewer.scene.getObjectByName('objectName');
  227. const material = object.material as PhysicalMaterial;
  228. // assign the texture
  229. material.map = texture;
  230. material.setDirty() // to let the viewer know that the material has changed and needs to re-render the scene. This will also trigger fade effect if FrameFadePlugin is added.
  231. ```
  232. Check out the image load example to see it in action or to check the JS equivalent code: https://threepipe.org/examples/#image-load/
  233. ### Zip files
  234. .zip files are automatically unzipped and the files are sent to re-load recursively when loaded with `viewer.load`.
  235. Any level of zip hierarchy is flattened.
  236. Loading files like .gltf with references to assets inside the zip file,
  237. any relative references are also automatically resolved.
  238. This is supported for file types like gltf, glb, obj,
  239. etc which support references to external files and has `root` set to `true in [IImporter](https://threepipe.org/docs/interfaces/IImporter.html).
  240. ```typescript
  241. const objectGltf = await viewer.load<IObject3D>('https://example.com/model.gltf.zip')
  242. ```
  243. If we know that the zip file contains a single gltf with all the assets, we can cast the result to [IObject3D](https://threepipe.org/docs/interfaces/IObject3D.html) type.
  244. To load multiple assets from zip files like multiple textures or materials, use `viewer.assetManager.addAsset` method which returns a promise of array of loaded assets.
  245. ```typescript
  246. const textures = await viewer.assetManager.addAsset<ITexture[]>('https://example.com/textures.zip')
  247. const materials = await viewer.assetManager.addAsset<IMaterial[]>('https://example.com/materials.zip')
  248. ```
  249. The auto import of zip contents can be disabled to get the files and blobs in the zip
  250. ```typescript
  251. const zip = await viewer.load<any>('https://example.com/file.zip', {autoImportZipContents: false})
  252. ```
  253. TODO - add example for loading zip files.
  254. ### txt, json files
  255. Text and JSON files can be loaded using the `viewer.load` method and return strings and objects respectively.
  256. ```typescript
  257. const text = await viewer.load<string>('https://example.com/file.txt')
  258. const json = await viewer.load<any>('https://example.com/file.json')
  259. ```
  260. ### Data URLs
  261. Data URLs can be loaded using the `viewer.load` method. The correct mime-type is required to be set in the data URL for finding the correct importer.
  262. ```typescript
  263. const dataUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA' // ... some data url
  264. const texture = await viewer.load<ITexture>(dataUrl)
  265. ```
  266. ### Local files, File and Blob
  267. Local files can be loaded using the `viewer.load` method by passing a [IAsset](https://threepipe.org/docs/interfaces/IAsset) object with [File](https://developer.mozilla.org/en-US/docs/Web/API/File) or [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object.
  268. ```typescript
  269. const file: File|Blob = fileObject // create a new file, blob or get from input element
  270. const text = await viewer.load<IObject>({
  271. // a path/name is required to determine the proper importer by extension. `file.name` can also be used if available
  272. path: 'file.glb',
  273. file
  274. })
  275. ```
  276. The same can be done for any file type.
  277. To load a `Map` of files(like when multiple files are dragged and dropped on the webpage) with internal references to other files, use `viewer.assetManager.importer.importFiles` method. Check the source for [DropzonePlugin](#DropzonePlugin) for an example.
  278. ### Background, Environment maps
  279. The background and environment maps can be set using the `viewer.setBackgroundMap` and `viewer.setEnvironmentMap` methods respectively. These accept both loaded textures from `viewer.load` and direct URLs. Files can be of any image format including hdr, exr.
  280. ```typescript
  281. await viewer.setEnvironmentMap('https://example.com/file.hdr')
  282. await viewer.setBackgroundMap('https://example.com/file.png')
  283. ```
  284. The same texture can be set to both by setting `setBackground` or `setEnvironment` to true in the options:
  285. ```typescript
  286. await viewer.setEnvironmentMap('https://example.com/file.hdr', {setBackground: true})
  287. ```
  288. Check the HDR Load example to see it in action: https://threepipe.org/examples/#hdr-load/
  289. ### SVG strings
  290. SVG strings can be converted to data urls using the [svgUrl](https://repalash.com/ts-browser-helpers/functions/svgUrl.html) string template function
  291. ```typescript
  292. const svgDataUrl = svgUrl`<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> ... </svg>`;
  293. const texture = await viewer.load<ITexture>(dataUrl)
  294. ```
  295. # Threepipe Plugins
  296. 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.
  297. ## TonemapPlugin
  298. todo: image
  299. Example: https://threepipe.org/examples/#tonemap-plugin/
  300. Source Code: [src/plugins/postprocessing/TonemapPlugin.ts](./src/plugins/postprocessing/TonemapPlugin.ts)
  301. API Reference: [TonemapPlugin](https://threepipe.org/docs/classes/TonemapPlugin.html)
  302. TonemapPlugin adds a post-processing material extension to the ScreenPass in render manager
  303. that applies tonemapping to the color. The tonemapping operator can be changed
  304. by setting the `toneMapping` property of the plugin. The default tonemapping operator is `ACESFilmicToneMapping`.
  305. Other Tonemapping properties can be like `exposure`, `contrast` and `saturation`
  306. TonemapPlugin is added by default in ThreeViewer unless `tonemap` is set to `false` in the options.
  307. ## DropzonePlugin
  308. todo: image
  309. Example: https://threepipe.org/examples/#dropzone-plugin/
  310. Source Code: [src/plugins/interaction/DropzonePlugin.ts](./src/plugins/interaction/DropzonePlugin.ts)
  311. API Reference: [DropzonePlugin](https://threepipe.org/docs/classes/DropzonePlugin.html)
  312. DropzonePlugin adds support for drag and drop of local files to automatically import, process and load them into the viewer.
  313. DropzonePlugin can be added by default in ThreeViewer
  314. by setting the `dropzone` property to `true` or an object of `DropzonePluginOptions` in the options.
  315. ```typescript
  316. import {DropzonePlugin, ThreeViewer} from 'threepipe'
  317. const viewer = new ThreeViewer({
  318. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  319. dropzone: true, // just set to true to enable drag drop functionatility in the viewer
  320. })
  321. ```
  322. To set custom options,
  323. pass an object of [DropzonePluginOptions](https://threepipe.org/docs/interfaces/DropzonePluginOptions.html) type to the `dropzone` property.
  324. ```typescript
  325. import {DropzonePlugin, ThreeViewer} from 'threepipe'
  326. const viewer = new ThreeViewer({
  327. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  328. dropzone: { // this can also be set to true and configured by getting a reference to the DropzonePlugin
  329. allowedExtensions: ['gltf', 'glb', 'hdr', 'png', 'jpg', 'json', 'fbx', 'obj', 'bin', 'exr'], // only allow these file types. If undefined, all files are allowed.
  330. addOptions: {
  331. disposeSceneObjects: true, // auto dispose of old scene objects
  332. autoSetEnvironment: true, // when hdr is dropped
  333. autoSetBackground: true, // when any image is dropped
  334. autoCenter: true, // auto center the object
  335. autoScale: true, // auto scale according to radius
  336. autoScaleRadius: 2,
  337. license: 'Imported from dropzone', // Any license to set on imported objects
  338. importConfig: true, // import config from file
  339. },
  340. // check more options in the DropzonePluginOptions interface
  341. },
  342. })
  343. ```
  344. ## ProgressivePlugin
  345. todo: image
  346. Example: https://threepipe.org/examples/#progressive-plugin/
  347. Source Code: [src/plugins/postprocessing/ProgressivePlugin.ts](./src/plugins/pipeline/ProgressivePlugin.ts)
  348. API Reference: [ProgressivePlugin](https://threepipe.org/docs/classes/ProgressivePlugin.html)
  349. Progressive Plugin adds a post-render pass to blend the last frame with the current frame.
  350. This is used as a dependency in other plugins for progressive rendering effect which is useful for progressive shadows, gi, denoising, baking, anti-aliasing, and many other effects.
  351. ## DepthBufferPlugin
  352. todo: image
  353. Example: https://threepipe.org/examples/#depth-buffer-plugin/
  354. Source Code: [src/plugins/pipeline/DepthBufferPlugin.ts](./src/plugins/pipeline/DepthBufferPlugin.ts)
  355. API Reference: [DepthBufferPlugin](https://threepipe.org/docs/classes/DepthBufferPlugin.html)
  356. 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.
  357. ```typescript
  358. import {ThreeViewer, DepthBufferPlugin} from 'threepipe'
  359. const viewer = new ThreeViewer({...})
  360. const depthPlugin = viewer.addPluginSync(new DepthBufferPlugin(HalfFloatType))
  361. const depthTarget = depthPlugin.target;
  362. // Use the depth target by accesing `depthTarget.texture`.
  363. ```
  364. 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.
  365. ## NormalBufferPlugin
  366. todo: image
  367. Example: https://threepipe.org/examples/#normal-buffer-plugin/
  368. Source Code: [src/plugins/pipeline/NormalBufferPlugin.ts](./src/plugins/pipeline/NormalBufferPlugin.ts)
  369. API Reference: [NormalBufferPlugin](https://threepipe.org/docs/classes/NormalBufferPlugin.html)
  370. 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.
  371. Note: Use [`DepthNormalBufferPlugin`](#DepthNormalBufferPlugin) if using both `DepthBufferPlugin` and `NormalBufferPlugin` to render both depth and normal buffers in a single pass.
  372. ```typescript
  373. import {ThreeViewer, NormalBufferPlugin} from 'threepipe'
  374. const viewer = new ThreeViewer({...})
  375. const normalPlugin = viewer.addPluginSync(new NormalBufferPlugin())
  376. const normalTarget = normalPlugin.target;
  377. // Use the normal target by accessing `normalTarget.texture`.
  378. ```
  379. ## GBufferPlugin
  380. todo
  381. ## GLTFAnimationPlugin
  382. todo: image
  383. Example: https://threepipe.org/examples/#gltf-animation-plugin/
  384. Source Code: [src/plugins/animation/GLTFAnimationPlugin.ts](./src/plugins/animation/GLTFAnimationPlugin.ts)
  385. API Reference: [GLTFAnimationPlugin](https://threepipe.org/docs/classes/GLTFAnimationPlugin.html)
  386. Manages playback of GLTF animations.
  387. The GLTF animations can be created in any 3d software that supports GLTF export like Blender.
  388. If animations from multiple files are loaded, they will be merged in a single root object and played together.
  389. The time playback is managed automatically, but can be controlled manually by setting {@link autoIncrementTime} to false and using {@link setTime} to set the time.
  390. This plugin is made for playing, pausing, stopping, all the animations at once, while it is possible to play individual animations, it is not recommended.
  391. To play individual animations, with custom choreography, use the {@link GLTFAnimationPlugin.animations} property to get reference to the animation clips and actions. Create your own mixers and control the animation playback like in three.js
  392. ## PopmotionPlugin
  393. todo: image
  394. Example: https://threepipe.org/examples/#popmotion-plugin/
  395. Source Code: [src/plugins/animation/PopmotionPlugin.ts](./src/plugins/animation/PopmotionPlugin.ts)
  396. API Reference: [PopmotionPlugin](https://threepipe.org/docs/classes/PopmotionPlugin.html)
  397. Provides animation/tweening capabilities to the viewer using the [popmotion.io](https://popmotion.io/) library.
  398. Overrides the driver in popmotion to sync with the viewer and provide ways to store and stop animations.
  399. ```typescript
  400. import {PopmotionPlugin, ThreeViewer} from 'threepipe'
  401. const viewer = new ThreeViewer({...})
  402. const cube = viewer.scene.getObjectByName('cube');
  403. const popmotion = viewer.addPluginSync(new PopmotionPlugin())
  404. // Move the object cube 1 unit up.
  405. const anim = popmotion.animate({
  406. from: cube.position.y,
  407. to: cube.position.y + 1,
  408. duration: 500, // ms
  409. onUpdate: (v) => {
  410. cube.position.setY(v)
  411. cube.setDirty()
  412. },
  413. onComplete: () => isMovedUp = !isMovedUp,
  414. })
  415. // await for animation
  416. await anim.promise;
  417. // or stop the animation
  418. // anim.stop()
  419. // Animate the color
  420. await popmotion.animateAsync({ // Also await for the animation.
  421. from: '#' + cube.material.color.getHexString(),
  422. to: '#' + new Color().setHSL(Math.random(), 1, 0.5).getHexString(),
  423. duration: 500,
  424. onUpdate: (v) => {
  425. cube.material.color.set(v)
  426. cube.material.setDirty()
  427. },
  428. })
  429. ```
  430. Note: The animation is started when the animate or animateAsync function is called.
  431. ## RenderTargetPreviewPlugin
  432. todo: image
  433. Example: https://threepipe.org/examples/#render-target-preview/
  434. Source Code: [src/plugins/ui/RenderTargetPreviewPlugin.ts](./src/plugins/ui/RenderTargetPreviewPlugin.ts)
  435. API Reference: [RenderTargetPreviewPlugin](https://threepipe.org/docs/classes/RenderTargetPreviewPlugin.html)
  436. RenderTargetPreviewPlugin is a useful development and debugging plugin that renders any registered render-target to the screen in small collapsable panels.
  437. ```typescript
  438. import {ThreeViewer, RenderTargetPreviewPlugin, NormalBufferPlugin} from 'threepipe'
  439. const viewer = new ThreeViewer({...})
  440. const normalPlugin = viewer.addPluginSync(new NormalBufferPlugin(HalfFloatType))
  441. const previewPlugin = viewer.addPluginSync(new RenderTargetPreviewPlugin())
  442. // Show the normal buffer in a panel
  443. previewPlugin.addTarget(()=>normalPlugin.target, 'normal', false, false)
  444. ```
  445. ## FrameFadePlugin
  446. todo: image
  447. Example: https://threepipe.org/examples/#frame-fade-plugin/
  448. Source Code: [src/plugins/pipeline/FrameFadePlugin.ts](./src/plugins/pipeline/FrameFadePlugin.ts)
  449. API Reference: [FrameFadePlugin](https://threepipe.org/docs/classes/FrameFadePlugin.html)
  450. FrameFadePlugin adds a post-render pass to the render manager and blends the last frame with the current frame over time. This is useful for creating smooth transitions between frames for example when changing the camera position, material, object properties, etc to avoid a sudden jump.
  451. ```typescript
  452. import {ThreeViewer, FrameFadePlugin} from 'threepipe'
  453. const viewer = new ThreeViewer({...})
  454. const fadePlugin = viewer.addPluginSync(new FrameFadePlugin())
  455. // Make some changes in the scene (any visual change that needs to be faded)
  456. // Start transition and wait for it to finish
  457. await fadePlugin.startTransition(400) // duration in ms
  458. ```
  459. To stop a transition, call `fadePlugin.stopTransition()`. This will immediately set the current frame to the last frame and stop the transition. The transition is also automatically stopped when the camera is moved or some pointer event occurs on the canvas.
  460. The plugin automatically tracks `setDirty()` function calls in objects, materials and the scene. It can be triggerred by calling `setDirty` on any material or object in the scene. Check the [example](https://threepipe.org/examples/#frame-fade-plugin/) for a demo. This can be disabled by options in the plugin.
  461. ## Rhino3dmLoadPlugin
  462. Example: https://threepipe.org/examples/#rhino3dm-load/
  463. Source Code: [src/plugins/import/Rhino3dmLoadPlugin.ts](./src/plugins/import/Rhino3dmLoadPlugin.ts)
  464. API Reference: [Rhino3dmLoadPlugin](https://threepipe.org/docs/classes/Rhino3dmLoadPlugin.html)
  465. 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.
  466. ```typescript
  467. import {Rhino3dmLoadPlugin} from 'threepipe'
  468. viewer.addPluginSync(new Rhino3dmLoadPlugin())
  469. const mesh = await viewer.load('file.3dm')
  470. ```
  471. ## PLYLoadPlugin
  472. Example: https://threepipe.org/examples/#ply-load/
  473. Source Code: [src/plugins/import/PLYLoadPlugin.ts](./src/plugins/import/PLYLoadPlugin.ts)
  474. API Reference: [PLYLoadPlugin](https://threepipe.org/docs/classes/PLYLoadPlugin.html)
  475. Adds support for loading .ply ([Polygon file format](https://en.wikipedia.org/wiki/PLY_(file_format))) files.
  476. ```typescript
  477. import {PLYLoadPlugin} from 'threepipe'
  478. viewer.addPluginSync(new PLYLoadPlugin())
  479. const mesh = await viewer.load('file.ply')
  480. ```
  481. ## STLLoadPlugin
  482. Example: https://threepipe.org/examples/#stl-load/
  483. Source Code: [src/plugins/import/STLLoadPlugin.ts](./src/plugins/import/STLLoadPlugin.ts)
  484. API Reference: [STLLoadPlugin](https://threepipe.org/docs/classes/STLLoadPlugin.html)
  485. Adds support for loading .stl ([Stereolithography](https://en.wikipedia.org/wiki/STL_(file_format))) files.
  486. ```typescript
  487. import {STLLoadPlugin} from 'threepipe'
  488. viewer.addPluginSync(new STLLoadPlugin())
  489. const mesh = await viewer.load('file.stl')
  490. ```
  491. ## KTX2LoadPlugin
  492. Example: https://threepipe.org/examples/#ktx2-load/
  493. Source Code: [src/plugins/import/KTX2LoadPlugin.ts](./src/plugins/import/KTX2LoadPlugin.ts)
  494. API Reference: [KTX2LoadPlugin](https://threepipe.org/docs/classes/KTX2LoadPlugin.html)
  495. Adds support for loading .ktx2 ([Khronos Texture](https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/) files.
  496. KTX2LoadPlugin also adds support for exporting loaded .ktx2 files in glTF files with the [KHR_texture_basisu](https://www.khronos.org/registry/KHR/textures/2.0-extensions/KHR_texture_basisu/) extension.
  497. ```typescript
  498. import {KTX2LoadPlugin} from 'threepipe'
  499. viewer.addPluginSync(new KTX2LoadPlugin())
  500. const texture = await viewer.load('file.ktx2')
  501. ```
  502. ## KTXLoadPlugin
  503. Example: https://threepipe.org/examples/#ktx-load/
  504. Source Code: [src/plugins/import/KTXLoadPlugin.ts](./src/plugins/import/KTXLoadPlugin.ts)
  505. API Reference: [KTXLoadPlugin](https://threepipe.org/docs/classes/KTXLoadPlugin.html)
  506. Adds support for loading .ktx ([Khronos Texture](https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/) files.
  507. Note: This plugin only adds support for loading .ktx file, and not exporting them in the bundled .glb. Use .ktx2 files instead of .ktx files for better compression and performance.
  508. ```typescript
  509. import {KTXLoadPlugin} from 'threepipe'
  510. viewer.addPluginSync(new KTXLoadPlugin())
  511. const texture = await viewer.load('file.ktx')
  512. ```
  513. # @threepipe Packages
  514. Additional plugins can be found in the [plugins](plugins/) directory.
  515. These add support for integrating with other libraries, adding new features, and other functionality with different licenses.
  516. ## @threepipe/plugin-tweakpane
  517. Tewakpane UI plugin for ThreePipe
  518. todo: image
  519. Example: https://threepipe.org/examples/#viewer-uiconfig/
  520. Source Code: [plugins/tweakpane/src/TweakpaneUiPlugin.ts](plugins/tweakpane/src/TweakpaneUiPlugin.ts)
  521. API Reference: [TweakpaneUiPlugin](https://threepipe.org/plugins/tweakpane/docs/classes/TweakpaneUiPlugin.html)
  522. NPM: `npm install @threepipe/plugin-tweakpane`
  523. CDN: https://threepipe.org/plugins/tweakpane/dist/index.mjs
  524. TweakpaneUiPlugin adds support for using [uiconfig-tweakpane](https://github.com/repalash/uiconfig-tweakpane)
  525. to create a configuration UI in applications using the [Tweakpane](https://cocopon.github.io/tweakpane/) library.
  526. The plugin takes the [uiconfig](https://github.com/repalash/uiconfig.js)
  527. that's defined in the viewer and all the objects to automatically render a UI in the browser.
  528. ```typescript
  529. import {IObject3D, ThreeViewer, TonemapPlugin} from 'threepipe'
  530. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  531. const viewer = new ThreeViewer({...})
  532. // Add the plugin
  533. const plugin = viewer.addPluginSync(new TweakpaneUiPlugin(true)) // true to show expanded the UI by default
  534. // Add the UI for the viewer
  535. plugin.appendChild(viewer.uiConfig)
  536. // Add UI for some plugins
  537. plugin.setupPlugins(TonemapPlugin, DropzonePlugin)
  538. ```
  539. ## @threepipe/plugin-tweakpane-editor
  540. Tweakpane Editor Plugin for ThreePipe
  541. todo: image
  542. Example: https://threepipe.org/examples/#tweakpane-editor/
  543. Source Code: [plugins/tweakpane-editor/src/TweakpaneEditorPlugin.ts](plugins/tweakpane-editor/src/TweakpaneEditorPlugin.ts)
  544. API Reference: [TweakpaneEditorPlugin](https://threepipe.org/plugins/tweakpane-editor/docs/classes/TweakpaneEditorPlugin.html)
  545. NPM: `npm install @threepipe/plugin-tweakpane-editor`
  546. CDN: https://threepipe.org/plugins/tweakpane-editor/dist/index.mjs
  547. TweakpaneEditorPlugin uses TweakpaneUiPlugin to create an editor for editing viewer,
  548. plugins, model and material configurations in the browser.
  549. ```typescript
  550. import {IObject3D, ThreeViewer, TonemapPlugin} from 'threepipe'
  551. import {TweakpaneEditorPlugin} from '@threepipe/plugin-tweakpane-editor'
  552. const viewer = new ThreeViewer({...})
  553. viewer.addPluginSync(new TweakpaneUiPlugin(true))
  554. const editor = viewer.addPluginSync(new TweakpaneEditorPlugin())
  555. // Add some plugins to the viewer
  556. await viewer.addPlugins([
  557. new ViewerUiConfigPlugin(),
  558. // new SceneUiConfigPlugin(), // this is already in ViewerUiPlugin
  559. new DepthBufferPlugin(HalfFloatType, true, true),
  560. new NormalBufferPlugin(HalfFloatType, false),
  561. new RenderTargetPreviewPlugin(false),
  562. ])
  563. // Load the plugin UI in the editor and tweakpane ui with categories.
  564. editor.loadPlugins({
  565. ['Viewer']: [ViewerUiConfigPlugin, SceneUiConfigPlugin, DropzonePlugin, FullScreenPlugin],
  566. ['GBuffer']: [DepthBufferPlugin, NormalBufferPlugin],
  567. ['Post-processing']: [TonemapPlugin],
  568. ['Debug']: [RenderTargetPreviewPlugin],
  569. })
  570. ```