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

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