@forgeax/engine-import 0.1.24 → 0.1.25

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.
@@ -1 +1 @@
1
- {"version":3,"file":"build-production.d.ts","sourceRoot":"","sources":["../src/build-production.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,kBAAkB,EAKxB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AASvE,OAAO,KAAK,EAKV,cAAc,EACd,mBAAmB,EACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAkB/D,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;CACtC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CAAC;IAC5C,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IACzC,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,M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AC,CAAC;IAC1D,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1D,QAAQ,CAAC,+BAA+B,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClE,QAAQ,CAAC,cAAc,CAAC,EAAE,IAAI,CAAC,mBAAmB,EAAE,SAAS,GAAG,YAAY,CAAC,CAAC;IAC9E,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,sBAAsB,KAAK,KAAK,CAAC;CAC3D;AA+vBD,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,cAAc,EAAE,CAAC,CAkB3B"}
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ import { createAcceptedPublication, ddcOutputDigest, DdcLifecycle, DdcGeneration
10
10
  import { deriveVertexLayoutProjection, normalizeMeshPayload } from '@forgeax/engine-geometry';
11
11
  import { BUILTIN_MESH_ASSETS } from '@forgeax/engine-pack/builtin';
12
12
  import { NativeCookerRegistry } from '@forgeax/engine-pack/native-cooker';
13
- import { isEngineMaterial } from '@forgeax/engine-shader';
13
+ import { isEngineMaterial, DEFAULT_STANDARD_SURFACE_MODULE } from '@forgeax/engine-shader';
14
14
  import { externalizeSceneAsset } from '@forgeax/engine-scene';
15
15
  import { sha256 } from '@noble/hashes/sha2.js';
16
16
  import { bytesToHex } from '@noble/hashes/utils.js';
@@ -785,6 +785,14 @@ function record(value) {
785
785
  function isAsset(value) {
786
786
  return record(value) && typeof value.kind === "string" && isScriptablePackAssetKind(value.kind);
787
787
  }
788
+ function needsMaterialCook(asset) {
789
+ if (asset.kind !== "material" || !Array.isArray(asset.passes)) return false;
790
+ return asset.passes.some((pass) => {
791
+ const module = pass.program.module;
792
+ const surface = pass.program.moduleSlots?.surface;
793
+ return surface !== void 0 && surface !== DEFAULT_STANDARD_SURFACE_MODULE && (module === "forgeax_material::standard" || module === "forgeax::default-standard-pbr" || module === "forgeax_material::pbr-skin" || module === "forgeax::pbr-skin" || module === "forgeax::default-standard-pbr-skin");
794
+ });
795
+ }
788
796
  function clone(value) {
789
797
  return structuredClone(value);
790
798
  }
@@ -1009,6 +1017,9 @@ async function buildScriptablePack(options) {
1009
1017
  const imported = [];
1010
1018
  const stagedOutputs = [];
1011
1019
  const localGuids = /* @__PURE__ */ new Set();
1020
+ const materialCookerRegistry = new NativeCookerRegistry();
1021
+ for (const cooker of options.cookers ?? []) materialCookerRegistry.register(cooker);
1022
+ const nativeFingerprints = /* @__PURE__ */ new Map();
1012
1023
  for (const sourceKey of Object.keys(built.value).sort()) {
1013
1024
  if (!isValidPackSourceKey(sourceKey))
1014
1025
  return err(sourceKeyFailure(options.sourcePath, sourceKey));
@@ -1084,12 +1095,40 @@ async function buildScriptablePack(options) {
1084
1095
  const invalidProduct2 = productError(options.sourcePath, sourceKey, producer, produced.value);
1085
1096
  if (invalidProduct2 !== void 0) return err(invalidProduct2);
1086
1097
  const product2 = produced.value;
1098
+ let payload = product2.payload;
1099
+ let artifacts2 = product2.artifacts;
1100
+ if (needsMaterialCook(asset) && materialCookerRegistry.get("material") !== void 0) {
1101
+ const cooked = await materialCookerRegistry.runDraft("material", {
1102
+ guid,
1103
+ source: asset,
1104
+ sourceKey,
1105
+ sourcePath: options.sourcePath,
1106
+ refs: product2.refs.map((reference) => reference.guid)
1107
+ });
1108
+ if (!cooked.ok) return err(cooked.error);
1109
+ if (cooked.value.guid.toLowerCase() !== normalizedGuid) {
1110
+ return err({
1111
+ code: "pack-source-output-invalid",
1112
+ expected: "the authored material cooker to preserve the derived AssetGuid",
1113
+ hint: "repair the native material cooker output GUID and rebuild the Pack",
1114
+ detail: {
1115
+ sourcePath: options.sourcePath,
1116
+ sourceKey,
1117
+ expectedGuid: guid,
1118
+ actualGuid: cooked.value.guid
1119
+ }
1120
+ });
1121
+ }
1122
+ payload = cooked.value.payload;
1123
+ artifacts2 = cooked.value.artifacts;
1124
+ nativeFingerprints.set(sourceKey, cooked.value.inputFingerprint);
1125
+ }
1087
1126
  imported.push({
1088
1127
  guid,
1089
1128
  kind: asset.kind,
1090
- payload: product2.payload,
1129
+ payload,
1091
1130
  refs: product2.refs,
1092
- artifacts: product2.artifacts
1131
+ artifacts: artifacts2
1093
1132
  });
1094
1133
  stagedOutputs.push({
1095
1134
  guid: AssetGuid.derive(subjectPackageId, sourceKey),
@@ -1120,7 +1159,7 @@ async function buildScriptablePack(options) {
1120
1159
  digest: read.digest
1121
1160
  })
1122
1161
  );
1123
- const inputFingerprint = await digest({
1162
+ const authoredInputFingerprint = await digest({
1124
1163
  packageId: PackageId.format(subjectPackageId),
1125
1164
  sourcePath: options.sourcePath,
1126
1165
  sourceClosure: options.sourceClosure ?? [],
@@ -1133,6 +1172,12 @@ async function buildScriptablePack(options) {
1133
1172
  authoringContractVersion: options.authoringContractVersion ?? "scriptable-pack/1",
1134
1173
  producerVersions: options.outputs.versions()
1135
1174
  });
1175
+ const inputFingerprint = nativeFingerprints.size === 0 ? authoredInputFingerprint : await digest({
1176
+ sourceRevision: authoredInputFingerprint,
1177
+ nativeCookers: [...nativeFingerprints.entries()].sort(
1178
+ ([left], [right]) => left.localeCompare(right)
1179
+ )
1180
+ });
1136
1181
  const refs = imported.flatMap((asset) => asset.refs);
1137
1182
  const artifacts = Object.fromEntries(
1138
1183
  imported.flatMap(
@@ -1214,6 +1259,7 @@ async function buildScriptablePackWorklist(options) {
1214
1259
  ...subject.inheritedValues === void 0 ? {} : { inheritedValues: subject.inheritedValues },
1215
1260
  ...subject.sourceClosure === void 0 ? {} : { sourceClosure: subject.sourceClosure },
1216
1261
  outputs: options.outputs,
1262
+ ...options.cookers === void 0 ? {} : { cookers: options.cookers },
1217
1263
  assetSource: stagedSource(staged, options.assetSource),
1218
1264
  availableGuids: /* @__PURE__ */ new Set([...availableGuids, ...staged.keys()]),
1219
1265
  deferReferenceValidation: true
@@ -2191,6 +2237,8 @@ async function readCookedAuthoredPack(authoredPack, cookers = [], sourcePath) {
2191
2237
  continue;
2192
2238
  }
2193
2239
  if (isEngineOwnedMaterial(asset)) {
2240
+ hasCookedAsset = true;
2241
+ refsByGuid.set(asset.guid.toLowerCase(), [...asset.refs]);
2194
2242
  assets.push({
2195
2243
  guid: asset.guid,
2196
2244
  kind: asset.kind,
@@ -2679,6 +2727,7 @@ async function produceScriptablePackProducts(options) {
2679
2727
  (source) => projectScriptablePackSceneComponents(source.definition.sceneComponents)
2680
2728
  )
2681
2729
  ),
2730
+ ...options.cookers === void 0 ? {} : { cookers: options.cookers },
2682
2731
  ...assetSource === void 0 ? {} : { assetSource },
2683
2732
  availableGuids,
2684
2733
  ...options.incomingRefs === void 0 ? {} : { incomingRefs: options.incomingRefs },
@@ -2980,6 +3029,7 @@ async function buildPackSources(context) {
2980
3029
  const built = await produceScriptablePackProducts({
2981
3030
  sources: inputs,
2982
3031
  declaredExternalOutputs: externalOutputs,
3032
+ cookers: context.cookers,
2983
3033
  availableGuids
2984
3034
  });
2985
3035
  if (!built.ok) dynamicFailure(context, built.error);