@relu-interactives/spatial-ecs 0.2.23 → 0.2.24

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.
@@ -974,82 +974,108 @@ function createColliderDesc(RAPIER, values, triMeshData) {
974
974
  return desc;
975
975
  }
976
976
  __name(createColliderDesc, "createColliderDesc");
977
- function findFirstMeshWithGeometry(object) {
978
- if (object instanceof THREE7.Mesh && object.geometry) {
979
- return object;
977
+ function collectTriMeshParts(object) {
978
+ if (!object) {
979
+ return null;
980
980
  }
981
- let found = null;
981
+ object.updateWorldMatrix(true, true);
982
+ const worldScale = new THREE7.Vector3();
983
+ object.getWorldScale(worldScale);
984
+ const scale = {
985
+ x: Math.abs(worldScale.x) || 1,
986
+ y: Math.abs(worldScale.y) || 1,
987
+ z: Math.abs(worldScale.z) || 1
988
+ };
989
+ const worldToObject = new THREE7.Matrix4().copy(object.matrixWorld).invert();
990
+ const parts = [];
982
991
  object.traverse((child) => {
983
- if (found) {
992
+ if (!(child instanceof THREE7.Mesh) || !child.geometry) {
984
993
  return;
985
994
  }
986
- if (child instanceof THREE7.Mesh && child.geometry) {
987
- found = child;
995
+ const geometry = child.geometry;
996
+ const positionAttribute = geometry.getAttribute("position");
997
+ if (!positionAttribute || positionAttribute.itemSize < 3) {
998
+ return;
988
999
  }
1000
+ const positionCount = positionAttribute.count;
1001
+ if (positionCount < 3) {
1002
+ return;
1003
+ }
1004
+ const indexAttribute = geometry.getIndex();
1005
+ const indexCount = indexAttribute ? indexAttribute.count : Math.floor(positionCount / 3) * 3;
1006
+ if (indexCount < 3) {
1007
+ return;
1008
+ }
1009
+ const relativeMatrix = new THREE7.Matrix4().multiplyMatrices(
1010
+ worldToObject,
1011
+ child.matrixWorld
1012
+ );
1013
+ const matrixSignature = relativeMatrix.elements.map((value) => value.toFixed(5)).join(",");
1014
+ parts.push({
1015
+ positionAttribute,
1016
+ indexAttribute,
1017
+ positionCount,
1018
+ indexCount,
1019
+ relativeMatrix,
1020
+ signature: `${child.uuid}:${geometry.uuid}:${positionCount}:${indexCount}:${matrixSignature}`
1021
+ });
989
1022
  });
990
- return found;
991
- }
992
- __name(findFirstMeshWithGeometry, "findFirstMeshWithGeometry");
993
- function createTriMeshData(object) {
994
- if (!object) {
1023
+ if (parts.length === 0) {
995
1024
  return null;
996
1025
  }
997
- const mesh = findFirstMeshWithGeometry(object);
998
- if (!mesh) {
1026
+ const scaleSignature = `${scale.x.toFixed(5)},${scale.y.toFixed(5)},${scale.z.toFixed(5)}`;
1027
+ return {
1028
+ parts,
1029
+ scale,
1030
+ signature: `${scaleSignature}|${parts.map((p) => p.signature).join("|")}`
1031
+ };
1032
+ }
1033
+ __name(collectTriMeshParts, "collectTriMeshParts");
1034
+ function createTriMeshData(collected) {
1035
+ if (!collected) {
999
1036
  return null;
1000
1037
  }
1001
- const geometry = mesh.geometry;
1002
- const positionAttribute = geometry.getAttribute("position");
1003
- if (!positionAttribute || positionAttribute.itemSize < 3) {
1004
- return null;
1038
+ const { parts, scale } = collected;
1039
+ let vertexTotal = 0;
1040
+ let indexTotal = 0;
1041
+ for (const part of parts) {
1042
+ vertexTotal += part.positionCount;
1043
+ indexTotal += part.indexCount;
1005
1044
  }
1006
- const positionCount = positionAttribute.count;
1007
- if (positionCount < 3) {
1045
+ if (vertexTotal < 3 || indexTotal < 3) {
1008
1046
  return null;
1009
1047
  }
1010
- object.updateWorldMatrix(true, true);
1011
- mesh.updateWorldMatrix(true, true);
1012
- const worldToObject = new THREE7.Matrix4().copy(object.matrixWorld).invert();
1013
- const relativeMatrix = new THREE7.Matrix4().multiplyMatrices(
1014
- worldToObject,
1015
- mesh.matrixWorld
1016
- );
1017
- const vertices = new Float32Array(positionCount * 3);
1048
+ const vertices = new Float32Array(vertexTotal * 3);
1049
+ const indices = new Uint32Array(indexTotal);
1018
1050
  const point = new THREE7.Vector3();
1019
- for (let index = 0; index < positionCount; index += 1) {
1020
- point.set(
1021
- positionAttribute.getX(index),
1022
- positionAttribute.getY(index),
1023
- positionAttribute.getZ(index)
1024
- ).applyMatrix4(relativeMatrix);
1025
- const outputIndex = index * 3;
1026
- vertices[outputIndex] = point.x;
1027
- vertices[outputIndex + 1] = point.y;
1028
- vertices[outputIndex + 2] = point.z;
1029
- }
1030
- const indexAttribute = geometry.getIndex();
1031
- let indices;
1032
- if (indexAttribute) {
1033
- indices = new Uint32Array(indexAttribute.count);
1034
- for (let index = 0; index < indexAttribute.count; index += 1) {
1035
- indices[index] = indexAttribute.getX(index);
1036
- }
1037
- } else {
1038
- const triangleIndexCount = Math.floor(positionCount / 3) * 3;
1039
- if (triangleIndexCount < 3) {
1040
- return null;
1041
- }
1042
- indices = new Uint32Array(triangleIndexCount);
1043
- for (let index = 0; index < triangleIndexCount; index += 1) {
1044
- indices[index] = index;
1051
+ let vertexOffset = 0;
1052
+ let indexOffset = 0;
1053
+ for (const part of parts) {
1054
+ const { positionAttribute, indexAttribute, relativeMatrix } = part;
1055
+ for (let index = 0; index < part.positionCount; index += 1) {
1056
+ point.set(
1057
+ positionAttribute.getX(index),
1058
+ positionAttribute.getY(index),
1059
+ positionAttribute.getZ(index)
1060
+ ).applyMatrix4(relativeMatrix);
1061
+ const outputIndex = (vertexOffset + index) * 3;
1062
+ vertices[outputIndex] = point.x * scale.x;
1063
+ vertices[outputIndex + 1] = point.y * scale.y;
1064
+ vertices[outputIndex + 2] = point.z * scale.z;
1065
+ }
1066
+ if (indexAttribute) {
1067
+ for (let index = 0; index < part.indexCount; index += 1) {
1068
+ indices[indexOffset + index] = vertexOffset + indexAttribute.getX(index);
1069
+ }
1070
+ } else {
1071
+ for (let index = 0; index < part.indexCount; index += 1) {
1072
+ indices[indexOffset + index] = vertexOffset + index;
1073
+ }
1045
1074
  }
1075
+ vertexOffset += part.positionCount;
1076
+ indexOffset += part.indexCount;
1046
1077
  }
1047
- const matrixSignature = relativeMatrix.elements.map((value) => value.toFixed(5)).join(",");
1048
- return {
1049
- vertices,
1050
- indices,
1051
- signature: `${mesh.uuid}:${geometry.uuid}:${positionCount}:${indices.length}:${matrixSignature}`
1052
- };
1078
+ return { vertices, indices, signature: collected.signature };
1053
1079
  }
1054
1080
  __name(createTriMeshData, "createTriMeshData");
1055
1081
  function syncBodyFromTransform(body, transform) {
@@ -1226,7 +1252,7 @@ var _PhysicsSyncSystem = class _PhysicsSyncSystem {
1226
1252
  syncBodyFromTransform(body, transform);
1227
1253
  }
1228
1254
  const effectiveCollider = computeColliderState(physics.values.collider, object);
1229
- const triMeshData = effectiveCollider.shape === "trimesh" ? createTriMeshData(object) : null;
1255
+ const triMeshParts = effectiveCollider.shape === "trimesh" ? collectTriMeshParts(object) : null;
1230
1256
  if (!effectiveCollider || !effectiveCollider.enabled) {
1231
1257
  const colliderHandle = this.colliderHandles.get(entityId);
1232
1258
  if (typeof colliderHandle === "number") {
@@ -1240,7 +1266,7 @@ var _PhysicsSyncSystem = class _PhysicsSyncSystem {
1240
1266
  physics.collider = null;
1241
1267
  continue;
1242
1268
  }
1243
- const colliderSignature = `${JSON.stringify(effectiveCollider)}:${triMeshData?.signature ?? ""}`;
1269
+ const colliderSignature = `${JSON.stringify(effectiveCollider)}:${triMeshParts?.signature ?? ""}`;
1244
1270
  const previousColliderSignature = this.colliderSignatures.get(entityId);
1245
1271
  if (!this.colliderHandles.has(entityId) || previousColliderSignature !== colliderSignature) {
1246
1272
  const previousColliderHandle = this.colliderHandles.get(entityId);
@@ -1253,7 +1279,7 @@ var _PhysicsSyncSystem = class _PhysicsSyncSystem {
1253
1279
  const colliderDesc = createColliderDesc(
1254
1280
  this.rapier,
1255
1281
  effectiveCollider,
1256
- triMeshData
1282
+ createTriMeshData(triMeshParts)
1257
1283
  );
1258
1284
  const createdCollider = physicsWorld.createCollider(colliderDesc, body);
1259
1285
  this.colliderHandles.set(entityId, createdCollider.handle);
@@ -5809,5 +5835,5 @@ __name(_VideoSystem, "VideoSystem");
5809
5835
  var VideoSystem = _VideoSystem;
5810
5836
 
5811
5837
  export { ADDED_NODE_MARKER_COMPONENT, AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, HYDRATABLE_ENTITY_KINDS, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, NODE_KEY_SEPARATOR, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, ObjectVisibilitySystem, PREFAB_FILE_VERSION, PREFAB_FILE_VERSION_NESTED, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, SCRIPT_OBJECT_ROOT_FLAG, ScriptBehaviourSystem, ScriptObject, ScriptObjectSystem, TransformSyncSystem, VideoSystem, buildComponentValueMaps, buildNodeKeyMapsFromSnapshot, buildNodeMapsFromSnapshot, canonicalizeComponentValue, clearPrefabCache, collectDiffPaths, collectEntitySubtree, collectSnapshotSubtreeIds, computeInstanceOverrides, decanonicalizeComponentValue, despawnPrefab, encodeOverride, findSnapshotRootEntityIds, findTopLevelNestedRegions, groupOverridePaths, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, indexSnapshotByEntity, instantiateSubtree, loadPrefab, mergeComponentValue, parseOverride, parsePrefabAsset, prefabFileVersionFor, restoreComponentState, restorePostCreateComponents, setPrefabAssetUrlResolver, spawnPrefab };
5812
- //# sourceMappingURL=chunk-7BEZBIVB.js.map
5813
- //# sourceMappingURL=chunk-7BEZBIVB.js.map
5838
+ //# sourceMappingURL=chunk-CCE5K2TU.js.map
5839
+ //# sourceMappingURL=chunk-CCE5K2TU.js.map