@forgeax/engine-gltf 0.1.28 → 0.1.29

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.
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { err, ok, createMaterialError, standardMaterialParameters, reconcileMeshMaterialSlotTopology, MESH_MATERIAL_SLOT_SOURCE_OVERRIDE_PAYLOAD_SCHEMA, STANDARD_MATERIAL_PARAM_SCHEMA, STANDARD_PHYSICAL_PARAMETER_NAMES, STANDARD_TRANSMISSION_PARAMETER_NAMES, ImportError, STANDARD_LAYER_PARAMETER_GROUPS, IMPORT_ERROR_HINTS, toShared, resolveMeshMaterialSlotDefaultGuid } from '@forgeax/engine-types';
1
+ import { err, ok, createMaterialError, standardMaterialParameters, reconcileMeshMaterialSlotTopology, MESH_MATERIAL_SLOT_SOURCE_OVERRIDE_PAYLOAD_SCHEMA, STANDARD_MATERIAL_PARAM_SCHEMA, STANDARD_PHYSICAL_PARAMETER_NAMES, STANDARD_TRANSMISSION_PARAMETER_NAMES, ImportError, STANDARD_LAYER_PARAMETER_GROUPS, IMPORT_ERROR_HINTS, parseConservativeAnimatedBounds, readConservativeAnimatedBounds, toShared, resolveMeshMaterialSlotDefaultGuid } from '@forgeax/engine-types';
2
2
  export { err, ok } from '@forgeax/engine-types';
3
3
  import { computeTangentVec4, packInterleavedVertexAttributes } from '@forgeax/engine-geometry';
4
4
  import { box3, mat4, vec3, quat } from '@forgeax/engine-math';
