@threepipe/plugin-gltf-transform 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +22 -3
  2. package/README.md +2 -2
  3. package/dist/GLTFDracoExportPlugin.d.ts +2 -44
  4. package/dist/GLTFDracoExportPlugin.d.ts.map +1 -1
  5. package/dist/GLTFDracoExporter.d.ts +5 -40
  6. package/dist/GLTFDracoExporter.d.ts.map +1 -1
  7. package/dist/GLTFDracoExporterBase.d.ts +49 -0
  8. package/dist/GLTFDracoExporterBase.d.ts.map +1 -0
  9. package/dist/GLTFSpecGlossinessConverterPlugin.d.ts +10 -31
  10. package/dist/GLTFSpecGlossinessConverterPlugin.d.ts.map +1 -1
  11. package/dist/GLTFSpecGlossinessConverterPluginBase.d.ts +45 -0
  12. package/dist/GLTFSpecGlossinessConverterPluginBase.d.ts.map +1 -0
  13. package/dist/dependencies.txt +12 -12
  14. package/dist/index.d.ts +5 -3
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +119 -136
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +117 -134
  19. package/dist/index.mjs.map +1 -1
  20. package/docs/assets/hierarchy.js +1 -1
  21. package/docs/assets/icons.js +1 -1
  22. package/docs/assets/icons.svg +1 -1
  23. package/docs/assets/main.js +2 -2
  24. package/docs/assets/navigation.js +1 -1
  25. package/docs/assets/search.js +1 -1
  26. package/docs/assets/style.css +3 -3
  27. package/docs/classes/GLTFDracoExportPlugin.html +7 -6
  28. package/docs/classes/GLTFDracoExporter.html +15 -14
  29. package/docs/classes/GLTFDracoExporterBase.html +37 -0
  30. package/docs/classes/GLTFSpecGlossinessConverterPlugin.html +16 -14
  31. package/docs/classes/GLTFSpecGlossinessConverterPluginBase.html +37 -0
  32. package/docs/classes/GLTFViewerConfigExtensionGP.html +5 -0
  33. package/docs/enums/EncoderMethod.html +2 -2
  34. package/docs/functions/createGenericExtensionClass.html +1 -1
  35. package/docs/functions/gltfKhrPbrSpecularGlossinessConverter.html +2 -1
  36. package/docs/functions/gltfKhrPbrSpecularGlossinessConverterBase.html +1 -0
  37. package/docs/hierarchy.html +1 -1
  38. package/docs/index.html +1 -1
  39. package/package.json +24 -2
  40. package/src/GLTFDracoExportPlugin.ts +2 -2
  41. package/src/GLTFDracoExporter.ts +10 -417
  42. package/src/GLTFDracoExporterBase.ts +427 -0
  43. package/src/GLTFSpecGlossinessConverterPlugin.ts +14 -115
  44. package/src/GLTFSpecGlossinessConverterPluginBase.ts +129 -0
  45. package/src/index.ts +3 -1
  46. package/tsconfig.json +1 -0
  47. package/docs/.nojekyll +0 -1
