threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gltf-three-extras-ext.md 4.2KB

11 maanden geleden
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ---
  2. prev:
  3. text: 'Using Vanilla Three.js style code'
  4. link: './vanilla-threejs'
  5. next: false
  6. aside: false
  7. ---
  8. # Saving three.js properties in glTF
  9. Threepipe support saving three.js object, material and light properties in glTF files automatically.
  10. This is done using custom glTF extensions that are added to the glTF file when exporting.
  11. If the files exported from threepipe exporter plugin or any of the editors is opened in external three.js editor, it cannot read these extra properties without the extensions support.
  12. ## Extensions
  13. - `WEBGI_object3d_extras`
  14. - Implemented in [GLTFObject3DExtrasExtension](https://threepipe.org/docs/classes/GLTFObject3DExtrasExtension.html)
  15. - This extension saves additional properties of `Object3D` like `visible`, `castShadow`, `frustumCulled`, etc.
  16. - Reference from three.js -> `ObjectLoader`
  17. - `WEBGI_material_extras`
  18. - Implemented in [GLTFMaterialExtrasExtension](https://threepipe.org/docs/classes/GLTFMaterialExtrasExtension.html)
  19. - This extension saves additional properties of `Material` like `emissiveIntensity`, `flatShading`, `blending`, etc.
  20. - Reference from three.js -> `MaterialLoader`
  21. - `WEBGI_light_extras`
  22. - Implemented in [GLTFLightExtrasExtension](https://threepipe.org/docs/classes/GLTFLightExtrasExtension.html)
  23. - This extension saves additional properties of `Light` like `shadow`.
  24. - This is used alongside `WEBGI_object3d_extras` extension for Light objects
  25. - `WEBGI_materials_alphamap`
  26. - Implemented in [GLTFMaterialsAlphaMapExtension](https://threepipe.org/docs/classes/GLTFMaterialsAlphaMapExtension.html)
  27. - This extension saves the alpha map texture for materials that have an `alphaMap` property.
  28. - `WEBGI_materials_bumpmap`
  29. - Implemented in [GLTFMaterialsBumpMapExtension](https://threepipe.org/docs/classes/GLTFMaterialsBumpMapExtension.html)
  30. - This extension saves the bump map texture for materials that have an `bumpMap` property.
  31. - `WEBGI_materials_displacementmap`
  32. - Implemented in [GLTFMaterialsDisplacementMapExtension](https://threepipe.org/docs/classes/GLTFMaterialsDisplacementMapExtension.html)
  33. - This extension saves the displacement map texture for materials that have an `displacementMap` property.
  34. - `WEBGI_materials_lightmap`
  35. - Implemented in [GLTFMaterialsLightMapExtension](https://threepipe.org/docs/classes/GLTFMaterialsLightMapExtension.html)
  36. - This extension saves the light map texture for materials that have an `lightMap` property.
  37. - `WEBGI_viewer`
  38. - Implemented in [GLTFViewerConfigExtension](https://threepipe.org/docs/classes/GLTFViewerConfigExtension.html)
  39. - Saves all the `ThreeViewer`, `RootScene`, `RenderManager` and all plugin configurations in the glTF file as JSON object. Textures are saved as binary blob or base64 encoded string depending on the file format.
  40. Threepipe includes some more extensions that are defined within plugins like `customBumpMapGLTFExtension`, `clearCoatTintGLTFExtension` etc.
  41. These custom extensions are written as standard three.js GLTFLoader and GLTFExporter extensions, so they can _ideally_ be used with any three.js project.
  42. ## glTF Transform Extensions
  43. It's possible to use the custom extensions with the [gltf-transform](https://gltf-transform.donmccurdy.com/) library as well.
  44. To do that, a custom extension implementation/class has to be created. Fortunately, in threepipe this can be done automatically at runtime.
  45. `@threepipe/plugin-gltf-transform` package provides `createGenericExtensionClass` function, and can be used to create an extension class that can be used with glTF Transform library.
  46. ```typescript
  47. const MyExtension = createGenericExtensionClass(GLTFMaterialsLightMapExtension.WebGiMaterialsLightMapExtension, GLTFMaterialsLightMapExtension.Textures)
  48. const io = new WebIO().registerExtensions([MyExtension])
  49. ```
  50. It is also possible to get all the extensions supported for `gltf-transform` using the `GLTFDracoExportPlugin` -
  51. ```typescript
  52. const plugin = viewer.getPlugin(GLTFDracoExportPlugin) // add the plugin before if not added
  53. const ALL_THREEPIPE_EXTENSIONS = plugin.gltfTransformExtensions
  54. const io = new WebIO().registerExtensions(ALL_THREEPIPE_EXTENSIONS)
  55. ```
  56. Checkout the [Serialization guide](./../guide/serialization) for more details on how to serialize and deserialize js in threepipe.