@onerjs/loaders 8.33.3 → 8.33.4

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.
@@ -3,7 +3,7 @@ import { FlowGraphBlockNames } from "@onerjs/core/FlowGraph/Blocks/flowGraphBloc
3
3
  import type { ISerializedFlowGraphBlock, ISerializedFlowGraphContext } from "@onerjs/core/FlowGraph/typeDefinitions.js";
4
4
  import type { InteractivityGraphToFlowGraphParser } from "./interactivityGraphParser.js";
5
5
  import type { IGLTF } from "../../glTFLoaderInterfaces.js";
6
- interface IGLTFToFlowGraphMappingObject<I = any, O = any> {
6
+ interface IGLTFToFlowGraphMappingObject {
7
7
  /**
8
8
  * The name of the property in the FlowGraph block.
9
9
  */
@@ -21,16 +21,15 @@ interface IGLTFToFlowGraphMappingObject<I = any, O = any> {
21
21
  /**
22
22
  * A function that transforms the data from the glTF to the FlowGraph block.
23
23
  */
24
- dataTransformer?: (data: I[], parser: InteractivityGraphToFlowGraphParser) => O[];
24
+ dataTransformer?: (data: any, parser: InteractivityGraphToFlowGraphParser) => any;
25
25
  /**
26
- * If the property is in the options passed to the constructor of the block.
26
+ * If the property can contain multiple values.
27
27
  */
28
- inOptions?: boolean;
28
+ isArray?: boolean;
29
29
  /**
30
- * If the property is a pointer to a value.
31
- * This will add an extra JsonPointerParser block to the graph.
30
+ * If the property is in the options passed to the constructor of the block.
32
31
  */
33
- isPointer?: boolean;
32
+ inOptions?: boolean;
34
33
  /**
35
34
  * If the property is an index to a value.
36
35
  * if defined this will be the name of the array to find the object in.
@@ -45,7 +44,7 @@ interface IGLTFToFlowGraphMappingObject<I = any, O = any> {
45
44
  /**
46
45
  * Used in configuration values. If defined, this will be the default value, if no value is provided.
47
46
  */
48
- defaultValue?: O;
47
+ defaultValue?: any;
49
48
  }
50
49
  export interface IGLTFToFlowGraphMapping {
51
50
  /**
@@ -103,7 +103,7 @@ const gltfToFlowGraphMapping = {
103
103
  throw new Error("Receive event should have a single configuration object, the event itself");
104
104
  }
105
105
  const eventConfiguration = gltfBlock.configuration["event"];
106
- const eventId = eventConfiguration.value[0];
106
+ const eventId = eventConfiguration.value?.[0];
107
107
  if (typeof eventId !== "number") {
108
108
  throw new Error("Event id should be a number");
109
109
  }
@@ -132,7 +132,7 @@ const gltfToFlowGraphMapping = {
132
132
  Logger.Error("Receive event should have a single configuration object, the event itself");
133
133
  return { valid: false, error: "Receive event should have a single configuration object, the event itself" };
134
134
  }
135
- const eventId = eventConfiguration.value[0];
135
+ const eventId = eventConfiguration.value?.[0];
136
136
  if (typeof eventId !== "number") {
137
137
  Logger.Error("Event id should be a number");
138
138
  return { valid: false, error: "Event id should be a number" };
@@ -151,7 +151,7 @@ const gltfToFlowGraphMapping = {
151
151
  throw new Error("Receive event should have a single configuration object, the event itself");
152
152
  }
153
153
  const eventConfiguration = gltfBlock.configuration["event"];
154
- const eventId = eventConfiguration.value[0];
154
+ const eventId = eventConfiguration.value?.[0];
155
155
  if (typeof eventId !== "number") {
156
156
  throw new Error("Event id should be a number");
157
157
  }
@@ -795,7 +795,7 @@ const gltfToFlowGraphMapping = {
795
795
  "flow/switch": {
796
796
  blocks: ["FlowGraphSwitchBlock" /* FlowGraphBlockNames.Switch */],
797
797
  configuration: {
798
- cases: { name: "cases", inOptions: true, defaultValue: [] },
798
+ cases: { name: "cases", isArray: true, inOptions: true, defaultValue: [] },
799
799
  },
800
800
  inputs: {
801
801
  values: {
@@ -804,20 +804,20 @@ const gltfToFlowGraphMapping = {
804
804
  },
805
805
  },
806
806
  validation(gltfBlock) {
807
- if (gltfBlock.configuration && gltfBlock.configuration.cases) {
808
- const cases = gltfBlock.configuration.cases.value;
809
- const onlyIntegers = cases.every((caseValue) => {
807
+ const cases = gltfBlock.configuration?.cases;
808
+ if (cases && cases.value) {
809
+ const onlyIntegers = cases.value.every((caseValue) => {
810
810
  // case value should be an integer. Since Number.isInteger(1.0) is true, we need to check if toString has only digits.
811
811
  return typeof caseValue === "number" && /^-?\d+$/.test(caseValue.toString());
812
812
  });
813
813
  if (!onlyIntegers) {
814
814
  Logger.Warn("Switch cases should be integers. Using empty array instead.");
815
- gltfBlock.configuration.cases.value = [];
815
+ cases.value = [];
816
816
  return { valid: true };
817
817
  }
818
818
  // check for duplicates
819
- const uniqueCases = new Set(cases);
820
- gltfBlock.configuration.cases.value = Array.from(uniqueCases);
819
+ const uniqueCases = new Set(cases.value);
820
+ cases.value = Array.from(uniqueCases);
821
821
  }
822
822
  return { valid: true };
823
823
  },
@@ -915,7 +915,7 @@ const gltfToFlowGraphMapping = {
915
915
  },
916
916
  validation(gltfBlock) {
917
917
  // check that the configuration value is an integer
918
- if (typeof gltfBlock.configuration?.inputFlows?.value[0] !== "number") {
918
+ if (typeof gltfBlock.configuration?.inputFlows?.value?.[0] !== "number") {
919
919
  gltfBlock.configuration = gltfBlock.configuration || {
920
920
  inputFlows: { value: [0] },
921
921
  };
@@ -960,27 +960,12 @@ const gltfToFlowGraphMapping = {
960
960
  inOptions: true,
961
961
  isVariable: true,
962
962
  dataTransformer(index, parser) {
963
- return [parser.getVariableName(index[0])];
963
+ return parser.getVariableName(index);
964
964
  },
965
965
  },
966
966
  },
967
967
  },
968
968
  "variable/set": {
969
- blocks: ["FlowGraphSetVariableBlock" /* FlowGraphBlockNames.SetVariable */],
970
- configuration: {
971
- variable: {
972
- name: "variable",
973
- gltfType: "number",
974
- flowGraphType: "string",
975
- inOptions: true,
976
- isVariable: true,
977
- dataTransformer(index, parser) {
978
- return [parser.getVariableName(index[0])];
979
- },
980
- },
981
- },
982
- },
983
- "variable/setMultiple": {
984
969
  blocks: ["FlowGraphSetVariableBlock" /* FlowGraphBlockNames.SetVariable */],
985
970
  configuration: {
986
971
  variables: {
@@ -988,8 +973,9 @@ const gltfToFlowGraphMapping = {
988
973
  gltfType: "number",
989
974
  flowGraphType: "string",
990
975
  inOptions: true,
976
+ isArray: true,
991
977
  dataTransformer(index, parser) {
992
- return [index[0].map((i) => parser.getVariableName(i))];
978
+ return index.map((i) => parser.getVariableName(i));
993
979
  },
994
980
  },
995
981
  },
@@ -1016,20 +1002,15 @@ const gltfToFlowGraphMapping = {
1016
1002
  inOptions: true,
1017
1003
  isVariable: true,
1018
1004
  dataTransformer(index, parser) {
1019
- return [parser.getVariableName(index[0])];
1005
+ return parser.getVariableName(index);
1020
1006
  },
1021
1007
  },
1022
1008
  useSlerp: {
1023
1009
  name: "animationType",
1024
1010
  inOptions: true,
1025
1011
  defaultValue: false,
1026
- dataTransformer: (value) => {
1027
- if (value[0] === true) {
1028
- return ["Quaternion" /* FlowGraphTypes.Quaternion */];
1029
- }
1030
- else {
1031
- return [undefined];
1032
- }
1012
+ dataTransformer(value) {
1013
+ return value === true ? "Quaternion" /* FlowGraphTypes.Quaternion */ : undefined;
1033
1014
  },
1034
1015
  },
1035
1016
  },
@@ -1085,25 +1066,23 @@ const gltfToFlowGraphMapping = {
1085
1066
  var _a, _b;
1086
1067
  // is useSlerp is used, animationType should be set to be quaternion!
1087
1068
  const serializedValueInterpolation = serializedObjects[0];
1088
- const propertyIndex = gltfBlock.configuration?.variable.value[0];
1069
+ const propertyIndex = gltfBlock.configuration?.variable.value?.[0];
1089
1070
  if (typeof propertyIndex !== "number") {
1090
1071
  Logger.Error("Variable index is not defined for variable interpolation block");
1091
1072
  throw new Error("Variable index is not defined for variable interpolation block");
1092
1073
  }
1093
1074
  const variable = parser.arrays.staticVariables[propertyIndex];
1094
1075
  // if not set by useSlerp
1095
- if (typeof serializedValueInterpolation.config.animationType.value === "undefined") {
1096
- // get the value type
1097
- parser.arrays.staticVariables;
1076
+ if (typeof serializedValueInterpolation.config?.animationType?.value === "undefined") {
1077
+ serializedValueInterpolation.config || (serializedValueInterpolation.config = {});
1078
+ (_a = serializedValueInterpolation.config).animationType || (_a.animationType = {});
1098
1079
  serializedValueInterpolation.config.animationType.value = getAnimationTypeByFlowGraphType(variable.type);
1099
1080
  }
1100
1081
  // variable/get configuration
1101
1082
  const serializedGetVariable = serializedObjects[4];
1102
1083
  serializedGetVariable.config || (serializedGetVariable.config = {});
1103
- (_a = serializedGetVariable.config).variable || (_a.variable = {});
1084
+ (_b = serializedGetVariable.config).variable || (_b.variable = {});
1104
1085
  serializedGetVariable.config.variable.value = parser.getVariableName(propertyIndex);
1105
- // get the control points from the easing block
1106
- (_b = serializedObjects[3]).config || (_b.config = {});
1107
1086
  return serializedObjects;
1108
1087
  },
1109
1088
  },
@@ -1411,7 +1390,7 @@ const gltfToFlowGraphMapping = {
1411
1390
  "math/switch": {
1412
1391
  blocks: ["FlowGraphDataSwitchBlock" /* FlowGraphBlockNames.DataSwitch */],
1413
1392
  configuration: {
1414
- cases: { name: "cases", inOptions: true, defaultValue: [] },
1393
+ cases: { name: "cases", isArray: true, inOptions: true, defaultValue: [] },
1415
1394
  },
1416
1395
  inputs: {
1417
1396
  values: {
@@ -1419,20 +1398,20 @@ const gltfToFlowGraphMapping = {
1419
1398
  },
1420
1399
  },
1421
1400
  validation(gltfBlock) {
1422
- if (gltfBlock.configuration && gltfBlock.configuration.cases) {
1423
- const cases = gltfBlock.configuration.cases.value;
1424
- const onlyIntegers = cases.every((caseValue) => {
1401
+ const cases = gltfBlock.configuration?.cases;
1402
+ if (cases && cases.value) {
1403
+ const onlyIntegers = cases.value.every((caseValue) => {
1425
1404
  // case value should be an integer. Since Number.isInteger(1.0) is true, we need to check if toString has only digits.
1426
1405
  return typeof caseValue === "number" && /^-?\d+$/.test(caseValue.toString());
1427
1406
  });
1428
1407
  if (!onlyIntegers) {
1429
1408
  Logger.Warn("Switch cases should be integers. Using empty array instead.");
1430
- gltfBlock.configuration.cases.value = [];
1409
+ cases.value = [];
1431
1410
  return { valid: true };
1432
1411
  }
1433
1412
  // check for duplicates
1434
- const uniqueCases = new Set(cases);
1435
- gltfBlock.configuration.cases.value = Array.from(uniqueCases);
1413
+ const uniqueCases = new Set(cases.value);
1414
+ cases.value = Array.from(uniqueCases);
1436
1415
  }
1437
1416
  return { valid: true };
1438
1417
  },