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

plugin-gltf-transform.md 4.1KB

1 год назад
1 год назад
1 год назад
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ---
  2. prev:
  3. text: '@threepipe/plugin-geometry-generator'
  4. link: './plugin-geometry-generator'
  5. next:
  6. text: '@threepipe/plugins-extra-importers'
  7. link: './plugins-extra-importers'
  8. ---
  9. # @threepipe/plugin-gltf-transform
  10. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/gltf-transform/src/index.ts) —
  11. [API Reference](https://threepipe.org/plugins/gltf-transform/docs)
  12. [![NPM Package](https://img.shields.io/npm/v/@threepipe/plugin-gltf-transform.svg)](https://www.npmjs.com/package/@threepipe/plugin-gltf-transform)
  13. ```bash
  14. npm install @threepipe/plugin-gltf-transform
  15. ```
  16. ## GLTFDracoExportPlugin
  17. Exports [GLTFDracoExportPlugin](https://threepipe.org/plugins/gltf-transform/docs/classes/GLTFDracoExportPlugin.html) that extends the default gltf exporter to compress the file (using [KHR_draco_mesh_compression](https://github.com/KhronosGroup/gltf/tree/main/extensions/2.0/Khronos/KHR_draco_mesh_compression)) after export.
  18. [Example](https://threepipe.org/examples/#glb-draco-export/) —
  19. To use, simply add the plugin to the viewer and export using the `viewer.export` or `viewer.exportScene` functions. This also adds UI options to `AssetExporterPlugin` which are used when exporting using the plugin or using `viewer.exportScene`
  20. The plugin overloads the default gltf exporter in the asset manager with `GLTFDracoExporter`. Using the [gltf-transform](https://gltf-transform.donmccurdy.com/) library, it compresses the exported gltf file using the [khr_draco_mesh_compression](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md) extension.
  21. Note - Only `glb` export supported right now.
  22. Sample Usage:
  23. ```typescript
  24. import {ThreeViewer, downloadBlob} from 'threepipe'
  25. import {GLTFDracoExportPlugin} from '@threepipe/plugin-gltf-transform'
  26. const viewer = new ThreeViewer({...})
  27. viewer.addPluginSync(GLTFDracoExportPlugin)
  28. await viewer.load('file.glb')
  29. const blob = await viewer.exportScene({
  30. compress: true, // this must be specified, by default it's false.
  31. viewerConfig: true, // to export with viewer, scene and plugin settings
  32. })
  33. // download the file
  34. downloadBlob(blob, 'scene.glb')
  35. ```
  36. ## GLTFSpecGlossinessConverterPlugin
  37. [GLTFSpecGlossinessConverterPlugin](https://threepipe.org/plugins/gltf-transform/docs/classes/GLTFSpecGlossinessConverterPlugin.html) that extends the default gltf exporter to compress the file after export.
  38. [Example](https://threepipe.org/examples/#gltf-spec-gloss-import/)
  39. ```bash
  40. npm install @threepipe/plugin-gltf-transform
  41. ```
  42. Plugin that adds a gltf loader extension that automatically converts GLTF files with specular glossiness materials ([KHR_materials_pbrSpecularGlossiness](https://kcoley.github.io/glTF/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/)) to metallic roughness during import.
  43. To use this plugin, simply add it to the viewer and import a file with `viewer.load` with specular glossiness materials.
  44. If `confirm` is set to true, a confirmation dialog will be shown before the conversion.
  45. To disable confirmation while loading a specific file, it can be passed as an option to `viewer.load`:
  46. Sample Usage:
  47. ```typescript
  48. import {ThreeViewer, downloadBlob} from 'threepipe'
  49. import {GLTFDracoExportPlugin, GLTFSpecGlossinessConverterPlugin} from '@threepipe/plugin-gltf-transform'
  50. const viewer = new ThreeViewer({...})
  51. viewer.addPluginSync(GLTFDracoExportPlugin)
  52. const plugin = viewer.addPluginSync(GLTFSpecGlossinessConverterPlugin) // it requires GLTFDracoExportPlugin
  53. plugin.confirm = true // show a confirmation dialog before conversion
  54. // customize the confirmation message
  55. plugin.confirmMessage = "Convert KHR_materials_pbrSpecularGlossiness to KHR_materials_pbrMetallicRoughness?"
  56. await viewer.load('file.glb', {
  57. autoScale: true,
  58. autoCenter: true,
  59. confirmSpecGlossConversion: false, // prevents the confirmation dialog while loading this file, even if set to true in the plugin
  60. })
  61. ```
  62. ::: tip
  63. The plugin uses `viewer.dialog` API to show the confirmation dialog. If you want to customize the dialog, you can use the `viewer.dialog` API to set a custom dialog component.
  64. :::