threepipe
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

plugin-network.md 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ---
  2. prev:
  3. text: '@threepipe/plugins-extra-importers'
  4. link: './plugins-extra-importers'
  5. next:
  6. text: '@threepipe/plugin-blend-importer'
  7. link: './plugin-blend-importer'
  8. ---
  9. # @threepipe/plugin-network
  10. Network/Cloud related plugin implementations for Threepipe.
  11. Includes `AWSClientPlugin` and `TransfrSharePlugin`.
  12. [![NPM Package](https://img.shields.io/npm/v/@threepipe/plugin-network.svg)](https://www.npmjs.com/package/@threepipe/plugin-network)
  13. ```bash
  14. npm install @threepipe/plugin-network
  15. ```
  16. ## TransfrSharePlugin
  17. [//]: # (todo: image)
  18. [Example](https://threepipe.org/examples/#transfr-share-plugin/) —
  19. [Source Code](https://github.com/repalash/threepipe/blob/master/plugins/network/src/TransfrSharePlugin.ts) —
  20. [API Reference](https://threepipe.org/plugins/network/docs/classes/TransfrSharePlugin.html)
  21. TransfrSharePlugin provides functionality to export and upload the scene or an object as glb and provide link to share/preview/edit the files.
  22. It uses the options from the `AssetExporterPlugin` to export the scene or object, and can be configured using its ui.
  23. Uses the free service [transfr.one](https://transfr.one/) by default which deletes the files after a certain time, but the url can be changed to a custom backend or a self-hosted version of transfr.
  24. ::: tip Note
  25. Since the uploaded files are publicly accessible by anyone by default, it is recommended to encrypt the file using the exporter options or use a secure backend.
  26. :::
  27. ```typescript
  28. import {ThreeViewer} from 'threepipe'
  29. import {TransfrSharePlugin} from '@threepipe/plugin-network'
  30. const viewer = new ThreeViewer({...})
  31. // Add the plugin
  32. const sharePlugin = viewer.addPluginSync(new TransfrSharePlugin())
  33. // when sharing, this query param is set to the model link
  34. sharePlugin.queryParam = 'm' // this is the default
  35. // used when clicking/calling Share page link
  36. sharePlugin.pageUrl = window.location.href // this is the default
  37. // used when clicking/calling Share viewer link
  38. sharePlugin.baseUrls.viewer = 'https://threepipe.org/examples/model-viewer/index.html'
  39. // used when clicking/calling Share editor link
  40. sharePlugin.baseUrls.editor = 'https://threepipe.org/examples/tweakpane-editor/index.html'
  41. // set to a custom server
  42. // sharePlugin.serverUrl = 'https://example.com/'
  43. // upload and get the link of the 3d model
  44. const link = await sharePlugin.getLink()
  45. // or upload and get the share link with a base page. And also copy to clipboard and shows a alert prompt(using viewer.dialog)
  46. const link2 = await sharePlugin.shareLink('https://example.com/custom_viewer')
  47. // or get the editor link directly
  48. const link3 = await sharePlugin.shareEditorLink()
  49. // to encrypt
  50. const assetExporterPlugin = viewer.getPlugin(AssetExporterPlugin) // this is a dependency, so automatically added
  51. assetExporterPlugin.encrypt = true
  52. // assetExporterPlugin.encryptKey = 'password' // user will be prompted for password when exporting if this is commented
  53. await sharePlugin.shareViewerLink()
  54. ```
  55. ### AWSClientPlugin
  56. [//]: # (todo: image)
  57. [Example](https://threepipe.org/examples/#aws-client-plugin/) —
  58. [Source Code](https://github.com/repalash/threepipe/blob/master/plugins/network/src/AWSClientPlugin.ts) —
  59. [API Reference](https://threepipe.org/plugins/network/docs/classes/AWSClientPlugin.html)
  60. Provides `fetch` function that performs a fetch request with AWS v4 signing.
  61. This is useful for connecting to AWS services like S3 directly from the client.
  62. It also interfaces with the `FileTransferPlugin` to directly upload file when exported with the viewer or the plugin.
  63. ::: danger Note
  64. Make sure to use keys with limited privileges and correct CORS settings.
  65. All the keys will be stored in plain text if `serializeSettings` is set to true
  66. :::
  67. ```typescript
  68. import {ThreeViewer} from 'threepipe'
  69. import {AWSClientPlugin} from '@threepipe/plugin-network'
  70. const viewer = new ThreeViewer({...})
  71. const awsPlugin = viewer.addPluginSync(new AWSClientPlugin())
  72. // set parameters and export. This can all be done from the UI also.
  73. awsPlugin.accessKeyId = '00000000000000000000'
  74. awsPlugin.accessKeySecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  75. awsPlugin.endpointURL = 'https://s3.amazonaws.com/bucket/'
  76. awsPlugin.pathPrefix = 'some/path/'
  77. // or load a json file with the parameters
  78. // the json file can be creating by entering the data in the UI and clicking the download preset json option.
  79. await viewer.load('file.json')
  80. // this will export the scene as glb
  81. const blob = await viewer.exportScene()
  82. // for a plugin config
  83. // blob = await viewer.export(viewer.getPlugin(GroundPlugin))
  84. // for a material
  85. // blob = await viewer.export(object.material)
  86. // for an object/mesh
  87. // blob = await viewer.export(object, {exportExt: 'glb'})
  88. // upload to s3. needs the parameters to be correct
  89. await viewer.exportBlob(blob, 'filename.glb')
  90. ```
  91. ::: tip Note
  92. CORS should be enabled for the S3 bucket on the domain where the viewer is hosted. This requirement can be bypassed during development by setting `AWSClientPlugin.USE_PROXY = true`. A free proxy is already set by default and can be changed by setting `AWSClientPlugin.PROXY_URL`.
  93. :::