@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.
- package/dist/{chunk-7BEZBIVB.js → chunk-CCE5K2TU.js} +91 -65
- package/dist/chunk-CCE5K2TU.js.map +1 -0
- package/dist/docs/guide/systems/physics-sync-system.md +1 -1
- package/dist/index.cjs +89 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/systems/index.cjs +89 -63
- package/dist/systems/index.cjs.map +1 -1
- package/dist/systems/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-7BEZBIVB.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MeshGeometrySystem, InstancedMeshSystem, EnvironmentSyncSystem, PostprocessingSyncSystem, LightSyncSystem, MaterialSyncSystem, PhysicsSyncSystem, AnimationSystem, AudioSystem, VideoSystem, CameraSyncSystem, TransformSyncSystem, ObjectVisibilitySystem, RenderSystem, spawnPrefab, despawnPrefab, buildNodeKeyMapsFromSnapshot, indexSnapshotByEntity, findTopLevelNestedRegions, collectSnapshotSubtreeIds, groupOverridePaths, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, canonicalizeComponentValue, mergeComponentValue, decanonicalizeComponentValue, computeInstanceOverrides, collectEntitySubtree, ADDED_NODE_MARKER_COMPONENT } from './chunk-
|
|
2
|
-
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 } from './chunk-
|
|
1
|
+
import { MeshGeometrySystem, InstancedMeshSystem, EnvironmentSyncSystem, PostprocessingSyncSystem, LightSyncSystem, MaterialSyncSystem, PhysicsSyncSystem, AnimationSystem, AudioSystem, VideoSystem, CameraSyncSystem, TransformSyncSystem, ObjectVisibilitySystem, RenderSystem, spawnPrefab, despawnPrefab, buildNodeKeyMapsFromSnapshot, indexSnapshotByEntity, findTopLevelNestedRegions, collectSnapshotSubtreeIds, groupOverridePaths, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, canonicalizeComponentValue, mergeComponentValue, decanonicalizeComponentValue, computeInstanceOverrides, collectEntitySubtree, ADDED_NODE_MARKER_COMPONENT } from './chunk-CCE5K2TU.js';
|
|
2
|
+
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 } from './chunk-CCE5K2TU.js';
|
|
3
3
|
import { registerDefaultFactories } from './chunk-52CHDPRQ.js';
|
|
4
4
|
export { createAnimationComponent, createAudioComponent, createCameraComponent, createEntityTypeComponent, createEnvironmentComponent, createImageComponent, createImageTargetAnchorComponent, createImageTargetComponent, createInstanceSlotComponent, createInstancedMeshComponent, createLightComponent, createMaterialComponent, createMeshComponent, createMeshGeometryComponent, createModelComponent, createNameComponent, createObject3DRefComponent, createParentIdComponent, createPhysicsComponent, createPostprocessingComponent, createScriptComponent, createScriptObjectComponent, createSelectableComponent, createSelectionTransformStateComponent, createSpriteComponent, createTransformComponent, createVideoComponent, registerDefaultComponentFactories, registerDefaultFactories } from './chunk-52CHDPRQ.js';
|
|
5
5
|
import { ObjectManagementSystem } from './chunk-WKGCC7YL.js';
|
package/dist/systems/index.cjs
CHANGED
|
@@ -3013,82 +3013,108 @@ function createColliderDesc(RAPIER, values, triMeshData) {
|
|
|
3013
3013
|
return desc;
|
|
3014
3014
|
}
|
|
3015
3015
|
__name(createColliderDesc, "createColliderDesc");
|
|
3016
|
-
function
|
|
3017
|
-
if (object
|
|
3018
|
-
return
|
|
3016
|
+
function collectTriMeshParts(object) {
|
|
3017
|
+
if (!object) {
|
|
3018
|
+
return null;
|
|
3019
3019
|
}
|
|
3020
|
-
|
|
3020
|
+
object.updateWorldMatrix(true, true);
|
|
3021
|
+
const worldScale = new THREE14__namespace.Vector3();
|
|
3022
|
+
object.getWorldScale(worldScale);
|
|
3023
|
+
const scale = {
|
|
3024
|
+
x: Math.abs(worldScale.x) || 1,
|
|
3025
|
+
y: Math.abs(worldScale.y) || 1,
|
|
3026
|
+
z: Math.abs(worldScale.z) || 1
|
|
3027
|
+
};
|
|
3028
|
+
const worldToObject = new THREE14__namespace.Matrix4().copy(object.matrixWorld).invert();
|
|
3029
|
+
const parts = [];
|
|
3021
3030
|
object.traverse((child) => {
|
|
3022
|
-
if (
|
|
3031
|
+
if (!(child instanceof THREE14__namespace.Mesh) || !child.geometry) {
|
|
3023
3032
|
return;
|
|
3024
3033
|
}
|
|
3025
|
-
|
|
3026
|
-
|
|
3034
|
+
const geometry = child.geometry;
|
|
3035
|
+
const positionAttribute = geometry.getAttribute("position");
|
|
3036
|
+
if (!positionAttribute || positionAttribute.itemSize < 3) {
|
|
3037
|
+
return;
|
|
3027
3038
|
}
|
|
3039
|
+
const positionCount = positionAttribute.count;
|
|
3040
|
+
if (positionCount < 3) {
|
|
3041
|
+
return;
|
|
3042
|
+
}
|
|
3043
|
+
const indexAttribute = geometry.getIndex();
|
|
3044
|
+
const indexCount = indexAttribute ? indexAttribute.count : Math.floor(positionCount / 3) * 3;
|
|
3045
|
+
if (indexCount < 3) {
|
|
3046
|
+
return;
|
|
3047
|
+
}
|
|
3048
|
+
const relativeMatrix = new THREE14__namespace.Matrix4().multiplyMatrices(
|
|
3049
|
+
worldToObject,
|
|
3050
|
+
child.matrixWorld
|
|
3051
|
+
);
|
|
3052
|
+
const matrixSignature = relativeMatrix.elements.map((value) => value.toFixed(5)).join(",");
|
|
3053
|
+
parts.push({
|
|
3054
|
+
positionAttribute,
|
|
3055
|
+
indexAttribute,
|
|
3056
|
+
positionCount,
|
|
3057
|
+
indexCount,
|
|
3058
|
+
relativeMatrix,
|
|
3059
|
+
signature: `${child.uuid}:${geometry.uuid}:${positionCount}:${indexCount}:${matrixSignature}`
|
|
3060
|
+
});
|
|
3028
3061
|
});
|
|
3029
|
-
|
|
3030
|
-
}
|
|
3031
|
-
__name(findFirstMeshWithGeometry, "findFirstMeshWithGeometry");
|
|
3032
|
-
function createTriMeshData(object) {
|
|
3033
|
-
if (!object) {
|
|
3062
|
+
if (parts.length === 0) {
|
|
3034
3063
|
return null;
|
|
3035
3064
|
}
|
|
3036
|
-
const
|
|
3037
|
-
|
|
3065
|
+
const scaleSignature = `${scale.x.toFixed(5)},${scale.y.toFixed(5)},${scale.z.toFixed(5)}`;
|
|
3066
|
+
return {
|
|
3067
|
+
parts,
|
|
3068
|
+
scale,
|
|
3069
|
+
signature: `${scaleSignature}|${parts.map((p) => p.signature).join("|")}`
|
|
3070
|
+
};
|
|
3071
|
+
}
|
|
3072
|
+
__name(collectTriMeshParts, "collectTriMeshParts");
|
|
3073
|
+
function createTriMeshData(collected) {
|
|
3074
|
+
if (!collected) {
|
|
3038
3075
|
return null;
|
|
3039
3076
|
}
|
|
3040
|
-
const
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3077
|
+
const { parts, scale } = collected;
|
|
3078
|
+
let vertexTotal = 0;
|
|
3079
|
+
let indexTotal = 0;
|
|
3080
|
+
for (const part of parts) {
|
|
3081
|
+
vertexTotal += part.positionCount;
|
|
3082
|
+
indexTotal += part.indexCount;
|
|
3044
3083
|
}
|
|
3045
|
-
|
|
3046
|
-
if (positionCount < 3) {
|
|
3084
|
+
if (vertexTotal < 3 || indexTotal < 3) {
|
|
3047
3085
|
return null;
|
|
3048
3086
|
}
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
const worldToObject = new THREE14__namespace.Matrix4().copy(object.matrixWorld).invert();
|
|
3052
|
-
const relativeMatrix = new THREE14__namespace.Matrix4().multiplyMatrices(
|
|
3053
|
-
worldToObject,
|
|
3054
|
-
mesh.matrixWorld
|
|
3055
|
-
);
|
|
3056
|
-
const vertices = new Float32Array(positionCount * 3);
|
|
3087
|
+
const vertices = new Float32Array(vertexTotal * 3);
|
|
3088
|
+
const indices = new Uint32Array(indexTotal);
|
|
3057
3089
|
const point = new THREE14__namespace.Vector3();
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
indices = new Uint32Array(triangleIndexCount);
|
|
3082
|
-
for (let index = 0; index < triangleIndexCount; index += 1) {
|
|
3083
|
-
indices[index] = index;
|
|
3090
|
+
let vertexOffset = 0;
|
|
3091
|
+
let indexOffset = 0;
|
|
3092
|
+
for (const part of parts) {
|
|
3093
|
+
const { positionAttribute, indexAttribute, relativeMatrix } = part;
|
|
3094
|
+
for (let index = 0; index < part.positionCount; index += 1) {
|
|
3095
|
+
point.set(
|
|
3096
|
+
positionAttribute.getX(index),
|
|
3097
|
+
positionAttribute.getY(index),
|
|
3098
|
+
positionAttribute.getZ(index)
|
|
3099
|
+
).applyMatrix4(relativeMatrix);
|
|
3100
|
+
const outputIndex = (vertexOffset + index) * 3;
|
|
3101
|
+
vertices[outputIndex] = point.x * scale.x;
|
|
3102
|
+
vertices[outputIndex + 1] = point.y * scale.y;
|
|
3103
|
+
vertices[outputIndex + 2] = point.z * scale.z;
|
|
3104
|
+
}
|
|
3105
|
+
if (indexAttribute) {
|
|
3106
|
+
for (let index = 0; index < part.indexCount; index += 1) {
|
|
3107
|
+
indices[indexOffset + index] = vertexOffset + indexAttribute.getX(index);
|
|
3108
|
+
}
|
|
3109
|
+
} else {
|
|
3110
|
+
for (let index = 0; index < part.indexCount; index += 1) {
|
|
3111
|
+
indices[indexOffset + index] = vertexOffset + index;
|
|
3112
|
+
}
|
|
3084
3113
|
}
|
|
3114
|
+
vertexOffset += part.positionCount;
|
|
3115
|
+
indexOffset += part.indexCount;
|
|
3085
3116
|
}
|
|
3086
|
-
|
|
3087
|
-
return {
|
|
3088
|
-
vertices,
|
|
3089
|
-
indices,
|
|
3090
|
-
signature: `${mesh.uuid}:${geometry.uuid}:${positionCount}:${indices.length}:${matrixSignature}`
|
|
3091
|
-
};
|
|
3117
|
+
return { vertices, indices, signature: collected.signature };
|
|
3092
3118
|
}
|
|
3093
3119
|
__name(createTriMeshData, "createTriMeshData");
|
|
3094
3120
|
function syncBodyFromTransform(body, transform) {
|
|
@@ -3265,7 +3291,7 @@ var _PhysicsSyncSystem = class _PhysicsSyncSystem {
|
|
|
3265
3291
|
syncBodyFromTransform(body, transform);
|
|
3266
3292
|
}
|
|
3267
3293
|
const effectiveCollider = computeColliderState(physics.values.collider, object);
|
|
3268
|
-
const
|
|
3294
|
+
const triMeshParts = effectiveCollider.shape === "trimesh" ? collectTriMeshParts(object) : null;
|
|
3269
3295
|
if (!effectiveCollider || !effectiveCollider.enabled) {
|
|
3270
3296
|
const colliderHandle = this.colliderHandles.get(entityId);
|
|
3271
3297
|
if (typeof colliderHandle === "number") {
|
|
@@ -3279,7 +3305,7 @@ var _PhysicsSyncSystem = class _PhysicsSyncSystem {
|
|
|
3279
3305
|
physics.collider = null;
|
|
3280
3306
|
continue;
|
|
3281
3307
|
}
|
|
3282
|
-
const colliderSignature = `${JSON.stringify(effectiveCollider)}:${
|
|
3308
|
+
const colliderSignature = `${JSON.stringify(effectiveCollider)}:${triMeshParts?.signature ?? ""}`;
|
|
3283
3309
|
const previousColliderSignature = this.colliderSignatures.get(entityId);
|
|
3284
3310
|
if (!this.colliderHandles.has(entityId) || previousColliderSignature !== colliderSignature) {
|
|
3285
3311
|
const previousColliderHandle = this.colliderHandles.get(entityId);
|
|
@@ -3292,7 +3318,7 @@ var _PhysicsSyncSystem = class _PhysicsSyncSystem {
|
|
|
3292
3318
|
const colliderDesc = createColliderDesc(
|
|
3293
3319
|
this.rapier,
|
|
3294
3320
|
effectiveCollider,
|
|
3295
|
-
|
|
3321
|
+
createTriMeshData(triMeshParts)
|
|
3296
3322
|
);
|
|
3297
3323
|
const createdCollider = physicsWorld.createCollider(colliderDesc, body);
|
|
3298
3324
|
this.colliderHandles.set(entityId, createdCollider.handle);
|