@@ -716,7 +716,7 @@ function composeMat4(out, tx, ty, tz, qx, qy, qz, qw, sx, sy, sz) {
716
716
  function gltfDocToSceneAsset(doc, ctx) {
717
717
  const sceneIr = doc.scenes[doc.defaultSceneIndex];
718
718
  const resultNodes = [];
719
- if (sceneIr === void 0) return { kind: "scene", entities: [] };
719
+ if (sceneIr === void 0) return { kind: "scene", entities: {} };
720
720
  const importedLights = doc.lights ?? doc.extensions?.KHR_lights_punctual?.lights ?? [];
721
721
  const animationTargetIds = /* @__PURE__ */ new Map();
722
722
  for (const clip of doc.animationClips) {
@@ -809,7 +809,10 @@ function gltfDocToSceneAsset(doc, ctx) {
809
809
  components.MeshRenderer = { materials: [] };
810
810
  }
811
811
  if (ir.instancing !== void 0) {
812
- components.Instances = { transforms: ir.instancing.transforms };
812
+ const collectionId = ctx.instanceCollectionIdsByNodeIndex?.get(gltfNodeIdx);
813
+ if (collectionId !== void 0) {
814
+ components.Instances = { collectionId };
815
+ }
813
816
  }
814
817
  if (isCamera) {
815
818
  components.Camera = {
@@ -837,10 +840,20 @@ function gltfDocToSceneAsset(doc, ctx) {
837
840
  for (let i = 0; i < 16; i++) parentWorld[i] = savedParent[i] ?? 0;
838
841
  };
839
842
  for (const rootIdx of sceneIr.nodes) visit(rootIdx, null);
840
- const frozen = resultNodes.map((n) => ({
841
- localId: n.localId,
842
- components: n.components
843
- }));
843
+ const keyByLocalId = /* @__PURE__ */ new Map();
844
+ for (const node of resultNodes) keyByLocalId.set(node.localIdx, `node-${node.localIdx}`);
845
+ const entities = {};
846
+ for (const node of resultNodes) {
847
+ const components = { ...node.components };
848
+ const childOf = components.ChildOf;
849
+ if (childOf !== void 0 && typeof childOf.parent === "number") {
850
+ const parentKey = keyByLocalId.get(childOf.parent);
851
+ if (parentKey === void 0)
852
+ throw new Error(`gltfDocToSceneAsset: missing parent node ${childOf.parent}`);
853
+ components.ChildOf = { ...childOf, parent: parentKey };
854
+ }
855
+ entities[`node-${node.localIdx}`] = { components };
856
+ }
844
857
  const lightFacts = importedLights.map((light) => ({
845
858
  kind: light.type,
846
859
  intensity: light.intensity,
@@ -849,7 +862,7 @@ function gltfDocToSceneAsset(doc, ctx) {
849
862
  }));
850
863
  return {
851
864
  kind: "scene",
852
- entities: frozen,
865
+ entities,
853
866
  ...lightFacts.length === 0 ? {} : { lights: lightFacts }
854
867
  };
855
868
  }
@@ -2303,8 +2316,6 @@ function parseAnimation(animationsJson, nodesJson, accessors, bufferViews, buffe
2303
2316
  }
2304
2317
  return ok(clips);
2305
2318
  }
2306
-
2307
- // src/parse-skin.ts
2308
2319
  var MAX_JOINTS = 256;
2309
2320
  var SKIN_ACCESSOR_TYPES = ["MAT4"];
2310
2321
  function identityMat4() {
@@ -2385,10 +2396,14 @@ function parseSkin(skinsJson, nodesJson, accessors, bufferViews, buffers) {
2385
2396
  if (!pathResult.ok) return err(pathResult.error);
2386
2397
  jointPaths.push(pathResult.value.join("/"));
2387
2398
  }
2399
+ const bounds = parseConservativeAnimatedBounds(
2400
+ skin.extras?.forgeax?.conservativeAnimatedBounds
2401
+ );
2388
2402
  records.push({
2389
2403
  jointCount: joints.length,
2390
2404
  inverseBindMatrices: ibm,
2391
- jointPaths
2405
+ jointPaths,
2406
+ ...bounds === void 0 ? {} : { bounds }
2392
2407
  });
2393
2408
  }
2394
2409
  return ok(records);
@@ -3599,6 +3614,16 @@ function isGlbBytes(source) {
3599
3614
  function publishesCatalogProduct(input) {
3600
3615
  return input.importSettings.geometry !== "procedural";
3601
3616
  }
3617
+ function applyImportSettingsBounds(doc, importSettings) {
3618
+ let changed = false;
3619
+ const skeletons = doc.skeletons.map((record, sourceIndex) => {
3620
+ const bounds = readConservativeAnimatedBounds(importSettings, sourceIndex);
3621
+ if (bounds === void 0 || record.bounds !== void 0) return record;
3622
+ changed = true;
3623
+ return { ...record, bounds };
3624
+ });
3625
+ return changed ? { ...doc, skeletons } : doc;
3626
+ }
3602
3627
  function previousMaterialSlotTopology(ctx, meshSourceKey) {
3603
3628
  if (meshSourceKey === void 0) return void 0;
3604
3629
  const value = ctx.sourceOverrides?.[meshSourceKey]?.materialSlots;
@@ -3918,7 +3943,7 @@ async function importGltf(ctx, meshopt) {
3918
3943
  }
3919
3944
  const parsed = await parseDoc(ctx.source, read.value, ctx);
3920
3945
  if (!parsed.ok) return parsed;
3921
- const doc = parsed.value;
3946
+ const doc = applyImportSettingsBounds(parsed.value, ctx.importSettings);
3922
3947
  const maps = buildHandleMaps(ctx.subAssets, doc);
3923
3948
  const imageColorSpaces = deriveTextureColorSpace({
3924
3949
  imageCount: (doc.images ?? []).length,
@@ -4217,7 +4242,7 @@ async function importGltf(ctx, meshopt) {
4217
4242
  fieldName: prov.fieldName,
4218
4243
  ...prov.arrayIndex !== void 0 ? { arrayIndex: prov.arrayIndex } : {}
4219
4244
  },
4220
- sceneEntityId: prov.sceneEntityId
4245
+ sceneEntityKey: prov.sceneEntityKey
4221
4246
  };
4222
4247
  }
4223
4248
  return { guid };
@@ -4228,19 +4253,19 @@ async function importGltf(ctx, meshopt) {
4228
4253
  });
4229
4254
  const handleValueProvenance = /* @__PURE__ */ new Map();
4230
4255
  const skeletonGuidProvenance = /* @__PURE__ */ new Map();
4231
- for (const entity of scene.entities) {
4256
+ for (const [sceneEntityKey, entity] of Object.entries(scene.entities)) {
4232
4257
  const comps = entity.components;
4233
4258
  const mf = comps.MeshFilter;
4234
4259
  if (mf !== void 0 && typeof mf.assetHandle === "number") {
4235
4260
  handleValueProvenance.set(mf.assetHandle, {
4236
- sceneEntityId: entity.localId,
4261
+ sceneEntityKey,
4237
4262
  componentName: "MeshFilter",
4238
4263
  fieldName: "assetHandle"
4239
4264
  });
4240
4265
  }
4241
4266
  const skin = comps.Skin;
4242
4267
  if (skin !== void 0 && typeof skin.skeleton === "string") {
4243
- skeletonGuidProvenance.set(skin.skeleton, { sceneEntityId: entity.localId });
4268
+ skeletonGuidProvenance.set(skin.skeleton, { sceneEntityKey });
4244
4269
  }
4245
4270
  }
4246
4271
  const meshGuidList = [...maps.meshGuidByIndex.values()];
@@ -4258,7 +4283,7 @@ async function importGltf(ctx, meshopt) {
4258
4283
  skProv !== void 0 ? {
4259
4284
  guid,
4260
4285
  sourceField: { componentName: "Skin", fieldName: "skeleton" },
4261
- sceneEntityId: skProv.sceneEntityId
4286
+ sceneEntityKey: skProv.sceneEntityKey
4262
4287
  } : { guid }
4263
4288
  );
4264
4289
  cursor++;
@@ -4288,7 +4313,8 @@ async function importGltf(ctx, meshopt) {
4288
4313
  const payload = {
4289
4314
  kind: "skeleton",
4290
4315
  inverseBindMatrices: rec.inverseBindMatrices,
4291
- jointCount: rec.jointCount
4316
+ jointCount: rec.jointCount,
4317
+ ...rec.bounds === void 0 ? {} : { bounds: rec.bounds }
4292
4318
  };
4293
4319
  out.push({ guid: sub.guid, kind: "skeleton", payload, refs: [], artifacts: {} });
4294
4320
  } else if (sub.kind === "skin") {