@relu-interactives/spatial-ecs 0.2.22 → 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.
- package/dist/{chunk-GZ2NKSMV.js → chunk-CCE5K2TU.js} +101 -68
- package/dist/chunk-CCE5K2TU.js.map +1 -0
- package/dist/docs/guide/authoring-a-script-object.md +24 -11
- package/dist/docs/guide/systems/physics-sync-system.md +1 -1
- package/dist/index.cjs +99 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/systems/index.cjs +99 -66
- package/dist/systems/index.cjs.map +1 -1
- package/dist/systems/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-GZ2NKSMV.js.map +0 -1
|
@@ -974,82 +974,108 @@ function createColliderDesc(RAPIER, values, triMeshData) {
|
|
|
974
974
|
return desc;
|
|
975
975
|
}
|
|
976
976
|
__name(createColliderDesc, "createColliderDesc");
|
|
977
|
-
function
|
|
978
|
-
if (object
|
|
979
|
-
return
|
|
977
|
+
function collectTriMeshParts(object) {
|
|
978
|
+
if (!object) {
|
|
979
|
+
return null;
|
|
980
980
|
}
|
|
981
|
-
|
|
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 (
|
|
992
|
+
if (!(child instanceof THREE7.Mesh) || !child.geometry) {
|
|
984
993
|
return;
|
|
985
994
|
}
|
|
986
|
-
|
|
987
|
-
|
|
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
|
-
|
|
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
|
|
998
|
-
|
|
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
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
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
|
-
|
|
1007
|
-
if (positionCount < 3) {
|
|
1045
|
+
if (vertexTotal < 3 || indexTotal < 3) {
|
|
1008
1046
|
return null;
|
|
1009
1047
|
}
|
|
1010
|
-
|
|
1011
|
-
|
|
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
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
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
|
-
|
|
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
|
|
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)}:${
|
|
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
|
-
|
|
1282
|
+
createTriMeshData(triMeshParts)
|
|
1257
1283
|
);
|
|
1258
1284
|
const createdCollider = physicsWorld.createCollider(colliderDesc, body);
|
|
1259
1285
|
this.colliderHandles.set(entityId, createdCollider.handle);
|
|
@@ -5410,9 +5436,9 @@ var _ScriptObjectSystem = class _ScriptObjectSystem {
|
|
|
5410
5436
|
} catch {
|
|
5411
5437
|
instance = new ctor(world, entityId, currentData);
|
|
5412
5438
|
}
|
|
5413
|
-
const
|
|
5414
|
-
const
|
|
5415
|
-
instance.data = resolveInputData(world,
|
|
5439
|
+
const literalDefaults = normalizeScriptData(instance.data);
|
|
5440
|
+
const seed = Object.keys(literalDefaults).length > 0 ? mergeDataByCurrentDefaults(literalDefaults, currentData) : { ...currentData };
|
|
5441
|
+
instance.data = resolveInputData(world, seed);
|
|
5416
5442
|
const parent = world.getComponent(entityId, Object3DRef)?.object;
|
|
5417
5443
|
if (!parent) {
|
|
5418
5444
|
throw new Error("Script object entity has no Object3D to attach to.");
|
|
@@ -5442,6 +5468,13 @@ var _ScriptObjectSystem = class _ScriptObjectSystem {
|
|
|
5442
5468
|
built.userData[SCRIPT_OBJECT_ROOT_FLAG] = true;
|
|
5443
5469
|
parent.add(built);
|
|
5444
5470
|
instance.root = built;
|
|
5471
|
+
const postBuildData = normalizeScriptData(instance.data);
|
|
5472
|
+
const schemaDefaults = { ...literalDefaults };
|
|
5473
|
+
for (const [key2, value] of Object.entries(postBuildData)) {
|
|
5474
|
+
if (!(key2 in schemaDefaults)) schemaDefaults[key2] = value;
|
|
5475
|
+
}
|
|
5476
|
+
const merged = mergeDataByCurrentDefaults(schemaDefaults, currentData);
|
|
5477
|
+
instance.data = resolveInputData(world, merged);
|
|
5445
5478
|
const stored = serializeDataForStorage(merged, merged);
|
|
5446
5479
|
component.data = stored;
|
|
5447
5480
|
component.runtimeState = "ready";
|
|
@@ -5802,5 +5835,5 @@ __name(_VideoSystem, "VideoSystem");
|
|
|
5802
5835
|
var VideoSystem = _VideoSystem;
|
|
5803
5836
|
|
|
5804
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 };
|
|
5805
|
-
//# sourceMappingURL=chunk-
|
|
5806
|
-
//# sourceMappingURL=chunk-
|
|
5838
|
+
//# sourceMappingURL=chunk-CCE5K2TU.js.map
|
|
5839
|
+
//# sourceMappingURL=chunk-CCE5K2TU.js.map
|