package/docs/index.html CHANGED
@@ -1 +1 @@
1
- <!DOCTYPE html><html class="default" lang="en" data-base="./"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>Threepipe gltf-transform Plugins</title><meta name="description" content="Documentation for Threepipe gltf-transform Plugins"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="index.html" class="title">Threepipe gltf-transform Plugins</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h1>Threepipe gltf-transform Plugins</h1></div><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Plugins"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h2>Plugins</h2></summary><dl class="tsd-member-summaries"><dt class="tsd-member-summary" id="gltfdracoexportplugin"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><a href="classes/GLTFDracoExportPlugin.html">GLTFDracoExportPlugin</a><a href="#gltfdracoexportplugin" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd></dl></details><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Other"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h2>Other</h2></summary><dl class="tsd-member-summaries"><dt class="tsd-member-summary" id="encodermethod"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Enumeration"><use href="assets/icons.svg#icon-8"></use></svg><a href="enums/EncoderMethod.html">EncoderMethod</a><a href="#encodermethod" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="gltfdracoexporter"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><a href="classes/GLTFDracoExporter.html">GLTFDracoExporter</a><a href="#gltfdracoexporter" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="gltfspecglossinessconverterplugin"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><a href="classes/GLTFSpecGlossinessConverterPlugin.html">GLTFSpecGlossinessConverterPlugin</a><a href="#gltfspecglossinessconverterplugin" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="creategenericextensionclass"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/createGenericExtensionClass.html">createGenericExtensionClass</a><a href="#creategenericextensionclass" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="gltfkhrpbrspecularglossinessconverter"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/gltfKhrPbrSpecularGlossinessConverter.html">gltfKhrPbrSpecularGlossinessConverter</a><a href="#gltfkhrpbrspecularglossinessconverter" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd></dl></details></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>On This Page</h3></summary><div class="tsd-accordion-details"><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Plugins"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Plugins</summary><div><a href="#gltfdracoexportplugin"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><span>GLTF<wbr/>Draco<wbr/>Export<wbr/>Plugin</span></a></div></details><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Other"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Other</summary><div><a href="#encodermethod"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Enumeration"><use href="assets/icons.svg#icon-8"></use></svg><span>Encoder<wbr/>Method</span></a><a href="#gltfdracoexporter"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><span>GLTF<wbr/>Draco<wbr/>Exporter</span></a><a href="#gltfspecglossinessconverterplugin"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><span>GLTF<wbr/>Spec<wbr/>Glossiness<wbr/>Converter<wbr/>Plugin</span></a><a href="#creategenericextensionclass"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>create<wbr/>Generic<wbr/>Extension<wbr/>Class</span></a><a href="#gltfkhrpbrspecularglossinessconverter"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>gltf<wbr/>Khr<wbr/>Pbr<wbr/>Specular<wbr/>Glossiness<wbr/>Converter</span></a></div></details></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="index.html" class="current">Threepipe gltf-transform Plugins</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
1
+ <!DOCTYPE html><html class="default" lang="en" data-base="./"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>Threepipe gltf-transform Plugins</title><meta name="description" content="Documentation for Threepipe gltf-transform Plugins"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script><script async src="assets/hierarchy.js" id="tsd-hierarchy-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="index.html" class="title">Threepipe gltf-transform Plugins</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h1>Threepipe gltf-transform Plugins</h1></div><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Plugins"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h2>Plugins</h2></summary><dl class="tsd-member-summaries"><dt class="tsd-member-summary" id="gltfdracoexportplugin"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><a href="classes/GLTFDracoExportPlugin.html">GLTFDracoExportPlugin</a><a href="#gltfdracoexportplugin" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd></dl></details><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Other"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h2>Other</h2></summary><dl class="tsd-member-summaries"><dt class="tsd-member-summary" id="encodermethod"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Enumeration"><use href="assets/icons.svg#icon-8"></use></svg><a href="enums/EncoderMethod.html">EncoderMethod</a><a href="#encodermethod" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="gltfdracoexporter"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><a href="classes/GLTFDracoExporter.html">GLTFDracoExporter</a><a href="#gltfdracoexporter" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="gltfdracoexporterbase"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><a href="classes/GLTFDracoExporterBase.html">GLTFDracoExporterBase</a><a href="#gltfdracoexporterbase" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="gltfspecglossinessconverterplugin"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><a href="classes/GLTFSpecGlossinessConverterPlugin.html">GLTFSpecGlossinessConverterPlugin</a><a href="#gltfspecglossinessconverterplugin" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="gltfspecglossinessconverterpluginbase"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><a href="classes/GLTFSpecGlossinessConverterPluginBase.html">GLTFSpecGlossinessConverterPluginBase</a><a href="#gltfspecglossinessconverterpluginbase" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="gltfviewerconfigextensiongp"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><a href="classes/GLTFViewerConfigExtensionGP.html">GLTFViewerConfigExtensionGP</a><a href="#gltfviewerconfigextensiongp" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="creategenericextensionclass"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/createGenericExtensionClass.html">createGenericExtensionClass</a><a href="#creategenericextensionclass" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="gltfkhrpbrspecularglossinessconverter"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a class="deprecated" href="functions/gltfKhrPbrSpecularGlossinessConverter.html">gltfKhrPbrSpecularGlossinessConverter</a><a href="#gltfkhrpbrspecularglossinessconverter" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="gltfkhrpbrspecularglossinessconverterbase"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/gltfKhrPbrSpecularGlossinessConverterBase.html">gltfKhrPbrSpecularGlossinessConverterBase</a><a href="#gltfkhrpbrspecularglossinessconverterbase" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd></dl></details></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>On This Page</h3></summary><div class="tsd-accordion-details"><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Plugins"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Plugins</summary><div><a href="#gltfdracoexportplugin"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><span>GLTF<wbr/>Draco<wbr/>Export<wbr/>Plugin</span></a></div></details><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Other"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Other</summary><div><a href="#encodermethod"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Enumeration"><use href="assets/icons.svg#icon-8"></use></svg><span>Encoder<wbr/>Method</span></a><a href="#gltfdracoexporter"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><span>GLTF<wbr/>Draco<wbr/>Exporter</span></a><a href="#gltfdracoexporterbase"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><span>GLTF<wbr/>Draco<wbr/>Exporter<wbr/>Base</span></a><a href="#gltfspecglossinessconverterplugin"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><span>GLTF<wbr/>Spec<wbr/>Glossiness<wbr/>Converter<wbr/>Plugin</span></a><a href="#gltfspecglossinessconverterpluginbase"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><span>GLTF<wbr/>Spec<wbr/>Glossiness<wbr/>Converter<wbr/>Plugin<wbr/>Base</span></a><a href="#gltfviewerconfigextensiongp"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Class"><use href="assets/icons.svg#icon-128"></use></svg><span>GLTF<wbr/>Viewer<wbr/>Config<wbr/>Extension<wbr/>GP</span></a><a href="#creategenericextensionclass"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>create<wbr/>Generic<wbr/>Extension<wbr/>Class</span></a><a href="#gltfkhrpbrspecularglossinessconverter"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>gltf<wbr/>Khr<wbr/>Pbr<wbr/>Specular<wbr/>Glossiness<wbr/>Converter</span></a><a href="#gltfkhrpbrspecularglossinessconverterbase"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>gltf<wbr/>Khr<wbr/>Pbr<wbr/>Specular<wbr/>Glossiness<wbr/>Converter<wbr/>Base</span></a></div></details></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="index.html" class="current">Threepipe gltf-transform Plugins</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
package/package.json CHANGED
@@ -1,10 +1,24 @@
1
1
  {
2
2
  "name": "@threepipe/plugin-gltf-transform",
3
3
  "description": "Utility plugins for threepipe using gltf-transform to optimize/compress glTF files.",
4
- "version": "0.2.2",
4
+ "version": "0.3.0",
5
5
  "dependencies": {},
6
6
  "peerDependencies": {
7
- "threepipe": ">=0.1.0"
7
+ "threepipe": ">=0.1.0",
8
+ "@gltf-transform/core": "^4.2.0",
9
+ "@gltf-transform/extensions": "^4.2.0",
10
+ "@gltf-transform/functions": "^4.2.0"
11
+ },
12
+ "peerDependenciesMeta": {
13
+ "@gltf-transform/core": {
14
+ "optional": true
15
+ },
16
+ "@gltf-transform/extensions": {
17
+ "optional": true
18
+ },
19
+ "@gltf-transform/functions": {
20
+ "optional": true
21
+ }
8
22
  },
9
23
  "exports": {
10
24
  ".": {
@@ -15,6 +29,13 @@
15
29
  "./dist/": {
16
30
  "import": "./dist/",
17
31
  "require": "./dist/"
32
+ },
33
+ "./lib": {
34
+ "types": "./lib/index.d.ts",
35
+ "import": "./lib/index.js"
36
+ },
37
+ "./lib/": {
38
+ "import": "./lib/"
18
39
  }
19
40
  },
20
41
  "type": "module",
@@ -23,6 +44,7 @@
23
44
  "types": "dist/index.d.ts",
24
45
  "files": [
25
46
  "dist",
47
+ "lib",
26
48
  "src",
27
49
  "README.md",
28
50
  "CHANGELOG.md",
@@ -23,7 +23,7 @@ import {
23
23
  GLTFViewerConfigExtensionGP,
24
24
  } from './GLTFDracoExporter'
25
25
  import {UiObjectConfig} from 'uiconfig.js'
26
- import {EncoderOptions} from '@gltf-transform/extensions/dist/khr-draco-mesh-compression/encoder'
26
+ import type {EncoderOptions} from './GLTFDracoExporterBase'
27
27
  import {Extension} from '@gltf-transform/core'
28
28
 
29
29
  export enum EncoderMethod {
@@ -162,7 +162,7 @@ export class GLTFDracoExportPlugin extends AViewerPluginSync {
162
162
  super.onRemove(viewer)
163
163
  }
164
164
 
165
- protected _makeUi = (exporter: AssetExporterPlugin)=>[
165
+ protected _makeUi = (exporter: AssetExporterPlugin): UiObjectConfig[]=>[
166
166
  {
167
167
  type: 'checkbox',
168
168
  label: 'DRACO Compress',
@@ -1,425 +1,18 @@
1
- import {
2
- Extension,
3
- ExtensionProperty,
4
- GLTF,
5
- Graph,
6
- Property,
7
- PropertyType,
8
- ReaderContext,
9
- Texture,
10
- TextureChannel,
11
- TextureInfo,
12
- WebIO,
13
- WriterContext,
14
- } from '@gltf-transform/core'
15
- import {EncoderOptions} from '@gltf-transform/extensions/dist/khr-draco-mesh-compression/encoder'
16
- import {ALL_EXTENSIONS, KHRDracoMeshCompression} from '@gltf-transform/extensions'
17
- import {DRACOLoader2, GLTFExporter2, GLTFExporter2Options, GLTFViewerConfigExtension, IExportWriter} from 'threepipe'
1
+ import {WebIO} from '@gltf-transform/core'
2
+ import type {EncoderOptions} from './GLTFDracoExporterBase'
3
+ import {DRACOLoader2} from 'threepipe'
4
+ import {GLTFDracoExporterBase} from './GLTFDracoExporterBase'
5
+
6
+ // Re-export everything from base so existing imports keep working
7
+ export {GLTFDracoExporterBase, GLTFViewerConfigExtensionGP, createGenericExtensionClass} from './GLTFDracoExporterBase'
18
8
 
19
9
  /**
20
10
  * GLTF Draco Exporter
21
11
  *
22
- * Extension of GLTFExporter2 that runs the output through gltf-transform for draco compression.
12
+ * Browser-specific extension of GLTFDracoExporterBase that uses WebIO.
23
13
  */
24
- export class GLTFDracoExporter extends GLTFExporter2 implements IExportWriter {
25
- public loader?: DRACOLoader2 // required for loading draco libs.
26
- private _io: WebIO
27
- private _loadedLibs = false
28
- private _encoderOptions: EncoderOptions
29
-
14
+ export class GLTFDracoExporter extends GLTFDracoExporterBase {
30
15
  constructor(encoderOptions?: EncoderOptions, loader?: DRACOLoader2) {
31
- super()
32
- encoderOptions = encoderOptions || {
33
- method: KHRDracoMeshCompression.EncoderMethod.EDGEBREAKER,
34
- encodeSpeed: 5,
35
- }
36
- this._io = new WebIO().registerExtensions(ALL_EXTENSIONS)
37
- this._encoderOptions = encoderOptions
38
-
39
- if (loader) {
40
- this.loader = loader
41
- this.loader.setDecoderConfig({type: 'js'}) // todo: hack for now.
42
- this.loader.preload(true, true)
43
- }
44
-
45
- }
46
-
47
- preload(): this {
48
- this._loadLibs()
49
- return this
50
- }
51
-
52
- private async _loadLibs() {
53
- if (this._loadedLibs || !this.loader) return
54
-
55
- const libs = await Promise.all([
56
- this.loader.initEncoder(),
57
- this.loader.initDecoder(),
58
- ])
59
- this._io.registerDependencies({
60
- ['draco3d.encoder']: libs[0],
61
- ['draco3d.decoder']: libs[1], // only required if we are loading a draco compressed gltf
62
- })
63
- this._loadedLibs = true
64
-
65
- }
66
-
67
- async parseAsync(obj: any, {compress = false, dracoOptions, ...options}: {compress: boolean, dracoOptions?: EncoderOptions} & GLTFExporter2Options, throwOnError = false): Promise<Blob> {
68
- if (!this.loader) {
69
- console.error('GLTFDracoExporter: No DRACOLoader2 instance provided')
70
- return super.parseAsync(obj, options)
71
- }
72
- await this._loadLibs()
73
-
74
- const ops = {...options}
75
- if (compress) {
76
- // externalImagesInExtras: this is required because gltf-transform doesn't support external images in glb
77
- // see https://github.com/donmccurdy/glTF-Transform/discussions/644
78
- ops.externalImagesInExtras = true
79
- }
80
-
81
- const uncompressed = await new Promise((resolve, reject) => this.parse(obj, resolve, reject, ops)) as any
82
-
83
- const uncompressedBlob = await super.parseAsync(uncompressed, ops)
84
- if (!compress) return uncompressedBlob
85
-
86
- try {
87
- if (!uncompressed) throw new Error('GLTFDracoExporter: gltf is null')
88
-
89
- let gltf = uncompressed
90
-
91
- const bytes = (gltf as ArrayBuffer).byteLength || Infinity
92
-
93
- const iDocument = await (typeof gltf === 'object' && !(gltf as any).byteLength ? this._io.readJSON({
94
- json: gltf as GLTF.IGLTF,
95
- resources: {},
96
- }) : this._io.readBinary(new Uint8Array(gltf as ArrayBuffer)))
97
-
98
- // iDocument.createExtension(GLTFViewerConfigExtensionGP)
99
- iDocument.createExtension(KHRDracoMeshCompression)
100
- .setRequired(true)
101
- .setEncoderOptions({...this._encoderOptions, ...dracoOptions ?? {}})
102
-
103
- if (ops.exportExt === 'glb') {
104
- gltf = await this._io.writeBinary(iDocument)
105
- if (isFinite(bytes)) {
106
- console.log('DRACO Compression ratio: ' + ((gltf as ArrayBuffer).byteLength / bytes).toFixed(5))
107
- }
108
- } else {
109
- const jDoc = await this._io.writeJSON(iDocument)
110
- gltf = jDoc.json
111
- if (Object.values(jDoc.resources).filter(v => v).length > 0) {
112
- console.warn('DRACOExporter: extra resources in resources not supported properly')
113
- ;(gltf as any).resources = jDoc.resources
114
- }
115
- }
116
-
117
- gltf.__isGLTFOutput = true
118
- const blob = await super.parseAsync(gltf, ops) as any // this will just convert it to blob because __isGLTFOutput is set (checked in GLTFExporter2)
119
- if (!blob) throw new Error('GLTFDracoExporter: blob is null')
120
- blob.ext = 'glb'
121
- ;(blob as any).__uncompressed = uncompressedBlob
122
- return blob
123
- } catch (e) {
124
- if (throwOnError) throw e
125
- console.error('Unable to compress glb with DRACO extension, fallback to uncompressed')
126
- console.error(e)
127
- return uncompressedBlob
128
- }
129
- }
130
-
131
- addExtension(...extension: (typeof Extension)[]): this {
132
- this._io.registerExtensions(extension)
133
- return this
134
- }
135
- createAndAddExtension(name: string, textures?: Record<string, string|number>): this {
136
- return this.addExtension(createGenericExtensionClass(name, textures))
137
- }
138
- createAndAddExtensions(extensions: [string, Record<string, string|number>|undefined][]): this {
139
- return this.addExtension(...extensions.map(e=> createGenericExtensionClass(e[0], e[1])))
140
- }
141
- }
142
-
143
- declare module 'threepipe'{
144
- interface GLTFExporter2Options {
145
- compress?: boolean
146
- dracoOptions?: EncoderOptions
147
- }
148
- }
149
-
150
- // for @gltf-transform/core
151
- class ViewerJSONExtensionProperty extends ExtensionProperty {
152
- readonly extensionName: string = GLTFViewerConfigExtension.ViewerConfigGLTFExtension
153
- readonly parentTypes: string[] = [PropertyType.SCENE]
154
- readonly propertyType: string = 'ViewerJSON'
155
-
156
- // eslint-disable-next-line @typescript-eslint/naming-convention
157
- protected init(): void {return}
158
-
159
- }
160
- export class GLTFViewerConfigExtensionGP extends Extension {
161
- public readonly extensionName = GLTFViewerConfigExtension.ViewerConfigGLTFExtension
162
- public static readonly EXTENSION_NAME = GLTFViewerConfigExtension.ViewerConfigGLTFExtension
163
- private _viewerConfig: any = {}
164
- // private _texturesRef: [any, Texture][] = []
165
-
166
- read(context: ReaderContext): this {
167
- this._viewerConfig = {}
168
- context.jsonDoc.json.scenes?.forEach((sceneDef, sceneIndex)=>{
169
- if (sceneDef.extensions && sceneDef.extensions[GLTFViewerConfigExtension.ViewerConfigGLTFExtension]) {
170
- const prop = new ViewerJSONExtensionProperty(this.document.getGraph())
171
- context.scenes[sceneIndex].setExtension(GLTFViewerConfigExtension.ViewerConfigGLTFExtension, prop)
172
- this._viewerConfig = sceneDef.extensions[GLTFViewerConfigExtension.ViewerConfigGLTFExtension] as any
173
- // prop.setExtras()
174
-
175
- /*
176
- const buffers = [] as any[]
177
-
178
- Object.values(viewerConfig.resources).forEach((res: any) => {
179
- Object.values(res).forEach((item: any) => {
180
- if (!item.url) return
181
- if (item.url.data?.image !== null) {
182
- buffers.push(item.url)
183
- }
184
- })
185
- })
186
- const jsonDoc = context.jsonDoc
187
- console.log(buffers)
188
- for (const buffer of buffers) {
189
- const img = buffer.data.image as number
190
- const imageDef = jsonDoc.json.images![img]
191
- const bufferViewDef = jsonDoc.json.bufferViews![imageDef.bufferView!]
192
- const bufferDef = jsonDoc.json.buffers![bufferViewDef.buffer]
193
- const bufferData = bufferDef.uri ? jsonDoc.resources[bufferDef.uri] : jsonDoc.resources[GLB_BUFFER]
194
- const byteOffset = bufferViewDef.byteOffset || 0
195
- const byteLength = bufferViewDef.byteLength
196
- const imageData = bufferData.slice(byteOffset, byteOffset + byteLength)
197
- const texture = this.document.createTexture(imageDef.name)
198
- texture.setImage(imageData)
199
- this._texturesRef.push([buffer, texture])
200
- }
201
- */
202
-
203
-
204
- }
205
- })
206
- return this
207
- }
208
-
209
- write(context: WriterContext): this {
210
- this.document.getRoot().listScenes().forEach((scene)=>{
211
- const prop = scene.getExtension(GLTFViewerConfigExtension.ViewerConfigGLTFExtension)
212
- if (prop) {
213
- const sceneDef = context.jsonDoc.json.scenes?.[context.jsonDoc.json.scene || 0] // todo: get proper scene index, if working with multiple scenes
214
- if (sceneDef && Object.keys(this._viewerConfig).length > 0) {
215
- sceneDef.extensions = sceneDef.extensions || {}
216
-
217
- /*
218
- console.log(context.jsonDoc.json.images)
219
- for (const [buffer, texture] of this._texturesRef) {
220
- const imageDef = context.createPropertyDef(texture) as GLTF.IImage
221
- context.createImageData(imageDef, texture.getImage()!, texture)
222
- buffer.data.image = context.jsonDoc.json.images!.push(imageDef) - 1
223
- context.imageIndexMap.set(texture, buffer.data.image)
224
- }
225
- console.log(context.jsonDoc.json)
226
- */
227
-
228
- sceneDef.extensions[GLTFViewerConfigExtension.ViewerConfigGLTFExtension] = this._viewerConfig
229
-
230
- // this._texturesRef = []
231
- this._viewerConfig = {}
232
-
233
- }
234
- }
235
- })
236
-
237
- return this
238
- }
239
-
240
- required = true
241
- }
242
-
243
- class GenericExtensionProperty extends ExtensionProperty<any> {
244
- readonly extensionName: string
245
- readonly parentTypes: string[] = [PropertyType.MATERIAL, PropertyType.MESH, PropertyType.NODE, PropertyType.SCENE]
246
- readonly propertyType: string = 'GenericExtension'
247
- textures: Record<string, [TextureInfo, Texture|null]> = {}
248
-
249
- addTexture(key: string, texInfo: TextureInfo, texture: Texture | null, channels = 0x1111) {
250
- this.setRef(key, texture, {channels})
251
- this.textures[key] = [texInfo, texture]
252
- }
253
-
254
- constructor(graph: Graph<Property>, name: string, extensionName: string) {
255
- super(graph, name)
256
- this.extensionName = extensionName
257
- }
258
-
259
- // eslint-disable-next-line @typescript-eslint/naming-convention
260
- protected init(): void {return}
261
- }
262
-
263
- // see transmission extension for reference
264
- abstract class GenericExtension extends Extension {
265
- abstract readonly extensionName: string
266
-
267
- textureChannels: Record<string, number> = {}
268
-
269
- read(context: ReaderContext): this {
270
- const jsonDoc = context.jsonDoc
271
- // console.log(jsonDoc)
272
- const materialDefs = jsonDoc.json.materials || []
273
- const textureDefs = jsonDoc.json.textures || []
274
- materialDefs.forEach((materialDef, materialIndex) => {
275
- if (materialDef.extensions && materialDef.extensions[this.extensionName]) {
276
- const paramsExt = new GenericExtensionProperty(this.document.getGraph(), '', this.extensionName)
277
- context.materials[materialIndex].setExtension(this.extensionName, paramsExt)
278
- const paramsExtDef = materialDef.extensions[this.extensionName] as Record<string, any>
279
- const paramsExtDef2 = {...paramsExtDef}
280
-
281
- for (const [key, value] of Object.entries(paramsExtDef2)) {
282
- if (typeof value?.index === 'number') { // this is a texture...
283
- const textureInfoDef = value
284
- const source = textureDefs[textureInfoDef.index]?.source
285
- if (typeof source !== 'number') {
286
- console.warn('GLTF Pipeline: source texture not found for texture info', textureInfoDef)
287
- continue
288
- }
289
- const texture = context.textures[source]
290
- const texInfo = new TextureInfo(this.document.getGraph())
291
- const channels = this.textureChannels[key] ?? 0x1111
292
- paramsExt.addTexture(key, texInfo, texture, channels)
293
- context.setTextureInfo(texInfo, textureInfoDef)
294
- delete paramsExtDef2[key]
295
- }
296
- }
297
-
298
- paramsExt.setExtras(paramsExtDef2)
299
- // console.log({...paramsExtDef})
300
- }
301
- })
302
- const meshDefs = jsonDoc.json.meshes || []
303
- meshDefs.forEach((meshDef, meshIndex) => {
304
- if (meshDef.extensions && meshDef.extensions[this.extensionName]) {
305
- const paramsExt = new GenericExtensionProperty(this.document.getGraph(), '', this.extensionName)
306
- context.meshes[meshIndex].setExtension(this.extensionName, paramsExt)
307
- const paramsExtDef = meshDef.extensions[this.extensionName] as Record<string, any>
308
- paramsExt.setExtras(paramsExtDef)
309
- }
310
- })
311
- const nodeDefs = jsonDoc.json.nodes || []
312
- nodeDefs.forEach((nodeDef, nodeIndex) => {
313
- if (nodeDef.extensions && nodeDef.extensions[this.extensionName]) {
314
- const paramsExt = new GenericExtensionProperty(this.document.getGraph(), '', this.extensionName)
315
- context.nodes[nodeIndex].setExtension(this.extensionName, paramsExt)
316
- const paramsExtDef = nodeDef.extensions[this.extensionName] as Record<string, any>
317
- paramsExt.setExtras(paramsExtDef)
318
- // console.log(paramsExtDef)
319
- }
320
- })
321
- const sceneDefs = jsonDoc.json.scenes || []
322
- sceneDefs.forEach((sceneDef, sceneIndex) => {
323
- if (sceneDef.extensions && sceneDef.extensions[this.extensionName]) {
324
- const paramsExt = new GenericExtensionProperty(this.document.getGraph(), '', this.extensionName)
325
- context.scenes[sceneIndex].setExtension(this.extensionName, paramsExt)
326
- const paramsExtDef = sceneDef.extensions[this.extensionName] as Record<string, any>
327
- paramsExt.setExtras(paramsExtDef)
328
- // console.log(paramsExtDef)
329
- }
330
- })
331
-
332
- return this
333
- }
334
-
335
- write(context: WriterContext): this {
336
- const jsonDoc = context.jsonDoc
337
- this.document.getRoot()
338
- .listMaterials()
339
- .forEach((material) => {
340
- const paramsExt = material.getExtension<GenericExtensionProperty>(this.extensionName)
341
- // console.log(paramsExt)
342
- if (paramsExt) {
343
- const materialIndex = context.materialIndexMap.get(material)!
344
- const materialDef = jsonDoc.json.materials![materialIndex]
345
- materialDef.extensions = materialDef.extensions || {}
346
- const extensionDef = paramsExt.getExtras()
347
- const extensionDef2 = {...extensionDef}
348
-
349
- // console.log(paramsExt.textures)
350
- for (const [key, value] of Object.entries(paramsExt.textures)) {
351
- const textureInfo = value[0]
352
- const textureLink = value[1]
353
- const texture = textureLink
354
-
355
- if (texture)
356
- extensionDef2[key] = context.createTextureInfoDef(texture, textureInfo)
357
-
358
- // console.log(texture)
359
-
360
- }
361
- // console.log(extensionDef2)
362
-
363
- materialDef.extensions[this.extensionName] = extensionDef2
364
- }
365
- })
366
- this.document.getRoot()
367
- .listMeshes()
368
- .forEach((mesh) => {
369
- const paramsExt = mesh.getExtension<GenericExtensionProperty>(this.extensionName)
370
- if (paramsExt) {
371
- const meshIndex = context.meshIndexMap.get(mesh)!
372
- const meshDef = jsonDoc.json.meshes![meshIndex]
373
- meshDef.extensions = meshDef.extensions || {}
374
- meshDef.extensions[this.extensionName] = paramsExt.getExtras()
375
- }
376
- })
377
- this.document.getRoot()
378
- .listNodes()
379
- .forEach((node) => {
380
- const paramsExt = node.getExtension<GenericExtensionProperty>(this.extensionName)
381
- if (paramsExt) {
382
- const nodeIndex = context.nodeIndexMap.get(node)!
383
- const nodeDef = jsonDoc.json.nodes![nodeIndex]
384
- nodeDef.extensions = nodeDef.extensions || {}
385
- nodeDef.extensions[this.extensionName] = paramsExt.getExtras()
386
- }
387
- })
388
- this.document.getRoot()
389
- .listScenes()
390
- .forEach((scene) => {
391
- const paramsExt = scene.getExtension<GenericExtensionProperty>(this.extensionName)
392
- if (paramsExt) {
393
- const sceneIndex = context.jsonDoc.json.scene || 0 // todo: get proper scene index, if working with multiple scenes, this will do the default one.
394
- const sceneDef = jsonDoc.json.scenes![sceneIndex]
395
- if (!sceneDef) return
396
- sceneDef.extensions = sceneDef.extensions || {}
397
- sceneDef.extensions[this.extensionName] = paramsExt.getExtras()
398
- }
399
- })
400
-
401
- return this
402
- }
403
-
404
- }
405
-
406
- function stringToChannel(s: string) {
407
- let r = 0
408
- if (s.includes('R')) r |= TextureChannel.R
409
- if (s.includes('G')) r |= TextureChannel.G
410
- if (s.includes('B')) r |= TextureChannel.B
411
- if (s.includes('A')) r |= TextureChannel.A
412
- return r
413
- }
414
-
415
- export function createGenericExtensionClass(name: string, textures?: Record<string, string|number>): typeof GenericExtension {
416
- return class extends GenericExtension {
417
- public static readonly EXTENSION_NAME = name
418
- readonly extensionName = name
419
- textureChannels: Record<string, number> = !textures ? {} : Object.fromEntries(
420
- Object.entries(textures)
421
- .map(([k, v])=>
422
- [k, typeof v === 'number' ? v : stringToChannel(v)])
423
- )
16
+ super(new WebIO(), encoderOptions, loader)
424
17
  }
425
18
  }