@threepipe/plugin-gltf-transform 0.2.1 → 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 +23 -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 +26 -3
  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 +42 -0
  47. package/docs/.nojekyll +0 -1
package/dist/index.mjs CHANGED
@@ -1,10 +1,3 @@
1
- /**
2
- * @license
3
- * @threepipe/plugin-gltf-transform v0.2.1
4
- * Copyright 2022-2025 repalash <palash@shaders.app>
5
- * Apache-2.0 License
6
- * See ./dependencies.txt for any bundled third-party dependencies and licenses.
7
- */
8
1
  import { GLTFViewerConfigExtension, GLTFExporter2, AViewerPluginSync, GLTFMaterialsBumpMapExtension, GLTFMaterialsLightMapExtension, GLTFMaterialsAlphaMapExtension, GLTFMaterialsDisplacementMapExtension, customBumpMapGLTFExtension, GLTFLightExtrasExtension, GLTFObject3DExtrasExtension, GLTFMaterialExtrasExtension, clearCoatTintGLTFExtension, noiseBumpMaterialGLTFExtension, fragmentClippingGLTFExtension, generateUUID, AssetExporterPlugin, GLTFBinaryExtension } from "threepipe";
9
2
  class EventDispatcher {
10
3
  constructor() {
@@ -290,8 +283,8 @@ class RefMap {
290
283
  return Object.values(this.map);
291
284
  }
292
285
  }
293
- const $attributes = Symbol("attributes");
294
- const $immutableKeys = Symbol("immutableKeys");
286
+ const $attributes = /* @__PURE__ */ Symbol("attributes");
287
+ const $immutableKeys = /* @__PURE__ */ Symbol("immutableKeys");
295
288
  class GraphNode extends EventDispatcher {
296
289
  /**
297
290
  * Internal graph used to search and maintain references.
@@ -9493,19 +9486,18 @@ class KHRXMP extends Extension {
9493
9486
  KHRXMP.EXTENSION_NAME = NAME;
9494
9487
  const KHRONOS_EXTENSIONS = [KHRDracoMeshCompression, KHRLightsPunctual, KHRMaterialsAnisotropy, KHRMaterialsClearcoat, KHRMaterialsDiffuseTransmission, KHRMaterialsDispersion, KHRMaterialsEmissiveStrength, KHRMaterialsIOR, KHRMaterialsIridescence, KHRMaterialsPBRSpecularGlossiness, KHRMaterialsSpecular, KHRMaterialsSheen, KHRMaterialsTransmission, KHRMaterialsUnlit, KHRMaterialsVariants, KHRMaterialsVolume, KHRMeshQuantization, KHRTextureBasisu, KHRTextureTransform, KHRXMP];
9495
9488
  const ALL_EXTENSIONS = [EXTMeshGPUInstancing, EXTMeshoptCompression, EXTTextureAVIF, EXTTextureWebP, ...KHRONOS_EXTENSIONS];
9496
- class GLTFDracoExporter extends GLTFExporter2 {
9497
- constructor(encoderOptions, loader) {
9489
+ class GLTFDracoExporterBase extends GLTFExporter2 {
9490
+ constructor(io, encoderOptions, loader) {
9498
9491
  super();
9499
9492
  this._loadedLibs = false;
9500
9493
  encoderOptions = encoderOptions || {
9501
9494
  method: KHRDracoMeshCompression.EncoderMethod.EDGEBREAKER,
9502
9495
  encodeSpeed: 5
9503
9496
  };
9504
- this._io = new WebIO().registerExtensions(ALL_EXTENSIONS);
9497
+ this._io = io.registerExtensions(ALL_EXTENSIONS);
9505
9498
  this._encoderOptions = encoderOptions;
9506
9499
  if (loader) {
9507
9500
  this.loader = loader;
9508
- this.loader.setDecoderConfig({ type: "js" });
9509
9501
  this.loader.preload(true, true);
9510
9502
  }
9511
9503
  }
@@ -9606,9 +9598,8 @@ const _GLTFViewerConfigExtensionGP = class _GLTFViewerConfigExtensionGP extends
9606
9598
  }
9607
9599
  // private _texturesRef: [any, Texture][] = []
9608
9600
  read(context) {
9609
- var _a;
9610
9601
  this._viewerConfig = {};
9611
- (_a = context.jsonDoc.json.scenes) == null ? void 0 : _a.forEach((sceneDef, sceneIndex) => {
9602
+ context.jsonDoc.json.scenes?.forEach((sceneDef, sceneIndex) => {
9612
9603
  if (sceneDef.extensions && sceneDef.extensions[GLTFViewerConfigExtension.ViewerConfigGLTFExtension]) {
9613
9604
  const prop = new ViewerJSONExtensionProperty(this.document.getGraph());
9614
9605
  context.scenes[sceneIndex].setExtension(GLTFViewerConfigExtension.ViewerConfigGLTFExtension, prop);
@@ -9619,10 +9610,9 @@ const _GLTFViewerConfigExtensionGP = class _GLTFViewerConfigExtensionGP extends
9619
9610
  }
9620
9611
  write(context) {
9621
9612
  this.document.getRoot().listScenes().forEach((scene) => {
9622
- var _a;
9623
9613
  const prop = scene.getExtension(GLTFViewerConfigExtension.ViewerConfigGLTFExtension);
9624
9614
  if (prop) {
9625
- const sceneDef = (_a = context.jsonDoc.json.scenes) == null ? void 0 : _a[context.jsonDoc.json.scene || 0];
9615
+ const sceneDef = context.jsonDoc.json.scenes?.[context.jsonDoc.json.scene || 0];
9626
9616
  if (sceneDef && Object.keys(this._viewerConfig).length > 0) {
9627
9617
  sceneDef.extensions = sceneDef.extensions || {};
9628
9618
  sceneDef.extensions[GLTFViewerConfigExtension.ViewerConfigGLTFExtension] = this._viewerConfig;
@@ -9662,16 +9652,15 @@ class GenericExtension extends Extension {
9662
9652
  const materialDefs = jsonDoc.json.materials || [];
9663
9653
  const textureDefs = jsonDoc.json.textures || [];
9664
9654
  materialDefs.forEach((materialDef, materialIndex) => {
9665
- var _a;
9666
9655
  if (materialDef.extensions && materialDef.extensions[this.extensionName]) {
9667
9656
  const paramsExt = new GenericExtensionProperty(this.document.getGraph(), "", this.extensionName);
9668
9657
  context.materials[materialIndex].setExtension(this.extensionName, paramsExt);
9669
9658
  const paramsExtDef = materialDef.extensions[this.extensionName];
9670
9659
  const paramsExtDef2 = { ...paramsExtDef };
9671
9660
  for (const [key, value] of Object.entries(paramsExtDef2)) {
9672
- if (typeof (value == null ? void 0 : value.index) === "number") {
9661
+ if (typeof value?.index === "number") {
9673
9662
  const textureInfoDef = value;
9674
- const source = (_a = textureDefs[textureInfoDef.index]) == null ? void 0 : _a.source;
9663
+ const source = textureDefs[textureInfoDef.index]?.source;
9675
9664
  if (typeof source !== "number") {
9676
9665
  console.warn("GLTF Pipeline: source texture not found for texture info", textureInfoDef);
9677
9666
  continue;
@@ -9787,6 +9776,11 @@ function createGenericExtensionClass(name, textures) {
9787
9776
  }
9788
9777
  }, _a.EXTENSION_NAME = name, _a;
9789
9778
  }
9779
+ class GLTFDracoExporter extends GLTFDracoExporterBase {
9780
+ constructor(encoderOptions, loader) {
9781
+ super(new WebIO(), encoderOptions, loader);
9782
+ }
9783
+ }
9790
9784
  var EncoderMethod = /* @__PURE__ */ ((EncoderMethod2) => {
9791
9785
  EncoderMethod2[EncoderMethod2["EDGEBREAKER"] = 1] = "EDGEBREAKER";
9792
9786
  EncoderMethod2[EncoderMethod2["SEQUENTIAL"] = 0] = "SEQUENTIAL";
@@ -9834,59 +9828,50 @@ const _GLTFDracoExportPlugin = class _GLTFDracoExportPlugin extends AViewerPlugi
9834
9828
  ex.addExtension(...this.gltfTransformExtensions);
9835
9829
  return ex;
9836
9830
  };
9837
- this._makeUi = (exporter) => {
9838
- var _a;
9839
- return [
9840
- {
9841
- type: "checkbox",
9842
- label: "DRACO Compress",
9843
- property: [exporter.exportOptions, "compress"],
9844
- onChange: () => {
9845
- var _a2, _b;
9846
- return (_b = (_a2 = exporter.uiConfig).uiRefresh) == null ? void 0 : _b.call(_a2, true);
9847
- }
9848
- },
9849
- {
9850
- type: "folder",
9851
- hidden: () => !exporter.exportOptions.compress,
9852
- label: "DRACO Options",
9853
- children: [
9854
- {
9831
+ this._makeUi = (exporter) => [
9832
+ {
9833
+ type: "checkbox",
9834
+ label: "DRACO Compress",
9835
+ property: [exporter.exportOptions, "compress"],
9836
+ onChange: () => exporter.uiConfig.uiRefresh?.(true)
9837
+ },
9838
+ {
9839
+ type: "folder",
9840
+ hidden: () => !exporter.exportOptions.compress,
9841
+ label: "DRACO Options",
9842
+ children: [
9843
+ {
9844
+ type: "slider",
9845
+ label: "Encode Speed",
9846
+ bounds: [1, 10],
9847
+ property: [exporter.exportOptions.dracoOptions, "encodeSpeed"]
9848
+ },
9849
+ {
9850
+ type: "dropdown",
9851
+ label: "Encoder Method",
9852
+ property: [exporter.exportOptions.dracoOptions, "method"],
9853
+ children: Object.entries(EncoderMethod).map(([k, v]) => ({ label: k, value: v }))
9854
+ },
9855
+ {
9856
+ type: "dropdown",
9857
+ label: "Quantization Volume",
9858
+ property: [exporter.exportOptions.dracoOptions, "quantizationVolume"],
9859
+ children: ["mesh", "scene", "bbox"].map((v) => ({ label: v }))
9860
+ },
9861
+ {
9862
+ type: "folder",
9863
+ label: "Quantization Bits",
9864
+ children: Object.keys(exporter.exportOptions.dracoOptions?.quantizationBits || {}).map((k) => ({
9855
9865
  type: "slider",
9856
- label: "Encode Speed",
9857
- bounds: [1, 10],
9858
- property: [exporter.exportOptions.dracoOptions, "encodeSpeed"]
9859
- },
9860
- {
9861
- type: "dropdown",
9862
- label: "Encoder Method",
9863
- property: [exporter.exportOptions.dracoOptions, "method"],
9864
- children: Object.entries(EncoderMethod).map(([k, v]) => ({ label: k, value: v }))
9865
- },
9866
- {
9867
- type: "dropdown",
9868
- label: "Quantization Volume",
9869
- property: [exporter.exportOptions.dracoOptions, "quantizationVolume"],
9870
- children: ["mesh", "scene", "bbox"].map((v) => ({ label: v }))
9871
- },
9872
- {
9873
- type: "folder",
9874
- label: "Quantization Bits",
9875
- children: Object.keys(((_a = exporter.exportOptions.dracoOptions) == null ? void 0 : _a.quantizationBits) || {}).map((k) => {
9876
- var _a2;
9877
- return {
9878
- type: "slider",
9879
- label: k,
9880
- bounds: [1, 16],
9881
- stepSize: 1,
9882
- property: [(_a2 = exporter.exportOptions.dracoOptions) == null ? void 0 : _a2.quantizationBits, k]
9883
- };
9884
- })
9885
- }
9886
- ]
9887
- }
9888
- ];
9889
- };
9866
+ label: k,
9867
+ bounds: [1, 16],
9868
+ stepSize: 1,
9869
+ property: [exporter.exportOptions.dracoOptions?.quantizationBits, k]
9870
+ }))
9871
+ }
9872
+ ]
9873
+ }
9874
+ ];
9890
9875
  }
9891
9876
  get gltfTransformExtensions() {
9892
9877
  return [GLTFViewerConfigExtensionGP, ...this.extraExtensions.map((e) => createGenericExtensionClass(e[0], e[1]))];
@@ -9907,11 +9892,10 @@ const _GLTFDracoExportPlugin = class _GLTFDracoExportPlugin extends AViewerPlugi
9907
9892
  if (ext >= 0) this.extraExtensions.splice(ext, 1);
9908
9893
  }
9909
9894
  onAdded(viewer) {
9910
- var _a;
9911
9895
  super.onAdded(viewer);
9912
9896
  const exporter = viewer.assetManager.exporter;
9913
9897
  let glbExporter = exporter.getExporter("glb");
9914
- this._lastExporter = glbExporter == null ? void 0 : glbExporter.ctor;
9898
+ this._lastExporter = glbExporter?.ctor;
9915
9899
  if (!glbExporter) {
9916
9900
  console.error("GLTFDracoExportPlugin: GLB exporter not found in AssetManager.exporter, creating a new one.");
9917
9901
  glbExporter = {
@@ -9940,7 +9924,7 @@ const _GLTFDracoExportPlugin = class _GLTFDracoExportPlugin extends AViewerPlugi
9940
9924
  }
9941
9925
  }
9942
9926
  });
9943
- const exportOptions = (_a = exportPlugin.uiConfig.children) == null ? void 0 : _a.find((c) => c.label === "GLB Export");
9927
+ const exportOptions = exportPlugin.uiConfig.children?.find((c) => c.label === "GLB Export");
9944
9928
  if (exportOptions) {
9945
9929
  exportOptions.children = [this._makeUi(exportPlugin), ...exportOptions.children || []];
9946
9930
  } else {
@@ -9977,12 +9961,6 @@ function requireIota() {
9977
9961
  iota_1 = iota;
9978
9962
  return iota_1;
9979
9963
  }
9980
- /*!
9981
- * Determine if an object is a Buffer
9982
- *
9983
- * @author Feross Aboukhadijeh <https://feross.org>
9984
- * @license MIT
9985
- */
9986
9964
  var isBuffer_1;
9987
9965
  var hasRequiredIsBuffer;
9988
9966
  function requireIsBuffer() {
@@ -10788,7 +10766,7 @@ var hasRequiredNdarrayOps;
10788
10766
  function requireNdarrayOps() {
10789
10767
  if (hasRequiredNdarrayOps) return ndarrayOps;
10790
10768
  hasRequiredNdarrayOps = 1;
10791
- (function(exports) {
10769
+ (function(exports$1) {
10792
10770
  var compile2 = requireCompiler();
10793
10771
  var EmptyProc = {
10794
10772
  body: "",
@@ -10857,7 +10835,7 @@ function requireNdarrayOps() {
10857
10835
  (function() {
10858
10836
  for (var id in assign_ops) {
10859
10837
  var op = assign_ops[id];
10860
- exports[id] = makeOp({
10838
+ exports$1[id] = makeOp({
10861
10839
  args: ["array", "array", "array"],
10862
10840
  body: {
10863
10841
  args: ["a", "b", "c"],
@@ -10865,7 +10843,7 @@ function requireNdarrayOps() {
10865
10843
  },
10866
10844
  funcName: id
10867
10845
  });
10868
- exports[id + "eq"] = makeOp({
10846
+ exports$1[id + "eq"] = makeOp({
10869
10847
  args: ["array", "array"],
10870
10848
  body: {
10871
10849
  args: ["a", "b"],
@@ -10873,7 +10851,7 @@ function requireNdarrayOps() {
10873
10851
  },
10874
10852
  funcName: id + "eq"
10875
10853
  });
10876
- exports[id + "s"] = makeOp({
10854
+ exports$1[id + "s"] = makeOp({
10877
10855
  args: ["array", "array", "scalar"],
10878
10856
  body: {
10879
10857
  args: ["a", "b", "s"],
@@ -10881,7 +10859,7 @@ function requireNdarrayOps() {
10881
10859
  },
10882
10860
  funcName: id + "s"
10883
10861
  });
10884
- exports[id + "seq"] = makeOp({
10862
+ exports$1[id + "seq"] = makeOp({
10885
10863
  args: ["array", "scalar"],
10886
10864
  body: {
10887
10865
  args: ["a", "s"],
@@ -10900,7 +10878,7 @@ function requireNdarrayOps() {
10900
10878
  (function() {
10901
10879
  for (var id in unary_ops) {
10902
10880
  var op = unary_ops[id];
10903
- exports[id] = makeOp({
10881
+ exports$1[id] = makeOp({
10904
10882
  args: ["array", "array"],
10905
10883
  body: {
10906
10884
  args: ["a", "b"],
@@ -10908,7 +10886,7 @@ function requireNdarrayOps() {
10908
10886
  },
10909
10887
  funcName: id
10910
10888
  });
10911
- exports[id + "eq"] = makeOp({
10889
+ exports$1[id + "eq"] = makeOp({
10912
10890
  args: ["array"],
10913
10891
  body: {
10914
10892
  args: ["a"],
@@ -10931,7 +10909,7 @@ function requireNdarrayOps() {
10931
10909
  (function() {
10932
10910
  for (var id in binary_ops) {
10933
10911
  var op = binary_ops[id];
10934
- exports[id] = makeOp({
10912
+ exports$1[id] = makeOp({
10935
10913
  args: ["array", "array", "array"],
10936
10914
  body: {
10937
10915
  args: ["a", "b", "c"],
@@ -10939,7 +10917,7 @@ function requireNdarrayOps() {
10939
10917
  },
10940
10918
  funcName: id
10941
10919
  });
10942
- exports[id + "s"] = makeOp({
10920
+ exports$1[id + "s"] = makeOp({
10943
10921
  args: ["array", "array", "scalar"],
10944
10922
  body: {
10945
10923
  args: ["a", "b", "s"],
@@ -10947,7 +10925,7 @@ function requireNdarrayOps() {
10947
10925
  },
10948
10926
  funcName: id + "s"
10949
10927
  });
10950
- exports[id + "eq"] = makeOp({
10928
+ exports$1[id + "eq"] = makeOp({
10951
10929
  args: ["array", "array"],
10952
10930
  body: {
10953
10931
  args: ["a", "b"],
@@ -10955,7 +10933,7 @@ function requireNdarrayOps() {
10955
10933
  },
10956
10934
  funcName: id + "eq"
10957
10935
  });
10958
- exports[id + "seq"] = makeOp({
10936
+ exports$1[id + "seq"] = makeOp({
10959
10937
  args: ["array", "scalar"],
10960
10938
  body: {
10961
10939
  args: ["a", "s"],
@@ -10983,13 +10961,13 @@ function requireNdarrayOps() {
10983
10961
  (function() {
10984
10962
  for (var i = 0; i < math_unary.length; ++i) {
10985
10963
  var f = math_unary[i];
10986
- exports[f] = makeOp({
10964
+ exports$1[f] = makeOp({
10987
10965
  args: ["array", "array"],
10988
10966
  pre: { args: [], body: "this_f=Math." + f, thisVars: ["this_f"] },
10989
10967
  body: { args: ["a", "b"], body: "a=this_f(b)", thisVars: ["this_f"] },
10990
10968
  funcName: f
10991
10969
  });
10992
- exports[f + "eq"] = makeOp({
10970
+ exports$1[f + "eq"] = makeOp({
10993
10971
  args: ["array"],
10994
10972
  pre: { args: [], body: "this_f=Math." + f, thisVars: ["this_f"] },
10995
10973
  body: { args: ["a"], body: "a=this_f(a)", thisVars: ["this_f"] },
@@ -11006,25 +10984,25 @@ function requireNdarrayOps() {
11006
10984
  (function() {
11007
10985
  for (var i = 0; i < math_comm.length; ++i) {
11008
10986
  var f = math_comm[i];
11009
- exports[f] = makeOp({
10987
+ exports$1[f] = makeOp({
11010
10988
  args: ["array", "array", "array"],
11011
10989
  pre: { args: [], body: "this_f=Math." + f, thisVars: ["this_f"] },
11012
10990
  body: { args: ["a", "b", "c"], body: "a=this_f(b,c)", thisVars: ["this_f"] },
11013
10991
  funcName: f
11014
10992
  });
11015
- exports[f + "s"] = makeOp({
10993
+ exports$1[f + "s"] = makeOp({
11016
10994
  args: ["array", "array", "scalar"],
11017
10995
  pre: { args: [], body: "this_f=Math." + f, thisVars: ["this_f"] },
11018
10996
  body: { args: ["a", "b", "c"], body: "a=this_f(b,c)", thisVars: ["this_f"] },
11019
10997
  funcName: f + "s"
11020
10998
  });
11021
- exports[f + "eq"] = makeOp({
10999
+ exports$1[f + "eq"] = makeOp({
11022
11000
  args: ["array", "array"],
11023
11001
  pre: { args: [], body: "this_f=Math." + f, thisVars: ["this_f"] },
11024
11002
  body: { args: ["a", "b"], body: "a=this_f(a,b)", thisVars: ["this_f"] },
11025
11003
  funcName: f + "eq"
11026
11004
  });
11027
- exports[f + "seq"] = makeOp({
11005
+ exports$1[f + "seq"] = makeOp({
11028
11006
  args: ["array", "scalar"],
11029
11007
  pre: { args: [], body: "this_f=Math." + f, thisVars: ["this_f"] },
11030
11008
  body: { args: ["a", "b"], body: "a=this_f(a,b)", thisVars: ["this_f"] },
@@ -11039,25 +11017,25 @@ function requireNdarrayOps() {
11039
11017
  (function() {
11040
11018
  for (var i = 0; i < math_noncomm.length; ++i) {
11041
11019
  var f = math_noncomm[i];
11042
- exports[f + "op"] = makeOp({
11020
+ exports$1[f + "op"] = makeOp({
11043
11021
  args: ["array", "array", "array"],
11044
11022
  pre: { args: [], body: "this_f=Math." + f, thisVars: ["this_f"] },
11045
11023
  body: { args: ["a", "b", "c"], body: "a=this_f(c,b)", thisVars: ["this_f"] },
11046
11024
  funcName: f + "op"
11047
11025
  });
11048
- exports[f + "ops"] = makeOp({
11026
+ exports$1[f + "ops"] = makeOp({
11049
11027
  args: ["array", "array", "scalar"],
11050
11028
  pre: { args: [], body: "this_f=Math." + f, thisVars: ["this_f"] },
11051
11029
  body: { args: ["a", "b", "c"], body: "a=this_f(c,b)", thisVars: ["this_f"] },
11052
11030
  funcName: f + "ops"
11053
11031
  });
11054
- exports[f + "opeq"] = makeOp({
11032
+ exports$1[f + "opeq"] = makeOp({
11055
11033
  args: ["array", "array"],
11056
11034
  pre: { args: [], body: "this_f=Math." + f, thisVars: ["this_f"] },
11057
11035
  body: { args: ["a", "b"], body: "a=this_f(b,a)", thisVars: ["this_f"] },
11058
11036
  funcName: f + "opeq"
11059
11037
  });
11060
- exports[f + "opseq"] = makeOp({
11038
+ exports$1[f + "opseq"] = makeOp({
11061
11039
  args: ["array", "scalar"],
11062
11040
  pre: { args: [], body: "this_f=Math." + f, thisVars: ["this_f"] },
11063
11041
  body: { args: ["a", "b"], body: "a=this_f(b,a)", thisVars: ["this_f"] },
@@ -11065,63 +11043,63 @@ function requireNdarrayOps() {
11065
11043
  });
11066
11044
  }
11067
11045
  })();
11068
- exports.any = compile2({
11046
+ exports$1.any = compile2({
11069
11047
  args: ["array"],
11070
11048
  pre: EmptyProc,
11071
11049
  body: { args: [{ name: "a", lvalue: false, rvalue: true, count: 1 }], body: "if(a){return true}", localVars: [], thisVars: [] },
11072
11050
  post: { args: [], localVars: [], thisVars: [], body: "return false" },
11073
11051
  funcName: "any"
11074
11052
  });
11075
- exports.all = compile2({
11053
+ exports$1.all = compile2({
11076
11054
  args: ["array"],
11077
11055
  pre: EmptyProc,
11078
11056
  body: { args: [{ name: "x", lvalue: false, rvalue: true, count: 1 }], body: "if(!x){return false}", localVars: [], thisVars: [] },
11079
11057
  post: { args: [], localVars: [], thisVars: [], body: "return true" },
11080
11058
  funcName: "all"
11081
11059
  });
11082
- exports.sum = compile2({
11060
+ exports$1.sum = compile2({
11083
11061
  args: ["array"],
11084
11062
  pre: { args: [], localVars: [], thisVars: ["this_s"], body: "this_s=0" },
11085
11063
  body: { args: [{ name: "a", lvalue: false, rvalue: true, count: 1 }], body: "this_s+=a", localVars: [], thisVars: ["this_s"] },
11086
11064
  post: { args: [], localVars: [], thisVars: ["this_s"], body: "return this_s" },
11087
11065
  funcName: "sum"
11088
11066
  });
11089
- exports.prod = compile2({
11067
+ exports$1.prod = compile2({
11090
11068
  args: ["array"],
11091
11069
  pre: { args: [], localVars: [], thisVars: ["this_s"], body: "this_s=1" },
11092
11070
  body: { args: [{ name: "a", lvalue: false, rvalue: true, count: 1 }], body: "this_s*=a", localVars: [], thisVars: ["this_s"] },
11093
11071
  post: { args: [], localVars: [], thisVars: ["this_s"], body: "return this_s" },
11094
11072
  funcName: "prod"
11095
11073
  });
11096
- exports.norm2squared = compile2({
11074
+ exports$1.norm2squared = compile2({
11097
11075
  args: ["array"],
11098
11076
  pre: { args: [], localVars: [], thisVars: ["this_s"], body: "this_s=0" },
11099
11077
  body: { args: [{ name: "a", lvalue: false, rvalue: true, count: 2 }], body: "this_s+=a*a", localVars: [], thisVars: ["this_s"] },
11100
11078
  post: { args: [], localVars: [], thisVars: ["this_s"], body: "return this_s" },
11101
11079
  funcName: "norm2squared"
11102
11080
  });
11103
- exports.norm2 = compile2({
11081
+ exports$1.norm2 = compile2({
11104
11082
  args: ["array"],
11105
11083
  pre: { args: [], localVars: [], thisVars: ["this_s"], body: "this_s=0" },
11106
11084
  body: { args: [{ name: "a", lvalue: false, rvalue: true, count: 2 }], body: "this_s+=a*a", localVars: [], thisVars: ["this_s"] },
11107
11085
  post: { args: [], localVars: [], thisVars: ["this_s"], body: "return Math.sqrt(this_s)" },
11108
11086
  funcName: "norm2"
11109
11087
  });
11110
- exports.norminf = compile2({
11088
+ exports$1.norminf = compile2({
11111
11089
  args: ["array"],
11112
11090
  pre: { args: [], localVars: [], thisVars: ["this_s"], body: "this_s=0" },
11113
11091
  body: { args: [{ name: "a", lvalue: false, rvalue: true, count: 4 }], body: "if(-a>this_s){this_s=-a}else if(a>this_s){this_s=a}", localVars: [], thisVars: ["this_s"] },
11114
11092
  post: { args: [], localVars: [], thisVars: ["this_s"], body: "return this_s" },
11115
11093
  funcName: "norminf"
11116
11094
  });
11117
- exports.norm1 = compile2({
11095
+ exports$1.norm1 = compile2({
11118
11096
  args: ["array"],
11119
11097
  pre: { args: [], localVars: [], thisVars: ["this_s"], body: "this_s=0" },
11120
11098
  body: { args: [{ name: "a", lvalue: false, rvalue: true, count: 3 }], body: "this_s+=a<0?-a:a", localVars: [], thisVars: ["this_s"] },
11121
11099
  post: { args: [], localVars: [], thisVars: ["this_s"], body: "return this_s" },
11122
11100
  funcName: "norm1"
11123
11101
  });
11124
- exports.sup = compile2({
11102
+ exports$1.sup = compile2({
11125
11103
  args: ["array"],
11126
11104
  pre: {
11127
11105
  body: "this_h=-Infinity",
@@ -11142,7 +11120,7 @@ function requireNdarrayOps() {
11142
11120
  localVars: []
11143
11121
  }
11144
11122
  });
11145
- exports.inf = compile2({
11123
+ exports$1.inf = compile2({
11146
11124
  args: ["array"],
11147
11125
  pre: {
11148
11126
  body: "this_h=Infinity",
@@ -11163,7 +11141,7 @@ function requireNdarrayOps() {
11163
11141
  localVars: []
11164
11142
  }
11165
11143
  });
11166
- exports.argmin = compile2({
11144
+ exports$1.argmin = compile2({
11167
11145
  args: ["index", "array", "shape"],
11168
11146
  pre: {
11169
11147
  body: "{this_v=Infinity;this_i=_inline_0_arg2_.slice(0)}",
@@ -11191,7 +11169,7 @@ function requireNdarrayOps() {
11191
11169
  localVars: []
11192
11170
  }
11193
11171
  });
11194
- exports.argmax = compile2({
11172
+ exports$1.argmax = compile2({
11195
11173
  args: ["index", "array", "shape"],
11196
11174
  pre: {
11197
11175
  body: "{this_v=-Infinity;this_i=_inline_0_arg2_.slice(0)}",
@@ -11219,23 +11197,23 @@ function requireNdarrayOps() {
11219
11197
  localVars: []
11220
11198
  }
11221
11199
  });
11222
- exports.random = makeOp({
11200
+ exports$1.random = makeOp({
11223
11201
  args: ["array"],
11224
11202
  pre: { args: [], body: "this_f=Math.random", thisVars: ["this_f"] },
11225
11203
  body: { args: ["a"], body: "a=this_f()", thisVars: ["this_f"] },
11226
11204
  funcName: "random"
11227
11205
  });
11228
- exports.assign = makeOp({
11206
+ exports$1.assign = makeOp({
11229
11207
  args: ["array", "array"],
11230
11208
  body: { args: ["a", "b"], body: "a=b" },
11231
11209
  funcName: "assign"
11232
11210
  });
11233
- exports.assigns = makeOp({
11211
+ exports$1.assigns = makeOp({
11234
11212
  args: ["array", "scalar"],
11235
11213
  body: { args: ["a", "b"], body: "a=b" },
11236
11214
  funcName: "assigns"
11237
11215
  });
11238
- exports.equals = compile2({
11216
+ exports$1.equals = compile2({
11239
11217
  args: ["array", "array"],
11240
11218
  pre: EmptyProc,
11241
11219
  body: {
@@ -11603,7 +11581,7 @@ var TextureResizeFilter;
11603
11581
  ({
11604
11582
  resizeFilter: TextureResizeFilter.LANCZOS3
11605
11583
  });
11606
- const _GLTFSpecGlossinessConverterPlugin = class _GLTFSpecGlossinessConverterPlugin extends AViewerPluginSync {
11584
+ const _GLTFSpecGlossinessConverterPluginBase = class _GLTFSpecGlossinessConverterPluginBase extends AViewerPluginSync {
11607
11585
  constructor() {
11608
11586
  super();
11609
11587
  this.enabled = true;
@@ -11613,16 +11591,12 @@ const _GLTFSpecGlossinessConverterPlugin = class _GLTFSpecGlossinessConverterPlu
11613
11591
  this._loaderCreate = this._loaderCreate.bind(this);
11614
11592
  }
11615
11593
  _loaderCreate({ loader }) {
11616
- var _a;
11617
11594
  if (!loader.isGLTFLoader2) return;
11618
- const ep = (_a = this._viewer) == null ? void 0 : _a.getPlugin(GLTFDracoExportPlugin);
11595
+ const ep = this._viewer?.getPlugin(GLTFDracoExportPlugin);
11619
11596
  if (!ep) {
11620
11597
  console.error("GLTFSpecGlossinessConverterPlugin requires GLTFDracoExportPlugin in the plugin for extra extensions");
11621
11598
  }
11622
- loader.register(gltfKhrPbrSpecularGlossinessConverter(async (m) => {
11623
- var _a2;
11624
- return !this.enabled ? false : !this.confirm ? true : ((_a2 = this._viewer) == null ? void 0 : _a2.dialog.confirm(this.confirmMessage || m)) ?? true;
11625
- }, ep == null ? void 0 : ep.gltfTransformExtensions));
11599
+ loader.register(gltfKhrPbrSpecularGlossinessConverterBase(() => this._createIO(), async (m) => !this.enabled ? false : !this.confirm ? true : this._viewer?.dialog.confirm(this.confirmMessage || m) ?? true, ep?.gltfTransformExtensions));
11626
11600
  }
11627
11601
  onAdded(v) {
11628
11602
  super.onAdded(v);
@@ -11633,18 +11607,17 @@ const _GLTFSpecGlossinessConverterPlugin = class _GLTFSpecGlossinessConverterPlu
11633
11607
  return super.onRemove(v);
11634
11608
  }
11635
11609
  };
11636
- _GLTFSpecGlossinessConverterPlugin.PluginType = "GLTFSpecGlossinessConverterPlugin";
11637
- let GLTFSpecGlossinessConverterPlugin = _GLTFSpecGlossinessConverterPlugin;
11638
- const gltfKhrPbrSpecularGlossinessConverter = (confirm, extensions) => (parser) => ({
11610
+ _GLTFSpecGlossinessConverterPluginBase.PluginType = "GLTFSpecGlossinessConverterPlugin";
11611
+ let GLTFSpecGlossinessConverterPluginBase = _GLTFSpecGlossinessConverterPluginBase;
11612
+ const gltfKhrPbrSpecularGlossinessConverterBase = (ioFactory, confirm, extensions) => (parser) => ({
11639
11613
  name: "KHR_materials_pbrSpecularGlossiness",
11640
11614
  beforeRoot: async () => {
11641
- var _a, _b, _c;
11642
11615
  try {
11643
11616
  if (!parser.json.extensionsUsed || !parser.json.extensionsUsed.includes("KHR_materials_pbrSpecularGlossiness")) return;
11644
- const doConfirm = ((_a = parser.importOptions) == null ? void 0 : _a.confirmSpecGlossConversion) ?? true;
11617
+ const doConfirm = parser.importOptions?.confirmSpecGlossConversion ?? true;
11645
11618
  if (doConfirm && confirm && !await confirm("Convert KHR_materials_pbrSpecularGlossiness to KHR_materials_pbrMetallicRoughness?")) return;
11646
11619
  const json = parser.json;
11647
- const io = new WebIO().registerExtensions(ALL_EXTENSIONS).registerExtensions(extensions ?? []);
11620
+ const io = ioFactory().registerExtensions(ALL_EXTENSIONS).registerExtensions(extensions ?? []);
11648
11621
  if (parser.extensions.KHR_draco_mesh_compression) {
11649
11622
  const dracoLoader = parser.extensions.KHR_draco_mesh_compression.dracoLoader;
11650
11623
  if (!dracoLoader.isDRACOLoader2) {
@@ -11660,12 +11633,12 @@ const gltfKhrPbrSpecularGlossinessConverter = (confirm, extensions) => (parser)
11660
11633
  const document = await io.readJSON({
11661
11634
  json,
11662
11635
  resources: {
11663
- ["@glb.bin"]: new Uint8Array((_b = parser.extensions.KHR_binary_glTF) == null ? void 0 : _b.body)
11636
+ ["@glb.bin"]: new Uint8Array(parser.extensions.KHR_binary_glTF?.body)
11664
11637
  }
11665
11638
  });
11666
11639
  await document.transform(metalRough());
11667
11640
  if (parser.extensions.KHR_draco_mesh_compression) {
11668
- (_c = document.getRoot().listExtensionsUsed().find((e) => e.extensionName === "KHR_draco_mesh_compression")) == null ? void 0 : _c.dispose();
11641
+ document.getRoot().listExtensionsUsed().find((e) => e.extensionName === "KHR_draco_mesh_compression")?.dispose();
11669
11642
  }
11670
11643
  const res = await io.writeBinary(document);
11671
11644
  const binaryExtension = new GLTFBinaryExtension(res.buffer);
@@ -11677,12 +11650,22 @@ const gltfKhrPbrSpecularGlossinessConverter = (confirm, extensions) => (parser)
11677
11650
  }
11678
11651
  }
11679
11652
  });
11653
+ class GLTFSpecGlossinessConverterPlugin extends GLTFSpecGlossinessConverterPluginBase {
11654
+ _createIO() {
11655
+ return new WebIO();
11656
+ }
11657
+ }
11658
+ const gltfKhrPbrSpecularGlossinessConverter = (confirm, extensions) => gltfKhrPbrSpecularGlossinessConverterBase(() => new WebIO(), confirm, extensions);
11680
11659
  export {
11681
11660
  EncoderMethod,
11682
11661
  GLTFDracoExportPlugin,
11683
11662
  GLTFDracoExporter,
11663
+ GLTFDracoExporterBase,
11684
11664
  GLTFSpecGlossinessConverterPlugin,
11665
+ GLTFSpecGlossinessConverterPluginBase,
11666
+ GLTFViewerConfigExtensionGP,
11685
11667
  createGenericExtensionClass,
11686
- gltfKhrPbrSpecularGlossinessConverter
11668
+ gltfKhrPbrSpecularGlossinessConverter,
11669
+ gltfKhrPbrSpecularGlossinessConverterBase
11687
11670
  };
11688
11671
  //# sourceMappingURL=index.mjs.map