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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  1. ## TonemapPlugin
  2. [//]: # (todo: image)
  3. [Example](https://threepipe.org/examples/#tonemap-plugin/) —
  4. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/postprocessing/TonemapPlugin.ts) —
  5. [API Reference](https://threepipe.org/docs/classes/TonemapPlugin.html)
  6. TonemapPlugin adds a post-processing material extension to the ScreenPass in render manager
  7. that applies tonemapping to the color. The tonemapping operator can be changed
  8. by setting the `toneMapping` property of the plugin. The default tonemapping operator is `ACESFilmicToneMapping`.
  9. Other Tonemapping properties can be like `exposure`, `contrast` and `saturation`
  10. TonemapPlugin is added by default in ThreeViewer unless `tonemap` is set to `false` in the options.
  11. ## DropzonePlugin
  12. [//]: # (todo: image)
  13. [Example](https://threepipe.org/examples/#dropzone-plugin/) —
  14. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/interaction/DropzonePlugin.ts) —
  15. [API Reference](https://threepipe.org/docs/classes/DropzonePlugin.html)
  16. DropzonePlugin adds support for drag and drop of local files to automatically import, process and load them into the viewer.
  17. DropzonePlugin can be added by default in ThreeViewer
  18. by setting the `dropzone` property to `true` or an object of `DropzonePluginOptions` in the options.
  19. ```typescript
  20. import {DropzonePlugin, ThreeViewer} from 'threepipe'
  21. const viewer = new ThreeViewer({
  22. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  23. dropzone: true, // just set to true to enable drag drop functionatility in the viewer
  24. })
  25. ```
  26. To set custom options,
  27. pass an object of [DropzonePluginOptions](https://threepipe.org/docs/interfaces/DropzonePluginOptions.html) type to the `dropzone` property.
  28. ```typescript
  29. import {DropzonePlugin, ThreeViewer} from 'threepipe'
  30. const viewer = new ThreeViewer({
  31. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  32. dropzone: { // this can also be set to true and configured by getting a reference to the DropzonePlugin
  33. allowedExtensions: ['gltf', 'glb', 'hdr', 'png', 'jpg', 'json', 'fbx', 'obj', 'bin', 'exr'], // only allow these file types. If undefined, all files are allowed.
  34. addOptions: {
  35. disposeSceneObjects: true, // auto dispose of old scene objects
  36. autoSetEnvironment: true, // when hdr is dropped
  37. autoSetBackground: true, // when any image is dropped
  38. autoCenter: true, // auto center the object
  39. autoScale: true, // auto scale according to radius
  40. autoScaleRadius: 2,
  41. license: 'Imported from dropzone', // Any license to set on imported objects
  42. importConfig: true, // import config from file
  43. },
  44. // check more options in the DropzonePluginOptions interface
  45. },
  46. })
  47. ```
  48. ## ProgressivePlugin
  49. [//]: # (todo: image)
  50. [Example](https://threepipe.org/examples/#progressive-plugin/) —
  51. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/pipeline/ProgressivePlugin.ts) —
  52. [API Reference](https://threepipe.org/docs/classes/ProgressivePlugin.html)
  53. Progressive Plugin adds a post-render pass to blend the last frame with the current frame.
  54. 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. The helper function `convergedPromise` returns a new promise that can be used to wait for the progressive rendering to converge.
  55. ## SSAAPlugin
  56. [//]: # (todo: image)
  57. [Example](https://threepipe.org/examples/#ssaa-plugin/) —
  58. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/pipeline/SSAAPlugin.ts) —
  59. [API Reference](https://threepipe.org/docs/classes/SSAAPlugin.html)
  60. SSAA Plugin adds support for [Super Sampling Anti-Aliasing](https://en.wikipedia.org/wiki/Supersampling) to the viewer. Simply add the plugin to the viewer to use it.
  61. It jitters the camera view offset over multiple frames, which are then blended by the [ProgressivePlugin](#progressiveplugin) to create a higher quality image. This is useful for reducing aliasing artifacts in the scene.
  62. By default, the pipeline only renders once per request animation frame. So we don't get any anti-aliasing while moving. For that, either use the TAA(Temporal Anti-aliasing) plugin or for the case of simple scenes - render multiple times per frame which can be done by setting `plugin.rendersPerFrame` or `viewer.rendersPerFrame`. Check out the [example](https://threepipe.org/examples/#ssaa-plugin/) to see the effect on frame rate.
  63. ```typescript
  64. const ssaa = viewer.addPluginSync(new SSAAPlugin())
  65. ssaa.enabled = true // toggle jittering(if you want to set custom view offset)
  66. ssaa.rendersPerFrame = 4 // render 4 times per frame (max 32 is useful)
  67. ```
  68. ## DepthBufferPlugin
  69. [//]: # (todo: image)
  70. [Example](https://threepipe.org/examples/#depth-buffer-plugin/) —
  71. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/pipeline/DepthBufferPlugin.ts) —
  72. [API Reference](https://threepipe.org/docs/classes/DepthBufferPlugin.html)
  73. 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.
  74. ```typescript
  75. import {ThreeViewer, DepthBufferPlugin} from 'threepipe'
  76. const viewer = new ThreeViewer({...})
  77. const depthPlugin = viewer.addPluginSync(new DepthBufferPlugin(HalfFloatType))
  78. const depthTarget = depthPlugin.target;
  79. // Use the depth target by accesing `depthTarget.texture`.
  80. ```
  81. 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.
  82. ## NormalBufferPlugin
  83. [//]: # (todo: image)
  84. [Example](https://threepipe.org/examples/#normal-buffer-plugin/) —
  85. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/pipeline/NormalBufferPlugin.ts) —
  86. [API Reference](https://threepipe.org/docs/classes/NormalBufferPlugin.html)
  87. 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.
  88. ::: info NOTE
  89. Use [`GBufferPlugin`](#GBufferPlugin) if using both `DepthBufferPlugin` and `NormalBufferPlugin` to render both depth and normal buffers in a single pass.
  90. :::
  91. ```typescript
  92. import {ThreeViewer, NormalBufferPlugin} from 'threepipe'
  93. const viewer = new ThreeViewer({...})
  94. const normalPlugin = viewer.addPluginSync(new NormalBufferPlugin())
  95. const normalTarget = normalPlugin.target;
  96. // Use the normal target by accessing `normalTarget.texture`.
  97. ```
  98. ## GBufferPlugin
  99. [//]: # (todo: image)
  100. [Example](https://threepipe.org/examples/#gbuffer-plugin/) —
  101. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/pipeline/GBufferPlugin.ts) —
  102. [API Reference](https://threepipe.org/docs/classes/GBufferPlugin.html)
  103. GBuffer Plugin adds a pre-render pass to the render manager and renders depth+normals to a target and some customizable flags to another. The multiple render target and textures can be accessed by other plugins throughout the rendering pipeline to create effects like SSAO, SSR, etc.
  104. ```typescript
  105. import {ThreeViewer, GBufferPlugin} from 'threepipe'
  106. const viewer = new ThreeViewer({...})
  107. const gBufferPlugin = viewer.addPluginSync(new GBufferPlugin())
  108. const gBuffer = gBufferPlugin.target;
  109. const normalDepth = gBufferPlugin.normalDepthTexture;
  110. const gBufferFlags = gBufferPlugin.flagsTexture;
  111. ```
  112. ## SSAOPlugin
  113. [//]: # (todo: image)
  114. [Example](https://threepipe.org/examples/#ssao-plugin/) —
  115. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/pipeline/SSAOPlugin.ts) —
  116. [API Reference](https://threepipe.org/docs/classes/SSAOPlugin.html)
  117. SSAO Plugin adds support for [Screen Space Ambient Occlusion](https://en.wikipedia.org/wiki/Screen_space_ambient_occlusion) to the viewer. Simply add the plugin to the viewer to use it.
  118. This is done by adding a pre-render pass to the render manager which renders SSAO to a custom render target. SSAOPlugin depends on [GBufferPlugin](#gbufferplugin), and is automatically added if not already.
  119. This render target is then used by all PhysicalMaterial(s) in the scene during the main RenderPass to get the AO data. SSAO can also be disabled from the UI of the material.
  120. Note: Use with [ProgressivePlugin](#progressiveplugin) and `TemporalAAPlugin` for best results.
  121. ```typescript
  122. import {ThreeViewer, SSAOPlugin} from 'threepipe'
  123. const viewer = new ThreeViewer({...})
  124. const ssaoPlugin = viewer.addPluginSync(new SSAOPlugin())
  125. // get the buffer.
  126. console.log(ssaoPlugin.target);
  127. // disable ssao for a material in the scene
  128. material.userData.ssaoDisabled = true
  129. ```
  130. > In the target/buffer - The ssao data is in the `r` channel to remain compatible with ORM. `gba` contains the depth in vec3(xyz) format.
  131. > Note that its `ssaoDisabled`, so setting it to `true` will disable the effect.
  132. ## CanvasSnapshotPlugin
  133. [//]: # (todo: image)
  134. [Example](https://threepipe.org/examples/#canvas-snapshot-plugin/) —
  135. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/export/CanvasSnapshotPlugin.ts) —
  136. [API Reference](https://threepipe.org/docs/classes/CanvasSnapshotPlugin.html)
  137. Canvas Snapshot Plugin adds support for taking snapshots of the canvas and exporting them as images and data urls. It includes options to take snapshot of a region, mime type, quality render scale and scaling the output image. Check out the interface [CanvasSnapshotOptions](https://threepipe.org/docs/interfaces/CanvasSnapshotOptions.html) for more details.
  138. ```typescript
  139. import {ThreeViewer, CanvasSnapshotPlugin} from 'threepipe'
  140. const viewer = new ThreeViewer({...})
  141. const snapshotPlugin = viewer.addPluginSync(new CanvasSnapshotPlugin())
  142. // download a snapshot.
  143. await snapshotPlugin.downloadSnapshot('image.webp', { // all parameters are optional
  144. scale: 1, // scale the final image
  145. timeout: 0, // wait before taking the snapshot, in ms
  146. quality: 0.9, // quality of the image (0-1) only for jpeg and webp
  147. displayPixelRatio: 2, // render scale
  148. mimeType: 'image/webp', // mime type of the image
  149. waitForProgressive: true, // wait for progressive rendering to finish (ProgressivePlugin). true by default
  150. rect: { // region to take snapshot. eg. crop center of the canvas
  151. height: viewer.canvas.clientHeight / 2,
  152. width: viewer.canvas.clientWidth / 2,
  153. x: viewer.canvas.clientWidth / 4,
  154. y: viewer.canvas.clientHeight / 4,
  155. },
  156. })
  157. // get data url (string)
  158. const dataUrl = await snapshotPlugin.getDataUrl({ // all parameters are optional
  159. displayPixelRatio: 2, // render scale
  160. mimeType: 'image/webp', // mime type of the image
  161. })
  162. // get File
  163. const file = await snapshotPlugin.getFile('file.jpeg', { // all parameters are optional
  164. mimeType: 'image/jpeg', // mime type of the image
  165. })
  166. ```
  167. ## PickingPlugin
  168. [//]: # (todo: image)
  169. [Example](https://threepipe.org/examples/#picking-plugin/) —
  170. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/interaction/PickingPlugin.ts) —
  171. [API Reference](https://threepipe.org/docs/classes/PickingPlugin.html)
  172. Picking Plugin adds support for selecting and hovering over objects in the viewer with user interactions and selection widgets.
  173. When the plugin is added to the viewer, it starts listening to the mouse move and click events over the canvas.
  174. When an object is clicked, it is selected,
  175. and if a UI plugin is added, the uiconfig for the selected object is populated in the interface.
  176. The events `selectedObjectChanged`, `hoverObjectChanged`, and `hitObject` can be listened to on the plugin.
  177. Picking plugin internally uses [ObjectPicker](https://threepipe.org/docs/classes/ObjectPicker.html),
  178. check out the documentation or source code for more information.
  179. ```typescript
  180. import {ThreeViewer, PickingPlugin} from 'threepipe'
  181. const viewer = new ThreeViewer({...})
  182. const pickingPlugin = viewer.addPluginSync(new PickingPlugin())
  183. // Hovering events are also supported, but since its computationally expensive for large scenes it is disabled by default.
  184. pickingPlugin.hoverEnabled = true
  185. pickingPlugin.addEventListener('hitObject', (e)=>{
  186. // This is fired when the user clicks on the canvas.
  187. // The selected object hasn't been changed yet, and we have the option to change it or disable selection at this point.
  188. // e.intersects.selectedObject contains the object that the user clicked on.
  189. console.log('Hit: ', e.intersects.selectedObject)
  190. // It can be changed here
  191. // e.intersects.selectedObject = e.intersects.selectedObject.parent // select the parent
  192. // e.intersects.selectedObject = null // unselect
  193. // Check other properties on the event like intersects, mouse position, normal etc.
  194. console.log(e)
  195. })
  196. pickingPlugin.addEventListener('selectedObjectChanged', (e)=>{
  197. // This is fired when the selected object is changed.
  198. // e.object contains the new selected object. It can be null if nothing is selected.
  199. console.log('Selected: ', e.object)
  200. })
  201. // Objects can be programmatically selected and unselected
  202. // to select
  203. pickingPlugin.setSelectedObject(object)
  204. // get the selected object
  205. console.log(pickingPlugin.getSelectedObject())
  206. // to unselect
  207. pickingPlugin.setSelectedObject(null)
  208. // Select object with camera animation to the object
  209. pickingPlugin.setSelectedObject(object, true)
  210. pickingPlugin.addEventListener('hoverObjectChanged', (e)=>{
  211. // This is fired when the hovered object is changed.
  212. // e.object contains the new hovered object.
  213. console.log('Hovering: ', e.object)
  214. })
  215. ```
  216. ## FullScreenPlugin
  217. [//]: # (todo: image)
  218. [Example](https://threepipe.org/examples/#fullscreen-plugin/) —
  219. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/interaction/FullScreenPlugin.ts) —
  220. [API Reference](https://threepipe.org/docs/classes/FullScreenPlugin.html)
  221. A simple plugin that provides functions to enter, exit and toggle full screen mode and check if the viewer is in full screen mode. Either the canvas or the whole container can be set to full screen.
  222. ```typescript
  223. import {ThreeViewer, FullScreenPlugin} from 'threepipe'
  224. const viewer = new ThreeViewer({...})
  225. const fullscreen = viewer.addPluginSync(new FullScreenPlugin())
  226. // enter full screen
  227. await fullscreen.enter(viewer.container) // viewer.canvas is used if no element is passed
  228. // exit full screen
  229. await fullscreen.exit()
  230. // toggle
  231. await fullscreen.toggle(viewer.container)
  232. // check if full screen
  233. console.log(fullScreenPlugin.isFullScreen())
  234. ```
  235. ## AssetExporterPlugin
  236. [//]: # (todo: image)
  237. [Example](https://threepipe.org/examples/#asset-exporter-plugin/) —
  238. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/export/AssetExporterPlugin.ts) —
  239. [API Reference](https://threepipe.org/docs/classes/AssetExporterPlugin.html)
  240. Asset Exporter Plugin provides options and methods to export the scene, object GLB or Viewer Config.
  241. All the functionality is available in the viewer(and `AssetExporter`) directly, this plugin only provides a ui-config and maintains state of the options which is saved as plugin configuration along with glb/vjson file
  242. ```typescript
  243. import {ThreeViewer, AssetExporterPlugin} from 'threepipe'
  244. const viewer = new ThreeViewer({...})
  245. const assetExporter = viewer.addPluginSync(new AssetExporterPlugin())
  246. // check the existing options
  247. console.log(assetExporter.exportOptions)
  248. // enable/disable viewer config/json embedding in glb
  249. assetExporter.viewerConfig = true
  250. // set encryption
  251. assetExporter.encrypt = true
  252. assetExporter.encryptKey = 'superstrongpassword' // comment this to get prompted for a key during export.
  253. // export scene as blob
  254. const blob = assetExporter.exportScene()
  255. // or export and download directly
  256. assetExporter.downloadSceneGlb()
  257. // export a specific object
  258. const object = viewer.scene.getObjectByName('objectName')
  259. const blob2 = assetExporter.exportObject(object, true) // true to also download
  260. ```
  261. Note: when downloading the model through the plugin, it uses viewer.export, which downloads the files by default, but uploads it to remote destinations when overloaded using `FileTransferPlugin`.
  262. ## FileTransferPlugin
  263. [//]: # (todo: image)
  264. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/export/FileTransferPlugin.ts) —
  265. [API Reference](https://threepipe.org/docs/classes/FileTransferPlugin.html)
  266. Provides a way to extend the viewer.export functionality with custom actions. It also maintains a process state for plugins like `LoadingScreenPlugin`.
  267. This plugin is added automatically, there is no need to use it manually, unless writing a plugin to extend the export functionality.
  268. Used in eg `AWSClientPlugin` to upload files directly to S3.
  269. ## LoadingScreenPlugin
  270. [//]: # (todo: image)
  271. [Example](https://threepipe.org/examples/#loading-screen-plugin/) —
  272. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/interaction/LoadingScreenPlugin.ts) —
  273. [API Reference](https://threepipe.org/docs/classes/LoadingScreenPlugin.html)
  274. Loading Screen Plugin adds configurable overlay with a logo, loading text, spinner and the list of loading items. It also provides options to minimize and maximize the loading popup when there is no objects in the scene.
  275. The overlay is automatically added to the viewer container and shown when any files are loading. Behaviour can be configured to change how its shown and hidden, and can even be triggered programmatically.
  276. ```typescript
  277. import {ThreeViewer, LoadingScreenPlugin} from 'threepipe'
  278. const viewer = new ThreeViewer({...})
  279. const loadingScreen = viewer.addPluginSync(new LoadingScreenPlugin())
  280. loadingScreen.loadingTextHeader = 'Loading Helmet 3D Model'
  281. loadingScreen.errorTextHeader = 'Error Loading Helmet 3D Model'
  282. loadingScreen.showFileNames = true
  283. loadingScreen.showProcessStates = true
  284. loadingScreen.showProgress = true
  285. loadingScreen.backgroundOpacity = 0.4 // 0-1
  286. loadingScreen.backgroundBlur = 28 // px
  287. ```
  288. See also the base class [AAssetManagerProcessStatePlugin](https://threepipe.org/docs/classes/AAssetManagerProcessStatePlugin.html) to write a custom loading plugin.
  289. ## InteractionPromptPlugin
  290. [//]: # (todo: image)
  291. [Example](https://threepipe.org/examples/#interaction-prompt-plugin/) —
  292. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/interaction/InteractionPromptPlugin.ts) —
  293. [API Reference](https://threepipe.org/docs/classes/InteractionPromptPlugin.html)
  294. Interaction Prompt Plugin adds a hand pointer icon over the canvas that moves to prompt the user to interact with the 3d scene. To use, simply add the plugin to the viewer.
  295. The default pointer icon from [google/model-viewer](https://github.com/google/model-viewer) and can be configured with the `pointerIcon` property.
  296. The pointer is automatically shown when some object is in the scene and the camera is not moving.
  297. The animation starts after a delay and stops on user interaction. It then restarts after a delay after the user stops interacting
  298. The plugin provides several options and functions to configure the automatic behaviour or trigger the animation manually.
  299. ```typescript
  300. import {ThreeViewer, InteractionPromptPlugin} from 'threepipe'
  301. const viewer = new ThreeViewer({...})
  302. const interactionPrompt = viewer.addPluginSync(new InteractionPromptPlugin())
  303. // change duration
  304. interactionPrompt.animationDuration = 3000
  305. // change animation distance in pixels
  306. interactionPrompt.animationDistance = 100
  307. // disable auto start when the camera stops
  308. interactionPrompt.autoStart = false
  309. interactionPrompt.autoStop = false
  310. // manually start and stop
  311. interactionPrompt.startAnimation()
  312. // ...
  313. interactionPrompt.stopAnimation()
  314. ```
  315. Note - The pointer is automatically shown/hidden when animation is started/stopped.
  316. ## TransformControlsPlugin
  317. [//]: # (todo: image)
  318. [Example](https://threepipe.org/examples/#transform-controls-plugin/) —
  319. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/interaction/TransformControlsPlugin.ts) —
  320. [API Reference](https://threepipe.org/docs/classes/TransformControlsPlugin.html)
  321. Transform Controls Plugin adds support for moving, rotating and scaling objects in the viewer with interactive widgets.
  322. Under the hood, TransformControlsPlugin uses [TransformControls2](https://threepipe.org/docs/classes/TransformControls2) to provide the interactive controls, it is a extended version of three.js [TransformControls](https://threejs.org/docs/#examples/en/controls/TransformControls).
  323. When the plugin is added to the viewer, it interfaces with the [PickingPlugin](#pickingplugin) and shows the control gizmos when an object is selected and hides them when the object is unselected.
  324. If the `PickingPlugin` is not added to the viewer before the `TransformControlsPlugin`, it is added automatically with the plugin.
  325. ```typescript
  326. import {ThreeViewer, TransformControlsPlugin} from 'threepipe'
  327. const viewer = new ThreeViewer({...})
  328. const transfromControlsPlugin = viewer.addPluginSync(new TransformControlsPlugin())
  329. // Get the underlying transform controls
  330. console.log(transfromControlsPlugin.transformControls)
  331. ```
  332. ## ContactShadowGroundPlugin
  333. [//]: # (todo: image)
  334. [Example](https://threepipe.org/examples/#contact-shadow-ground-plugin/) —
  335. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/extras/ContactShadowGroundPlugin.ts) —
  336. [API Reference](https://threepipe.org/docs/classes/ContactShadowGroundPlugin.html)
  337. Contact Shadow Ground Plugin adds a ground plane with three.js contact shadows to the viewer scene.
  338. The plane is added to the scene root at runtime and not saved with scene export. Instead the plugin settings are saved with the scene.
  339. It inherits from the base class [BaseGroundPlugin](https://threepipe.org/docs/classes/BaseGroundPlugin.html) which provides generic ground plane functionality. Check the source code for more details. With the property `autoAdjustTransform`, the ground plane is automatically adjusted based on the bounding box of the scene.
  340. ```typescript
  341. import {ThreeViewer, ContactShadowGroundPlugin} from 'threepipe'
  342. const viewer = new ThreeViewer({...})
  343. viewer.addPluginSync(new ContactShadowGroundPlugin())
  344. ```
  345. ## GLTFAnimationPlugin
  346. [//]: # (todo: image)
  347. [Example](https://threepipe.org/examples/#gltf-animation-plugin/) —
  348. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/animation/GLTFAnimationPlugin.ts) —
  349. [API Reference](https://threepipe.org/docs/classes/GLTFAnimationPlugin.html)
  350. Manages playback of GLTF animations.
  351. The GLTF animations can be created in any 3d software that supports GLTF export like Blender.
  352. If animations from multiple files are loaded, they will be merged in a single root object and played together.
  353. 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.
  354. 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.
  355. 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
  356. ## PopmotionPlugin
  357. [//]: # (todo: image)
  358. [Example](https://threepipe.org/examples/#popmotion-plugin/) —
  359. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/animation/PopmotionPlugin.ts) —
  360. [API Reference](https://threepipe.org/docs/classes/PopmotionPlugin.html)
  361. Provides animation/tweening capabilities to the viewer using the [popmotion.io](https://popmotion.io/) library.
  362. Overrides the driver in popmotion to sync with the viewer and provide ways to store and stop animations.
  363. ```typescript
  364. import {PopmotionPlugin, ThreeViewer} from 'threepipe'
  365. const viewer = new ThreeViewer({...})
  366. const cube = viewer.scene.getObjectByName('cube');
  367. const popmotion = viewer.addPluginSync(new PopmotionPlugin())
  368. // Move the object cube 1 unit up.
  369. const anim = popmotion.animateTarget(cube, 'position', {
  370. to: cube.position.clone().add(new Vector3(0,1,0)),
  371. duration: 500, // ms
  372. onComplete: () => isMovedUp = true,
  373. onStop: () => throw(new Error('Animation stopped')),
  374. })
  375. // Alternatively, set the property directly in onUpdate.
  376. const anim1 = popmotion.animate({
  377. from: cube.position.y,
  378. to: cube.position.y + 1,
  379. duration: 500, // ms
  380. onUpdate: (v) => {
  381. cube.position.setY(v)
  382. cube.setDirty()
  383. },
  384. onComplete: () => isMovedUp = true,
  385. onStop: () => throw(new Error('Animation stopped')),
  386. onEnd: () => console.log('Animation ended'), // This runs after both onComplete and onStop
  387. })
  388. // await for animation. This promise will reject only if an exception is thrown in onStop or onComplete. onStop rejects if throwOnStop is true
  389. await anim.promise.catch((e)=>{
  390. console.log(e, 'animation stopped before completion')
  391. });
  392. // or stop the animation
  393. // anim.stop()
  394. // Animate the color
  395. await popmotion.animateAsync({ // Also await for the animation.
  396. from: '#' + cube.material.color.getHexString(),
  397. to: '#' + new Color().setHSL(Math.random(), 1, 0.5).getHexString(),
  398. duration: 1000, // 1s
  399. onUpdate: (v) => {
  400. cube.material.color.set(v)
  401. cube.material.setDirty()
  402. },
  403. })
  404. ```
  405. Note: The animation is started when the animate or animateAsync function is called.
  406. ## CameraViewPlugin
  407. [//]: # (todo: image)
  408. [Example](https://threepipe.org/examples/#camera-view-plugin/) —
  409. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/animation/CameraViewPlugin.ts) —
  410. [API Reference](https://threepipe.org/docs/classes/CameraViewPlugin.html)
  411. CameraViewPlugin adds support to save and load camera views, which can then be animated to.
  412. It uses PopmotionPlugin internally to animate any camera to a saved view or to loop through all the saved views.
  413. It also provides a UI to manage the views.
  414. ```typescript
  415. import {CameraViewPlugin, ThreeViewer, CameraView, Vector3, Quaternion, EasingFunctions, timeout} from 'threepipe'
  416. const viewer = new ThreeViewer({...})
  417. const cameraViewPlugin = viewer.addPluginSync(new CameraViewPlugin())
  418. const intialView = cameraViewPlugin.getView()
  419. // or = viewer.scene.mainCamera.getView()
  420. // create a new view
  421. const view = new CameraView(
  422. 'My View', // name
  423. new Vector3(0, 0, 10), // position
  424. new Vector3(0, 0, 0), // target
  425. new Quaternion(0, 0, 0, 1), // quaternion rotation
  426. 1 // zoom
  427. )
  428. // or clone a view
  429. const view2 = intialView.clone()
  430. view2.position.add(new Vector3(0, 5, 0)) // move up 5 units
  431. // animate the main camera to a view
  432. await cameraViewPlugin.animateToView(
  433. view,
  434. 2000, // in ms, = 2sec
  435. EasingFunctions.easeInOut,
  436. ).catch(()=>console.log('Animation stopped'))
  437. // stop any/all animations
  438. cameraViewPlugin.stopAllAnimations()
  439. // add views to the plugin
  440. cameraViewPlugin.addView(view)
  441. cameraViewPlugin.addView(view2)
  442. cameraViewPlugin.addView(intialView)
  443. cameraViewPlugin.addCurrentView() // adds the current view of the main camera
  444. // loop through all the views once
  445. cameraViewPlugin.animDuration = 2000 // default duration
  446. cameraViewPlugin.animEase = EasingFunctions.easeInOutSine // default easing
  447. await cameraViewPlugin.animateAllViews()
  448. // loop through all the views forever
  449. cameraViewPlugin.viewLooping = true
  450. await timeout(10000) // wait for some time
  451. // stop looping
  452. cameraViewPlugin.viewLooping = false
  453. ```
  454. ## TransformAnimationPlugin
  455. [//]: # (todo: image)
  456. [Example](https://threepipe.org/examples/#transform-animation-plugin/) —
  457. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/animation/TransformAnimationPlugin.ts) —
  458. [API Reference](https://threepipe.org/docs/classes/TransformAnimationPlugin.html)
  459. TransformAnimationPlugin adds support to save and load transform(position, rotation, scale) states for objects in the scene, which can then be animated to.
  460. It uses PopmotionPlugin internally to animate any object to a saved transform object.
  461. The transformations are saved in the object userData, and can be created and interacted with from the plugin.
  462. It also provides a UI to manage the states, this UI is added to the object's uiConfig and can be accessed using the object UI or PickingPlugin. Check the example for a working demo.
  463. Sample Usage -
  464. ```javascript
  465. import {TransformAnimationPlugin, ThreeViewer, Vector3, Quaternion, EasingFunctions, timeout} from 'threepipe'
  466. const viewer = new ThreeViewer({...})
  467. const model = viewer.scene.getObjectByName('model')
  468. const transformAnim = viewer.addPluginSync(new TransformAnimationPlugin())
  469. // Save the current state of the model as a transform
  470. transformAnim.addTransform(model, 'initial')
  471. // Rotate/Move the model and save other transform states
  472. // left
  473. model.rotation.set(0, Math.PI / 2, 0)
  474. model.setDirty?.()
  475. transformAnim.addTransform(model, 'left')
  476. // top
  477. model.rotation.set(Math.PI / 2, 0, 0)
  478. model.setDirty?.()
  479. transformAnim.addTransform(model, 'top')
  480. // up
  481. model.position.set(0, 2, 0)
  482. model.lookAt(viewer.scene.mainCamera.position)
  483. model.setDirty?.()
  484. transformAnim.addTransform(model, 'up')
  485. // animate to a transform(from current position) in 1 sec
  486. const anim = transformAnim.animateTransform(model, 'left', 1000)
  487. // to stop the animation
  488. // anim.stop()
  489. // wait for the animation to finish
  490. await anim.promise
  491. // set a transform without animation
  492. transformAnim.setTransform(model, 'top')
  493. // await directly.
  494. await transformAnim.animateToTransform(model, 'up', 1000)?.promise
  495. ```
  496. ## RenderTargetPreviewPlugin
  497. [//]: # (todo: image)
  498. [Example](https://threepipe.org/examples/#render-target-preview/) —
  499. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/ui/RenderTargetPreviewPlugin.ts) —
  500. [API Reference](https://threepipe.org/docs/classes/RenderTargetPreviewPlugin.html)
  501. RenderTargetPreviewPlugin is a useful development and debugging plugin that renders any registered render-target to the screen in small collapsable panels.
  502. ```typescript
  503. import {ThreeViewer, RenderTargetPreviewPlugin, NormalBufferPlugin} from 'threepipe'
  504. const viewer = new ThreeViewer({...})
  505. const normalPlugin = viewer.addPluginSync(new NormalBufferPlugin(HalfFloatType))
  506. const previewPlugin = viewer.addPluginSync(new RenderTargetPreviewPlugin())
  507. // Show the normal buffer in a panel
  508. previewPlugin.addTarget(()=>normalPlugin.target, 'normal', false, false)
  509. ```
  510. ## GeometryUVPreviewPlugin
  511. [//]: # (todo: image)
  512. [Example](https://threepipe.org/examples/#geometry-uv-preview/) —
  513. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/ui/GeometryUVPreviewPlugin.ts) —
  514. [API Reference](https://threepipe.org/docs/classes/GeometryUVPreviewPlugin.html)
  515. GeometryUVPreviewPlugin is a useful development and debugging plugin
  516. that adds a panel to the viewer to show the UVs of a geometry.
  517. ```typescript
  518. import {ThreeViewer, GeometryUVPreviewPlugin, SphereGeometry} from 'threepipe'
  519. const viewer = new ThreeViewer({...})
  520. const previewPlugin = viewer.addPluginSync(new GeometryUVPreviewPlugin())
  521. const geometry = new SphereGeometry(1, 32, 32)
  522. // Show the normal buffer in a panel
  523. previewPlugin.addGeometry(geometry, 'sphere')
  524. ```
  525. ## FrameFadePlugin
  526. [//]: # (todo: image)
  527. [Example](https://threepipe.org/examples/#frame-fade-plugin/) —
  528. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/pipeline/FrameFadePlugin.ts) —
  529. [API Reference](https://threepipe.org/docs/classes/FrameFadePlugin.html)
  530. 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.
  531. ```typescript
  532. import {ThreeViewer, FrameFadePlugin} from 'threepipe'
  533. const viewer = new ThreeViewer({...})
  534. const fadePlugin = viewer.addPluginSync(new FrameFadePlugin())
  535. // Make some changes in the scene (any visual change that needs to be faded)
  536. // Start transition and wait for it to finish
  537. await fadePlugin.startTransition(400) // duration in ms
  538. ```
  539. 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.
  540. 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.
  541. ## VignettePlugin
  542. [//]: # (todo: image)
  543. [Example](https://threepipe.org/examples/#vignette-plugin/) —
  544. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/postprocessing/VignettePlugin.ts) —
  545. [API Reference](https://threepipe.org/docs/classes/VignettePlugin.html)
  546. VignettePlugin adds a post-processing material extension to the ScreenPass in render manager
  547. that applies a vignette effect to the final render. The parameters `power` and `color` can be changed to customize the effect.
  548. ```typescript
  549. import {ThreeViewer, VignettePlugin} from 'threepipe'
  550. const viewer = new ThreeViewer({...})
  551. const vignettePlugin = viewer.addPluginSync(VignettePlugin)
  552. // Change the vignette color
  553. vignettePlugin.power = 1
  554. vignettePlugin.color = new Color(0.5, 0, 0)
  555. // or
  556. // vignettePlugin.color.set('#ff0000'); vignettePlugin.setDirty() // Call setDirty to tell the plugin that color has changed
  557. ```
  558. ## ChromaticAberrationPlugin
  559. [//]: # (todo: image)
  560. [Example](https://threepipe.org/examples/#chromatic-aberration-plugin/) —
  561. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/postprocessing/ChromaticAberrationPlugin.ts) —
  562. [API Reference](https://threepipe.org/docs/classes/ChromaticAberrationPlugin.html)
  563. ChromaticAberrationPlugin adds a post-processing material extension to the ScreenPass in render manager
  564. that applies a chromatic-aberration effect to the final render. The parameter `intensity` can be changed to customize the effect.
  565. ```typescript
  566. import {ThreeViewer, ChromaticAberrationPlugin} from 'threepipe'
  567. const viewer = new ThreeViewer({...})
  568. const chromaticAberrationPlugin = viewer.addPluginSync(ChromaticAberrationPlugin)
  569. // Change the chromaticAberration color
  570. chromaticAberrationPlugin.intensity = 0.5
  571. ```
  572. ## FilmicGrainPlugin
  573. [//]: # (todo: image)
  574. [Example](https://threepipe.org/examples/#filmic-grain-plugin/) —
  575. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/postprocessing/FilmicGrainPlugin.ts) —
  576. [API Reference](https://threepipe.org/docs/classes/FilmicGrainPlugin.html)
  577. FilmicGrainPlugin adds a post-processing material extension to the ScreenPass in render manager
  578. that applies a filmic-grain effect to the final render. The parameters `power` and `color` can be changed to customize the effect.
  579. ```typescript
  580. import {ThreeViewer, FilmicGrainPlugin} from 'threepipe'
  581. const viewer = new ThreeViewer({...})
  582. const filmicGrainPlugin = viewer.addPluginSync(FilmicGrainPlugin)
  583. // Change the filmicGrain color
  584. filmicGrainPlugin.intensity = 10
  585. filmicGrainPlugin.multiply = false
  586. ```
  587. ## NoiseBumpMaterialPlugin
  588. [//]: # (todo: image)
  589. [Example](https://threepipe.org/examples/#noise-bump-material-plugin/) —
  590. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/material/NoiseBumpMaterialPlugin.ts) —
  591. [API Reference](https://threepipe.org/docs/classes/NoiseBumpMaterialPlugin.html)
  592. NoiseBumpMaterialPlugin adds a material extension to PhysicalMaterial to add support for sparkle bump / noise bump by creating procedural bump map from noise to simulate sparkle flakes.
  593. It uses voronoise function from blender along with several additions to generate the noise for the generation.
  594. It also adds a UI to the material to edit the settings.
  595. It uses `WEBGI_materials_noise_bump` glTF extension to save the settings in glTF/glb files.
  596. ```typescript
  597. import {ThreeViewer, NoiseBumpMaterialPlugin} from 'threepipe'
  598. const viewer = new ThreeViewer({...})
  599. const noiseBump = viewer.addPluginSync(NoiseBumpMaterialPlugin)
  600. // Add noise bump to a material
  601. NoiseBumpMaterialPlugin.AddNoiseBumpMaterial(material, {
  602. flakeScale: 300,
  603. })
  604. // Change properties with code or use the UI
  605. material.userData._noiseBumpMat!.bumpNoiseParams = [1, 1]
  606. material.setDirty()
  607. // Disable
  608. material.userData._noiseBumpMat!.hasBump = false
  609. material.setDirty()
  610. ```
  611. ## CustomBumpMapPlugin
  612. [//]: # (todo: image)
  613. [Example](https://threepipe.org/examples/#custom-bump-map-plugin/) —
  614. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/material/CustomBumpMapPlugin.ts) —
  615. [API Reference](https://threepipe.org/docs/classes/CustomBumpMapPlugin.html)
  616. CustomBumpMapPlugin adds a material extension to PhysicalMaterial to support custom bump maps.
  617. A Custom bump map is similar to the built-in bump map, but allows using an extra bump map and scale to give a combined effect.
  618. This plugin also has support for bicubic filtering of the custom bump map and is enabled by default.
  619. It also adds a UI to the material to edit the settings.
  620. It uses `WEBGI_materials_custom_bump_map` glTF extension to save the settings in glTF/glb files.
  621. ```typescript
  622. import {ThreeViewer, CustomBumpMapPlugin} from 'threepipe'
  623. const viewer = new ThreeViewer({...})
  624. const customBump = viewer.addPluginSync(CustomBumpMapPlugin)
  625. // Add noise bump to a material
  626. customBump.enableCustomBump(material, bumpMap, 0.2)
  627. // Change properties with code or use the UI
  628. material.userData._customBumpMat = texture
  629. material.setDirty()
  630. // Disable
  631. material.userData._hasCustomBump = false
  632. // or
  633. material.userData._customBumpMat = null
  634. material.setDirty()
  635. ```
  636. ## ClearcoatTintPlugin
  637. [//]: # (todo: image)
  638. [Example](https://threepipe.org/examples/#clearcoat-tint-plugin/) —
  639. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/material/ClearcoatTintPlugin.ts) —
  640. [API Reference](https://threepipe.org/docs/classes/ClearcoatTintPlugin.html)
  641. ClearcoatTintPlugin adds a material extension to PhysicalMaterial which adds tint and thickness to the built-in clearcoat properties.
  642. It also adds a UI to the material to edit the settings.
  643. It uses `WEBGI_materials_clearcoat_tint` glTF extension to save the settings in glTF/glb files.
  644. ```typescript
  645. import {ThreeViewer, ClearcoatTintPlugin} from 'threepipe'
  646. const viewer = new ThreeViewer({...})
  647. const clearcoatTint = viewer.addPluginSync(ClearcoatTintPlugin)
  648. material.clearcoat = 1
  649. // add initial properties
  650. ClearcoatTintPlugin.AddClearcoatTint(material, {
  651. tintColor: '#ff0000',
  652. thickness: 1,
  653. })
  654. // Change properties with code or use the UI
  655. material.userData._clearcoatTint!.tintColor = '#ff0000'
  656. material.setDirty()
  657. // Disable
  658. material.userData._clearcoatTint.enableTint = false
  659. material.setDirty()
  660. ```
  661. ## FragmentClippingExtensionPlugin
  662. [//]: # (todo: image)
  663. [Example](https://threepipe.org/examples/#fragment-clipping-extension-plugin/) —
  664. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/material/FragmentClippingExtensionPlugin.ts) —
  665. [API Reference](https://threepipe.org/docs/classes/FragmentClippingExtensionPlugin.html)
  666. FragmentClippingExtensionPlugin adds a material extension to PhysicalMaterial to add support for fragment clipping.
  667. Fragment clipping allows to clip fragments of the material in screen space or world space based on a circle, rectangle, plane, sphere, etc.
  668. It uses fixed SDFs with params defined by the user for clipping.
  669. It also adds a UI to the material to edit the settings.
  670. It uses `WEBGI_materials_fragment_clipping_extension` glTF extension to save the settings in glTF/glb files.
  671. ```typescript
  672. import {ThreeViewer, FragmentClippingExtensionPlugin} from 'threepipe'
  673. const viewer = new ThreeViewer({...})
  674. const fragmentClipping = viewer.addPluginSync(FragmentClippingExtensionPlugin)
  675. // add initial properties
  676. FragmentClippingExtensionPlugin.AddFragmentClipping(material, {
  677. clipPosition: new Vector4(0.5, 0.5, 0, 0),
  678. clipParams: new Vector4(0.1, 0.05, 0, 1),
  679. })
  680. // Change properties with code or use the UI
  681. material.userData._fragmentClipping!.clipPosition.set(0, 0, 0, 0)
  682. material.setDirty()
  683. // Disable
  684. material.userData._clearcoatTint.clipEnabled = false
  685. material.setDirty()
  686. ```
  687. ## ParallaxMappingPlugin
  688. [//]: # (todo: image)
  689. [Example](https://threepipe.org/examples/#parallax-mapping-plugin/) —
  690. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/material/ParallaxMappingPlugin.ts) —
  691. [API Reference](https://threepipe.org/docs/classes/ParallaxMappingPlugin.html)
  692. `ParallaxMappingPlugin` adds a material extension to PhysicalMaterial to add support for [parallax relief mapping](https://en.wikipedia.org/wiki/Relief_mapping_(computer_graphics)). The idea is to walk along a ray that has entered the bumpmap's volume, finding the intersection point of the ray with the bumpmap. [Steep parallax mapping](https://en.wikipedia.org/wiki/Parallax_mapping) and [parallax occlusion mapping](https://en.wikipedia.org/wiki/Parallax_occlusion_mapping) are other common names for these techniques.
  693. To use the plugin, add the plugin to the viewer and use the `bumpMap` in `PhysicalMaterial` normally. The max height is determined by the `bumpScale` in the material. This is assumed to be in world scale.
  694. ```typescript
  695. import {ThreeViewer, ParallaxMappingPlugin} from 'threepipe'
  696. const viewer = new ThreeViewer({...})
  697. const parallaxMapping = viewer.addPluginSync(ParallaxMappingPlugin)
  698. // load or create an object
  699. // set the bump map
  700. object.material.bumpMap = await viewer.load<ITexture>(bumps[0]) || null
  701. // set the bump scale
  702. object.material.bumpScale = 0.1
  703. // setDirty to notify the viewer to update.
  704. object.material.setDirty()
  705. ```
  706. ### References and related links:
  707. - WebGL implementation by Rabbid76 - [github.com/Rabbid76/graphics-snippets](https://github.com/Rabbid76/graphics-snippets/blob/master/html/technique/parallax_005_parallax_relief_mapping_derivative_tbn.html)
  708. - Lesson on Parallax Occlusion Mapping in GLSL - [http://sunandblackcat.com/tipFullView.php?topicid=28](https://web.archive.org/web/20190128023901/http://sunandblackcat.com/tipFullView.php?topicid=28)
  709. - Learn OpenGL - https://learnopengl.com/Advanced-Lighting/Parallax-Mapping
  710. ## HDRiGroundPlugin
  711. [//]: # (todo: image)
  712. [Example](https://threepipe.org/examples/#hdri-ground-plugin/) &mdash;
  713. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/extras/HDRiGroundPlugin.ts) &mdash;
  714. [API Reference](https://threepipe.org/docs/classes/HDRiGroundPlugin.html)
  715. HDRiGroundPlugin patches the background shader in the renderer to add support for ground projected environment map/skybox. Works simply by setting the background same as the environemnt and enabling the plugin.
  716. The world radius, tripod height, and origin position(center offset) can be set in the plugin.
  717. The plugin is disabled by default when added. Set `.enabled` to enable it or pass `true` in the constructor.
  718. If the background is not the same as the environment when enabled, the user will be prompted for this, unless `promptOnBackgroundMismatch` is set to `false` in the plugin.
  719. ```typescript
  720. import {ThreeViewer, HDRiGrounPlugin} from 'threepipe'
  721. const viewer = new ThreeViewer({...})
  722. const hdriGround = viewer.addPluginSync(new HDRiGrounPlugin())
  723. // Load an hdr environment map
  724. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  725. // set background to environment
  726. viewer.scene.background = 'environment'
  727. // or
  728. // viewer.scene.background = viewer.scene.environemnt
  729. // enable the plugin
  730. hdriGround.enabled = true
  731. ```
  732. Check the [example](https://threepipe.org/examples/#hdri-ground-plugin/) for a demo.
  733. ## VirtualCamerasPlugin
  734. [//]: # (todo: image)
  735. [Example](https://threepipe.org/examples/#virtual-cameras-plugin/) &mdash;
  736. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/rendering/VirtualCamerasPlugin.ts) &mdash;
  737. [API Reference](https://threepipe.org/docs/classes/VirtualCamerasPlugin.html)
  738. VirtualCamerasPlugin adds support for rendering to multiple virtual cameras in the viewer. These cameras are rendered in preRender callback just before the main camera is rendered. The virtual cameras can be added to the plugin and removed from it.
  739. The feed to the virtual camera is rendered to a Render Target texture which can be accessed and re-rendered in the scene or used in other plugins.
  740. ```typescript
  741. import {ThreeViewer, VirtualCamerasPlugin} from 'threepipe'
  742. const viewer = new ThreeViewer({...})
  743. const virtualCameras = viewer.addPluginSync(new VirtualCamerasPlugin())
  744. const camera = new PerspectiveCamera2('orbit', viewer.canvas, false, 45, 1)
  745. camera.name = name
  746. camera.position.set(0, 5, 0)
  747. camera.target.set(0, 0.25, 0)
  748. camera.userData.autoLookAtTarget = true // automatically look at the target (in setDirty)
  749. camera.setDirty()
  750. camera.addEventListener('update', ()=>{
  751. viewer.setDirty() // if the camera is not added to the scene it wont update automatically when camera.setDirty is called(like from the UI)
  752. })
  753. const vCam = virtualCameras.addCamera(camera)
  754. console.log(vCam.target) // target is a WebGLRenderTarget/IRenderTarget
  755. ```
  756. Check the [virtual camera](https://threepipe.org/examples/#virtual-camera/) example for using the texture in the scene.
  757. ## EditorViewWidgetPlugin
  758. [//]: # (todo: image)
  759. [Example](https://threepipe.org/examples/#editor-view-widget-plugin/) &mdash;
  760. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/interaction/EditorViewWidgetPlugin.ts) &mdash;
  761. [API Reference](https://threepipe.org/docs/classes/EditorViewWidgetPlugin.html)
  762. EditorViewWidgetPlugin adds a ViewHelper in the parent of the viewer canvas to show the current camera view and allow the user to change the camera view to one of the primary world axes.
  763. Simply add the plugin to the viewer to see the widget.
  764. ```typescript
  765. import {ThreeViewer, EditorViewWidgetPlugin} from 'threepipe'
  766. const viewer = new ThreeViewer({...})
  767. const plugin = viewer.addPluginSync(new EditorViewWidgetPlugin())
  768. // to hide the widget
  769. plugin.enabled = false
  770. ```
  771. ## Object3DWidgetsPlugin
  772. [//]: # (todo: image)
  773. [Example](https://threepipe.org/examples/#object3d-widgets-plugin/) &mdash;
  774. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/extras/Object3DWidgetsPlugin.ts) &mdash;
  775. [API Reference](https://threepipe.org/docs/classes/Object3DWidgetsPlugin.html)
  776. Object3DWidgetsPlugin adds support for light and camera helpers/gizmos in the viewer.
  777. A helper is automatically created when any supported light or camera is added to the scene.
  778. Simply add the plugin to the viewer to see the widget.
  779. Support for additional types of helpers can be added dynamically or by other plugins by pushing a helper constructor to the `Object3DWidgetsPlugin.helpers` array, and calling `Object3DWidgetsPlugin.refresh()`.
  780. The helper class prototype should implement the `IObject3DHelper` interface. Check `DirectionalLightHelper2` for an example.
  781. ```typescript
  782. import {ThreeViewer, Object3DWidgetsPlugin, Object3DGeneratorPlugin} from 'threepipe'
  783. const viewer = new ThreeViewer({...})
  784. // Add the plugin to add support
  785. const plugin = viewer.addPluginSync(new Object3DWidgetsPlugin())
  786. // Add some lights or cameras to the scene. (This can be done before adding the plugin as well)
  787. // Using Object3DGeneratorPlugin to create a camera and add it to the scene.
  788. const generator = viewer.getOrAddPluginSync(Object3DGeneratorPlugin)
  789. generator.generate('camera-perspective', {
  790. position: new Vector3(5, 5, 0),
  791. name: 'My Camera'
  792. })
  793. // to hide the widgets
  794. plugin.enabled = false
  795. // to add support for a custom helper
  796. plugin.helpers.push(MyCustomHelper)
  797. plugin.refresh()
  798. ```
  799. ## Object3DGeneratorPlugin
  800. [//]: # (todo: image)
  801. [Example](https://threepipe.org/examples/#object3d-generator-plugin/) &mdash;
  802. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/extras/Object3DGeneratorPlugin.ts) &mdash;
  803. [API Reference](https://threepipe.org/docs/classes/Object3DGeneratorPlugin.html)
  804. Object3DGeneratorPlugin adds support for creating different types of lights and camera objects in the viewer.
  805. Call the `generate` method with any type to generate a type of object(like lights, cameras, mesh etc).
  806. Support for the following types of generators is included in the plugin:
  807. * camera-perspective - Creates instance of `PerspectiveCamera2`
  808. * light-directional - Creates instance of `DirectionalLight2`
  809. * light-ambient - Creates instance of `AmbientLight2`
  810. * light-point - Creates instance of `PointLight2`
  811. * light-spot - Creates instance of `SpotLight2`
  812. * light-hemisphere - Creates instance of `HemisphereLight2`
  813. * light-rect-area - Creates instance of `RectAreaLight2`
  814. Additional types of generators can be added dynamically or by other plugins by adding a custom generator function to the `Object3DGeneratorPlugin.generators` object. This is done by [GeometryGeneratorPlugin](#threepipeplugin-geometry-generator) to add various type of primitive objects like plane, sphere, etc
  815. A custom generator can take in any kind object as parameters and should return an `IObject3D`.
  816. Sample Usage
  817. ```typescript
  818. import {ThreeViewer, Object3DWidgetsPlugin, Object3DGeneratorPlugin, Mesh2} from 'threepipe'
  819. const viewer = new ThreeViewer({...})
  820. const generator = viewer.addPluginSync(Object3DGeneratorPlugin)
  821. generator.generate('camera-perspective', {
  822. position: new Vector3(5, 5, 0),
  823. name: 'My Camera'
  824. })
  825. const light = generator.generate('light-spot', {
  826. position: new Vector3(5, 0, 0),
  827. })
  828. // to add support for a custom helper
  829. plugin.generators['custom-object'] = (params)=>{
  830. const object = new Mesh2(new PlaneGeometry(1,1), new PhysicalMaterial())
  831. object.name = params.name ?? 'Custom Mesh'
  832. if(params.position) object.position.copy(params.position)
  833. return object
  834. }
  835. const obj = generator.generate('custom-object', {
  836. position: new Vector3(5, 0, 0),
  837. })
  838. // Add Object3DWidgetsPlugin to see the added lights and cameras.
  839. viewer.addPluginSync(new Object3DWidgetsPlugin())
  840. ```
  841. Check the [example](https://threepipe.org/examples/#object3d-generator-plugin/) for the UI.
  842. ## DeviceOrientationControlsPlugin
  843. [//]: # (todo: image)
  844. [Example](https://threepipe.org/examples/#device-orientation-controls-plugin/) &mdash;
  845. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/interaction/DeviceOrientationControlsPlugin.ts) &mdash;
  846. [API Reference](https://threepipe.org/docs/classes/DeviceOrientationControlsPlugin.html)
  847. DeviceOrientationControlsPlugin enables controlling the main camera rotation in the scene with device orientation. This only works on devices which have a gyroscope(but can also be emulated in devtools in chrome).
  848. After the plugin is added, it adds support for setting `deviceOrientation` as the key in `scene.mainCamera.controlMode`.
  849. When the controls is started (for the first time), the current camera rotation is and the device orientation is saved and used as reference. To reset the saved device orientation, call `resetView` in the controls.
  850. Sample Usage
  851. ```typescript
  852. import {ThreeViewer, DeviceOrientationControlsPlugin, Mesh2} from 'threepipe'
  853. const viewer = new ThreeViewer({...})
  854. viewer.addPluginSync(DeviceOrientationControlsPlugin)
  855. // after some user action
  856. viewer.scene.mainCamera.controlsMode = 'deviceOrientation'
  857. // to reset the saved device orientation
  858. viewer.scene.mainCamera.controls.resetView()
  859. // switch back to default orbit controls
  860. viewer.scene.mainCamera.controlsMode = 'orbit'
  861. ```
  862. ## PointerLockControlsPlugin
  863. [//]: # (todo: image)
  864. [Example](https://threepipe.org/examples/#pointer-lock-controls-plugin/) &mdash;
  865. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/interaction/PointerLockControlsPlugin.ts) &mdash;
  866. [API Reference](https://threepipe.org/docs/classes/PointerLockControlsPlugin.html)
  867. PointerLockControlsPlugin adds support for using PointerLockControls from three.js. It works similar to controls in first person shooter, captures the mouse pointer and uses it to look around with the camera.
  868. After the plugin is added, it adds support for setting `pointerLock` as the key in `scene.mainCamera.controlMode`.
  869. Sample Usage
  870. ```typescript
  871. import {ThreeViewer, PointerLockControlsPlugin, Mesh2} from 'threepipe'
  872. const viewer = new ThreeViewer({...})
  873. viewer.addPluginSync(PointerLockControlsPlugin)
  874. // after some user action
  875. viewer.scene.mainCamera.controlsMode = 'pointerLock'
  876. // listen to lock/unlock events
  877. viewer.scene.mainCamera.controls?.addEventListener('lock', ()=> console.log('pointer locked'))
  878. viewer.scene.mainCamera.controls?.addEventListener('unlock', ()=> console.log('pointer unlocked'))
  879. // switch back to default orbit controls
  880. viewer.scene.mainCamera.controlsMode = 'orbit'
  881. ```
  882. ## ThreeFirstPersonControlsPlugin
  883. [//]: # (todo: image)
  884. [Example](https://threepipe.org/examples/#three-first-person-controls-plugin/) &mdash;
  885. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/interaction/ThreeFirstPersonControlsPlugin.ts) &mdash;
  886. [API Reference](https://threepipe.org/docs/classes/ThreeFirstPersonControlsPlugin.html)
  887. ThreeFirstPersonControlsPlugin adds support for using FirstPersonControls from three.js. It works similar to idle look around in first person games, it does not captures the mouse pointer.
  888. After the plugin is added, it adds support for setting `threeFirstPerson` as the key in `scene.mainCamera.controlMode`.
  889. Sample Usage
  890. ```typescript
  891. import {ThreeViewer, ThreeFirstPersonControlsPlugin, Mesh2} from 'threepipe'
  892. const viewer = new ThreeViewer({...})
  893. viewer.addPluginSync(ThreeFirstPersonControlsPlugin)
  894. // after some user action
  895. viewer.scene.mainCamera.controlsMode = 'threeFirstPerson'
  896. // switch back to default orbit controls
  897. viewer.scene.mainCamera.controlsMode = 'orbit'
  898. ```
  899. ## GLTFKHRMaterialVariantsPlugin
  900. [//]: # (todo: image)
  901. [Example](https://threepipe.org/examples/#gltf-khr-material-variants-plugin/) &mdash;
  902. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/extras/GLTFKHRMaterialVariantsPlugin.ts) &mdash;
  903. [API Reference](https://threepipe.org/docs/classes/GLTFKHRMaterialVariantsPlugin.html)
  904. GLTFKHRMaterialVariantsPlugin adds support for importing and exporting glTF models with the `KHR_materials_variants` extension to load the model with different material variants/combinations. It also provides API and UI to change the current material variant.
  905. The plugin automatically adds support for the extension when added to the viewer.
  906. The materials are stored in `object.userData._variantMaterials` and are automatically loaded and saved when using the `GLTFLoader`.
  907. Sample Usage
  908. ```typescript
  909. import {ThreeViewer, GLTFKHRMaterialVariantsPlugin, Mesh2} from 'threepipe'
  910. const viewer = new ThreeViewer({...})
  911. const variantsPlugin = viewer.addPluginSync(GLTFKHRMaterialVariantsPlugin)
  912. // load some model
  913. await viewer.load(model_url)
  914. // list of all variants in the model (names and objects)
  915. console.log(variantsPlugin.variants)
  916. // change the selected variant
  917. variantsPlugin.selectedVariant = 'beach'
  918. ```
  919. ### Links
  920. - https://www.khronos.org/blog/blender-gltf-i-o-support-for-gltf-pbr-material-extensions
  921. - https://www.khronos.org/blog/streamlining-3d-commerce-with-material-variant-support-in-gltf-assets
  922. - https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_variants/README.md
  923. ## Rhino3dmLoadPlugin
  924. [Example](https://threepipe.org/examples/#rhino3dm-load/) &mdash;
  925. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/import/Rhino3dmLoadPlugin.ts) &mdash;
  926. [API Reference](https://threepipe.org/docs/classes/Rhino3dmLoadPlugin.html)
  927. 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.
  928. It also adds some helpful options to process the model after load.
  929. ```typescript
  930. import {Rhino3dmLoadPlugin} from 'threepipe'
  931. const rhino3dmPlugin = viewer.addPluginSync(new Rhino3dmLoadPlugin())
  932. rhino3dmPlugin.importMaterials = true // import materials source from 3dm file
  933. rhino3dmPlugin.forceLayerMaterials = true // force material source to be layer in 3dm file.
  934. rhino3dmPlugin.hideLineMesh = true // hide all lines and points in the model.
  935. rhino3dmPlugin.replaceWithInstancedMesh = true // replace meshes with the same parent, geometry and material with a single instance mesh.
  936. const mesh = await viewer.load('file.3dm')
  937. ```
  938. ## PLYLoadPlugin
  939. [Example](https://threepipe.org/examples/#ply-load/) &mdash;
  940. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/import/PLYLoadPlugin.ts) &mdash;
  941. [API Reference](https://threepipe.org/docs/classes/PLYLoadPlugin.html)
  942. Adds support for loading .ply ([Polygon file format](https://en.wikipedia.org/wiki/PLY_(file_format))) files.
  943. ```typescript
  944. import {PLYLoadPlugin} from 'threepipe'
  945. viewer.addPluginSync(new PLYLoadPlugin())
  946. const mesh = await viewer.load('file.ply')
  947. ```
  948. ## USDZLoadPlugin
  949. [Example](https://threepipe.org/examples/#usdz-load/) &mdash;
  950. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/import/USDZLoadPlugin.ts) &mdash;
  951. [API Reference](https://threepipe.org/docs/classes/USDZLoadPlugin.html)
  952. Adds support for loading .usdz and .usda ([Universal Scene Description](https://graphics.pixar.com/usd/docs/index.html)) files.
  953. ```typescript
  954. import {USDZLoadPlugin} from 'threepipe'
  955. viewer.addPluginSync(new USDZLoadPlugin())
  956. const mesh = await viewer.load('file.usdz')
  957. const mesh2 = await viewer.load('file.usda')
  958. ```
  959. ## STLLoadPlugin
  960. [Example](https://threepipe.org/examples/#stl-load/) &mdash;
  961. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/import/STLLoadPlugin.ts) &mdash;
  962. [API Reference](https://threepipe.org/docs/classes/STLLoadPlugin.html)
  963. Adds support for loading .stl ([Stereolithography](https://en.wikipedia.org/wiki/STL_(file_format))) files.
  964. ```typescript
  965. import {STLLoadPlugin} from 'threepipe'
  966. viewer.addPluginSync(new STLLoadPlugin())
  967. const mesh = await viewer.load('file.stl')
  968. ```
  969. ## KTX2LoadPlugin
  970. [Example](https://threepipe.org/examples/#ktx2-load/) &mdash;
  971. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/import/KTX2LoadPlugin.ts) &mdash;
  972. [API Reference](https://threepipe.org/docs/classes/KTX2LoadPlugin.html)
  973. Adds support for loading .ktx2 ([Khronos Texture](https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/) files with asset manager and embedded in glTF files.
  974. 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.
  975. ```typescript
  976. import {KTX2LoadPlugin} from 'threepipe'
  977. viewer.addPluginSync(new KTX2LoadPlugin())
  978. const texture = await viewer.load('file.ktx2')
  979. ```
  980. ## KTXLoadPlugin
  981. [Example](https://threepipe.org/examples/#ktx-load/) &mdash;
  982. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/import/KTXLoadPlugin.ts) &mdash;
  983. [API Reference](https://threepipe.org/docs/classes/KTXLoadPlugin.html)
  984. Adds support for loading .ktx ([Khronos Texture](https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/) files.
  985. 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.
  986. ```typescript
  987. import {KTXLoadPlugin} from 'threepipe'
  988. viewer.addPluginSync(new KTXLoadPlugin())
  989. const texture = await viewer.load('file.ktx')
  990. ```
  991. ## GLTFMeshOptDecodePlugin
  992. [Example](https://threepipe.org/examples/#gltf-meshopt-compression/) &mdash;
  993. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/import/GLTFMeshOptDecodePlugin.ts) &mdash;
  994. [API Reference](https://threepipe.org/docs/classes/GLTFMeshOptDecodePlugin.html)
  995. Loads the MeshOpt Decoder module from [meshoptimizer](https://github.com/zeux/meshoptimizer) library at runtime from a customisable cdn url.
  996. The loaded module is set in `window.MeshoptDecoder` and then used by `GLTFLoader2` to decode files using [EXT_meshopt_compression](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_meshopt_compression/README.md) extension
  997. ```typescript
  998. import {GLTFMeshOptDecodePlugin} from 'threepipe'
  999. const plugin = viewer.addPluginSync(new GLTFMeshOptDecodePlugin())
  1000. // await plugin.initialize() // optional, this happens when loading a gltf file with extension anyway
  1001. const texture = await viewer.load('file.glb')
  1002. ```
  1003. ## SimplifyModifierPlugin
  1004. [Example](https://threepipe.org/examples/#simplify-modifier-plugin/) &mdash;
  1005. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/extras/SimplifyModifierPlugin.ts) &mdash;
  1006. [API Reference](https://threepipe.org/docs/classes/SimplifyModifierPlugin.html)
  1007. Boilerplate for implementing a plugin for simplifying geometries.
  1008. This is a base class and cannot be used directly.
  1009. A sample to use it:
  1010. ```typescript
  1011. class SimplifyModifierPluginImpl extends SimplifyModifierPlugin {
  1012. protected _simplify(geometry: IGeometry, count: number) {
  1013. return new SimplifyModifier().modify(geometry, count) as IGeometry
  1014. }
  1015. }
  1016. const plugin = viewer.addPluginSync(new SimplifyModifierPluginImpl())
  1017. const root = await viewer.load('file.glb')
  1018. plugin.simplifyAll(root, {factor: 0.75})
  1019. ```
  1020. Check the [example](https://threepipe.org/examples/#simplify-modifier-plugin/) for full implementation.
  1021. ## MeshOptSimplifyModifierPlugin
  1022. [Example](https://threepipe.org/examples/#meshopt-simplify-modifier-plugin/) &mdash;
  1023. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/extras/MeshOptSimplifyModifierPlugin.ts) &mdash;
  1024. [API Reference](https://threepipe.org/docs/classes/MeshOptSimplifyModifierPlugin.html)
  1025. Simplify modifier using [meshoptimizer](https://github.com/zeux/meshoptimizer) library. It Loads the library at runtime from a customisable CDN URL.
  1026. Note: It does not guarantee that the geometry will be simplified to the exact target count.
  1027. ```typescript
  1028. const simplifyModifier = viewer.addPluginSync(new MeshOptSimplifyModifierPlugin())
  1029. const root = await viewer.load('file.glb')
  1030. simplifyModifier.simplifyAll(root, {factor: 0.75})
  1031. ```