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