@relu-interactives/spatial-ecs 0.2.4 → 0.2.6
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/{System-BTyYvKVH.d.cts → System-CIiWteft.d.cts} +2 -2
- package/dist/{System-BTyYvKVH.d.ts → System-CIiWteft.d.ts} +2 -2
- package/dist/{Video-BWhbvVPg.d.ts → Video-B-qMljTn.d.ts} +147 -75
- package/dist/{Video-D2H5H-K3.d.cts → Video-Dj4KBqQ1.d.cts} +147 -75
- package/dist/{chunk-XWIEEJ7Z.js → chunk-EIC5B3A7.js} +128 -82
- package/dist/chunk-EIC5B3A7.js.map +1 -0
- package/dist/{chunk-AYEF3X2P.js → chunk-FDWNCXU3.js} +3 -3
- package/dist/chunk-FDWNCXU3.js.map +1 -0
- package/dist/{chunk-NFDTIYR4.js → chunk-G2DUXNTQ.js} +18 -2
- package/dist/chunk-G2DUXNTQ.js.map +1 -0
- package/dist/{chunk-P2YDX5DB.js → chunk-NRSUYDBA.js} +275 -5
- package/dist/chunk-NRSUYDBA.js.map +1 -0
- package/dist/{chunk-MAWBTMCG.js → chunk-R5D5PWXV.js} +160 -88
- package/dist/chunk-R5D5PWXV.js.map +1 -0
- package/dist/components/index.cjs +165 -93
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +1 -1
- package/dist/factories/index.cjs +221 -105
- package/dist/factories/index.cjs.map +1 -1
- package/dist/factories/index.d.cts +9 -3
- package/dist/factories/index.d.ts +9 -3
- package/dist/factories/index.js +3 -3
- package/dist/{index-KdEzEZox.d.cts → index-B12sx9yF.d.cts} +8 -3
- package/dist/{index-Dm6zF1MY.d.ts → index-Cf-PaKyN.d.ts} +8 -3
- package/dist/index.cjs +627 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +54 -12
- package/dist/index.js.map +1 -1
- package/dist/systems/index.cjs +403 -63
- package/dist/systems/index.cjs.map +1 -1
- package/dist/systems/index.d.cts +27 -3
- package/dist/systems/index.d.ts +27 -3
- package/dist/systems/index.js +3 -3
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/worldSnapshotUtils.cjs +16 -0
- package/dist/worldSnapshotUtils.cjs.map +1 -1
- package/dist/worldSnapshotUtils.d.cts +1 -1
- package/dist/worldSnapshotUtils.d.ts +1 -1
- package/dist/worldSnapshotUtils.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-AYEF3X2P.js.map +0 -1
- package/dist/chunk-MAWBTMCG.js.map +0 -1
- package/dist/chunk-NFDTIYR4.js.map +0 -1
- package/dist/chunk-P2YDX5DB.js.map +0 -1
- package/dist/chunk-XWIEEJ7Z.js.map +0 -1
package/dist/systems/index.cjs
CHANGED
|
@@ -1251,6 +1251,138 @@ var _Postprocessing = class _Postprocessing extends Component {
|
|
|
1251
1251
|
};
|
|
1252
1252
|
__name(_Postprocessing, "Postprocessing");
|
|
1253
1253
|
var Postprocessing = _Postprocessing;
|
|
1254
|
+
var DEFAULT_MESH_GEOMETRY_PARAMETERS = {
|
|
1255
|
+
capsule: { radius: 0.5, height: 1 },
|
|
1256
|
+
cube: { width: 1, height: 1, depth: 1 },
|
|
1257
|
+
cylinder: { radius: 0.5, height: 1 },
|
|
1258
|
+
plane: { width: 100, height: 100 },
|
|
1259
|
+
sphere: { radius: 0.5 }
|
|
1260
|
+
};
|
|
1261
|
+
var GEOMETRY_TYPE_BY_KIND = {
|
|
1262
|
+
capsule: "CapsuleGeometry",
|
|
1263
|
+
cube: "BoxGeometry",
|
|
1264
|
+
cylinder: "CylinderGeometry",
|
|
1265
|
+
model: "Model",
|
|
1266
|
+
plane: "PlaneGeometry",
|
|
1267
|
+
sphere: "SphereGeometry"
|
|
1268
|
+
};
|
|
1269
|
+
var _MeshGeometryComponent = class _MeshGeometryComponent extends Component {
|
|
1270
|
+
constructor(kind, object, parameters, options) {
|
|
1271
|
+
super();
|
|
1272
|
+
this.kind = kind;
|
|
1273
|
+
this.geometryType = GEOMETRY_TYPE_BY_KIND[kind];
|
|
1274
|
+
this.object = object;
|
|
1275
|
+
this.modelName = options?.modelName ?? "";
|
|
1276
|
+
this.castShadow = options?.castShadow ?? false;
|
|
1277
|
+
this.receiveShadow = options?.receiveShadow ?? false;
|
|
1278
|
+
switch (kind) {
|
|
1279
|
+
case "cube":
|
|
1280
|
+
this.parameters = {
|
|
1281
|
+
...DEFAULT_MESH_GEOMETRY_PARAMETERS.cube,
|
|
1282
|
+
...parameters
|
|
1283
|
+
};
|
|
1284
|
+
break;
|
|
1285
|
+
case "plane":
|
|
1286
|
+
this.parameters = {
|
|
1287
|
+
...DEFAULT_MESH_GEOMETRY_PARAMETERS.plane,
|
|
1288
|
+
...parameters
|
|
1289
|
+
};
|
|
1290
|
+
break;
|
|
1291
|
+
case "sphere":
|
|
1292
|
+
this.parameters = {
|
|
1293
|
+
...DEFAULT_MESH_GEOMETRY_PARAMETERS.sphere,
|
|
1294
|
+
...parameters
|
|
1295
|
+
};
|
|
1296
|
+
break;
|
|
1297
|
+
case "cylinder":
|
|
1298
|
+
this.parameters = {
|
|
1299
|
+
...DEFAULT_MESH_GEOMETRY_PARAMETERS.cylinder,
|
|
1300
|
+
...parameters
|
|
1301
|
+
};
|
|
1302
|
+
break;
|
|
1303
|
+
case "capsule":
|
|
1304
|
+
this.parameters = {
|
|
1305
|
+
...DEFAULT_MESH_GEOMETRY_PARAMETERS.capsule,
|
|
1306
|
+
...parameters
|
|
1307
|
+
};
|
|
1308
|
+
break;
|
|
1309
|
+
case "model":
|
|
1310
|
+
this.parameters = {};
|
|
1311
|
+
break;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
__name(_MeshGeometryComponent, "MeshGeometryComponent");
|
|
1316
|
+
var MeshGeometryComponent = _MeshGeometryComponent;
|
|
1317
|
+
|
|
1318
|
+
// core/components/InstancedMesh.ts
|
|
1319
|
+
var DEFAULT_INSTANCE_TRANSFORM = {
|
|
1320
|
+
position: { x: 0, y: 0, z: 0 },
|
|
1321
|
+
rotation: { x: 0, y: 0, z: 0 },
|
|
1322
|
+
scale: { x: 1, y: 1, z: 1 }
|
|
1323
|
+
};
|
|
1324
|
+
var DEFAULT_INSTANCED_MESH_PARAMETERS = {
|
|
1325
|
+
capsule: DEFAULT_MESH_GEOMETRY_PARAMETERS.capsule,
|
|
1326
|
+
cube: DEFAULT_MESH_GEOMETRY_PARAMETERS.cube,
|
|
1327
|
+
cylinder: DEFAULT_MESH_GEOMETRY_PARAMETERS.cylinder,
|
|
1328
|
+
model: DEFAULT_MESH_GEOMETRY_PARAMETERS.cube,
|
|
1329
|
+
plane: DEFAULT_MESH_GEOMETRY_PARAMETERS.plane,
|
|
1330
|
+
sphere: DEFAULT_MESH_GEOMETRY_PARAMETERS.sphere
|
|
1331
|
+
};
|
|
1332
|
+
var _InstancedMeshComponent = class _InstancedMeshComponent extends Component {
|
|
1333
|
+
constructor(meshKind = "cube", meshParameters, options) {
|
|
1334
|
+
super();
|
|
1335
|
+
this.meshKind = meshKind;
|
|
1336
|
+
this.modelPath = options?.modelPath ?? "";
|
|
1337
|
+
this.meshParameters = {
|
|
1338
|
+
...DEFAULT_INSTANCED_MESH_PARAMETERS[meshKind],
|
|
1339
|
+
...meshParameters ?? {}
|
|
1340
|
+
};
|
|
1341
|
+
this.castShadow = options?.castShadow ?? false;
|
|
1342
|
+
this.receiveShadow = options?.receiveShadow ?? false;
|
|
1343
|
+
this.instances = options?.instances && options.instances.length > 0 ? options.instances : [{ ...DEFAULT_INSTANCE_TRANSFORM }];
|
|
1344
|
+
this.instancedMesh = null;
|
|
1345
|
+
}
|
|
1346
|
+
/** Sanitize and return a copy of the current mesh parameters with valid values. */
|
|
1347
|
+
getSanitizedParameters() {
|
|
1348
|
+
const MIN_DIM = 0.01;
|
|
1349
|
+
const MIN_RAD = 1e-3;
|
|
1350
|
+
const sanitize = /* @__PURE__ */ __name((v, min) => Number.isFinite(v) ? Math.max(min, v) : min, "sanitize");
|
|
1351
|
+
switch (this.meshKind) {
|
|
1352
|
+
case "cube": {
|
|
1353
|
+
const p = this.meshParameters;
|
|
1354
|
+
return {
|
|
1355
|
+
width: sanitize(p.width, MIN_DIM),
|
|
1356
|
+
height: sanitize(p.height, MIN_DIM),
|
|
1357
|
+
depth: sanitize(p.depth, MIN_DIM)
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
case "plane": {
|
|
1361
|
+
const p = this.meshParameters;
|
|
1362
|
+
return {
|
|
1363
|
+
width: sanitize(p.width, MIN_DIM),
|
|
1364
|
+
height: sanitize(p.height, MIN_DIM)
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
case "sphere": {
|
|
1368
|
+
const p = this.meshParameters;
|
|
1369
|
+
return { radius: sanitize(p.radius, MIN_RAD) };
|
|
1370
|
+
}
|
|
1371
|
+
case "cylinder":
|
|
1372
|
+
case "capsule": {
|
|
1373
|
+
const p = this.meshParameters;
|
|
1374
|
+
return {
|
|
1375
|
+
radius: sanitize(p.radius, MIN_RAD),
|
|
1376
|
+
height: sanitize(p.height, MIN_DIM)
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
case "model":
|
|
1380
|
+
return DEFAULT_MESH_GEOMETRY_PARAMETERS.cube;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
__name(_InstancedMeshComponent, "InstancedMeshComponent");
|
|
1385
|
+
var InstancedMeshComponent = _InstancedMeshComponent;
|
|
1254
1386
|
|
|
1255
1387
|
// core/components/Physics.ts
|
|
1256
1388
|
var DEFAULT_RIGIDBODY_STATE = {
|
|
@@ -1611,69 +1743,6 @@ var _MaterialComponent = class _MaterialComponent extends Component {
|
|
|
1611
1743
|
};
|
|
1612
1744
|
__name(_MaterialComponent, "MaterialComponent");
|
|
1613
1745
|
var MaterialComponent = _MaterialComponent;
|
|
1614
|
-
var DEFAULT_MESH_GEOMETRY_PARAMETERS = {
|
|
1615
|
-
capsule: { radius: 0.5, height: 1 },
|
|
1616
|
-
cube: { width: 1, height: 1, depth: 1 },
|
|
1617
|
-
cylinder: { radius: 0.5, height: 1 },
|
|
1618
|
-
plane: { width: 100, height: 100 },
|
|
1619
|
-
sphere: { radius: 0.5 }
|
|
1620
|
-
};
|
|
1621
|
-
var GEOMETRY_TYPE_BY_KIND = {
|
|
1622
|
-
capsule: "CapsuleGeometry",
|
|
1623
|
-
cube: "BoxGeometry",
|
|
1624
|
-
cylinder: "CylinderGeometry",
|
|
1625
|
-
model: "Model",
|
|
1626
|
-
plane: "PlaneGeometry",
|
|
1627
|
-
sphere: "SphereGeometry"
|
|
1628
|
-
};
|
|
1629
|
-
var _MeshGeometryComponent = class _MeshGeometryComponent extends Component {
|
|
1630
|
-
constructor(kind, object, parameters, options) {
|
|
1631
|
-
super();
|
|
1632
|
-
this.kind = kind;
|
|
1633
|
-
this.geometryType = GEOMETRY_TYPE_BY_KIND[kind];
|
|
1634
|
-
this.object = object;
|
|
1635
|
-
this.modelName = options?.modelName ?? "";
|
|
1636
|
-
this.castShadow = options?.castShadow ?? false;
|
|
1637
|
-
this.receiveShadow = options?.receiveShadow ?? false;
|
|
1638
|
-
switch (kind) {
|
|
1639
|
-
case "cube":
|
|
1640
|
-
this.parameters = {
|
|
1641
|
-
...DEFAULT_MESH_GEOMETRY_PARAMETERS.cube,
|
|
1642
|
-
...parameters
|
|
1643
|
-
};
|
|
1644
|
-
break;
|
|
1645
|
-
case "plane":
|
|
1646
|
-
this.parameters = {
|
|
1647
|
-
...DEFAULT_MESH_GEOMETRY_PARAMETERS.plane,
|
|
1648
|
-
...parameters
|
|
1649
|
-
};
|
|
1650
|
-
break;
|
|
1651
|
-
case "sphere":
|
|
1652
|
-
this.parameters = {
|
|
1653
|
-
...DEFAULT_MESH_GEOMETRY_PARAMETERS.sphere,
|
|
1654
|
-
...parameters
|
|
1655
|
-
};
|
|
1656
|
-
break;
|
|
1657
|
-
case "cylinder":
|
|
1658
|
-
this.parameters = {
|
|
1659
|
-
...DEFAULT_MESH_GEOMETRY_PARAMETERS.cylinder,
|
|
1660
|
-
...parameters
|
|
1661
|
-
};
|
|
1662
|
-
break;
|
|
1663
|
-
case "capsule":
|
|
1664
|
-
this.parameters = {
|
|
1665
|
-
...DEFAULT_MESH_GEOMETRY_PARAMETERS.capsule,
|
|
1666
|
-
...parameters
|
|
1667
|
-
};
|
|
1668
|
-
break;
|
|
1669
|
-
case "model":
|
|
1670
|
-
this.parameters = {};
|
|
1671
|
-
break;
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
};
|
|
1675
|
-
__name(_MeshGeometryComponent, "MeshGeometryComponent");
|
|
1676
|
-
var MeshGeometryComponent = _MeshGeometryComponent;
|
|
1677
1746
|
|
|
1678
1747
|
// core/components/Model.ts
|
|
1679
1748
|
var _ModelComponent = class _ModelComponent extends Component {
|
|
@@ -4068,6 +4137,276 @@ var _MeshGeometrySystem = class _MeshGeometrySystem {
|
|
|
4068
4137
|
};
|
|
4069
4138
|
__name(_MeshGeometrySystem, "MeshGeometrySystem");
|
|
4070
4139
|
var MeshGeometrySystem = _MeshGeometrySystem;
|
|
4140
|
+
var DRACO_DECODER_PATH = resolveDracoDecoderPath();
|
|
4141
|
+
var loadGLTF = /* @__PURE__ */ __name((path) => {
|
|
4142
|
+
return new Promise((resolve, reject) => {
|
|
4143
|
+
const loader = new GLTFLoader_js.GLTFLoader();
|
|
4144
|
+
try {
|
|
4145
|
+
const dracoLoader = new DRACOLoader_js.DRACOLoader();
|
|
4146
|
+
dracoLoader.setDecoderPath(DRACO_DECODER_PATH);
|
|
4147
|
+
loader.setDRACOLoader(dracoLoader);
|
|
4148
|
+
} catch (error) {
|
|
4149
|
+
console.debug("DRACOLoader setup failed or unavailable", error);
|
|
4150
|
+
}
|
|
4151
|
+
loader.load(
|
|
4152
|
+
path,
|
|
4153
|
+
(gltf) => {
|
|
4154
|
+
resolve(gltf);
|
|
4155
|
+
},
|
|
4156
|
+
void 0,
|
|
4157
|
+
(error) => {
|
|
4158
|
+
console.debug("GLTFLoader failed to load", error);
|
|
4159
|
+
reject(error);
|
|
4160
|
+
}
|
|
4161
|
+
);
|
|
4162
|
+
});
|
|
4163
|
+
}, "loadGLTF");
|
|
4164
|
+
|
|
4165
|
+
// core/systems/InstancedMeshSystem.ts
|
|
4166
|
+
function buildGeometry(component) {
|
|
4167
|
+
const p = component.getSanitizedParameters();
|
|
4168
|
+
switch (component.meshKind) {
|
|
4169
|
+
case "cube": {
|
|
4170
|
+
const params = p;
|
|
4171
|
+
return new THREE13__namespace.BoxGeometry(params.width, params.height, params.depth);
|
|
4172
|
+
}
|
|
4173
|
+
case "plane": {
|
|
4174
|
+
const params = p;
|
|
4175
|
+
return new THREE13__namespace.PlaneGeometry(params.width, params.height);
|
|
4176
|
+
}
|
|
4177
|
+
case "sphere": {
|
|
4178
|
+
const params = p;
|
|
4179
|
+
return new THREE13__namespace.SphereGeometry(params.radius, 24, 24);
|
|
4180
|
+
}
|
|
4181
|
+
case "cylinder": {
|
|
4182
|
+
const params = p;
|
|
4183
|
+
return new THREE13__namespace.CylinderGeometry(params.radius, params.radius, params.height, 20);
|
|
4184
|
+
}
|
|
4185
|
+
case "capsule": {
|
|
4186
|
+
const params = p;
|
|
4187
|
+
return new THREE13__namespace.CapsuleGeometry(params.radius, params.height, 4, 8);
|
|
4188
|
+
}
|
|
4189
|
+
default:
|
|
4190
|
+
return new THREE13__namespace.BoxGeometry(1, 1, 1);
|
|
4191
|
+
}
|
|
4192
|
+
}
|
|
4193
|
+
__name(buildGeometry, "buildGeometry");
|
|
4194
|
+
var _position = new THREE13__namespace.Vector3();
|
|
4195
|
+
var _quaternion = new THREE13__namespace.Quaternion();
|
|
4196
|
+
var _euler = new THREE13__namespace.Euler();
|
|
4197
|
+
var _scale = new THREE13__namespace.Vector3();
|
|
4198
|
+
var _matrix = new THREE13__namespace.Matrix4();
|
|
4199
|
+
var _modelMatrix = new THREE13__namespace.Matrix4();
|
|
4200
|
+
function instanceTransformToMatrix4(inst, out) {
|
|
4201
|
+
_position.set(inst.position.x, inst.position.y, inst.position.z);
|
|
4202
|
+
_euler.set(inst.rotation.x, inst.rotation.y, inst.rotation.z, "XYZ");
|
|
4203
|
+
_quaternion.setFromEuler(_euler);
|
|
4204
|
+
_scale.set(inst.scale.x, inst.scale.y, inst.scale.z);
|
|
4205
|
+
out.compose(_position, _quaternion, _scale);
|
|
4206
|
+
}
|
|
4207
|
+
__name(instanceTransformToMatrix4, "instanceTransformToMatrix4");
|
|
4208
|
+
function disposePrimitiveInstancedMesh(mesh) {
|
|
4209
|
+
mesh.geometry.dispose();
|
|
4210
|
+
if (Array.isArray(mesh.material)) {
|
|
4211
|
+
for (const m of mesh.material) {
|
|
4212
|
+
m.dispose();
|
|
4213
|
+
}
|
|
4214
|
+
} else {
|
|
4215
|
+
mesh.material.dispose();
|
|
4216
|
+
}
|
|
4217
|
+
}
|
|
4218
|
+
__name(disposePrimitiveInstancedMesh, "disposePrimitiveInstancedMesh");
|
|
4219
|
+
function disposeModelGroup(group) {
|
|
4220
|
+
group.traverse((child) => {
|
|
4221
|
+
const im = child;
|
|
4222
|
+
if (im.isInstancedMesh) {
|
|
4223
|
+
im.geometry.dispose();
|
|
4224
|
+
if (Array.isArray(im.material)) {
|
|
4225
|
+
for (const m of im.material) {
|
|
4226
|
+
m.dispose();
|
|
4227
|
+
}
|
|
4228
|
+
} else {
|
|
4229
|
+
im.material.dispose();
|
|
4230
|
+
}
|
|
4231
|
+
}
|
|
4232
|
+
});
|
|
4233
|
+
}
|
|
4234
|
+
__name(disposeModelGroup, "disposeModelGroup");
|
|
4235
|
+
var _InstancedMeshSystem = class _InstancedMeshSystem {
|
|
4236
|
+
constructor() {
|
|
4237
|
+
/** Signature tracking for geometry + instance count changes. */
|
|
4238
|
+
this.geometrySignatures = /* @__PURE__ */ new Map();
|
|
4239
|
+
/** Entities whose GLTF model is currently loading. Prevents duplicate load triggers. */
|
|
4240
|
+
this.loadingEntities = /* @__PURE__ */ new Set();
|
|
4241
|
+
/** Per-mesh data for model kind, populated after GLTF load. */
|
|
4242
|
+
this.modelMeshEntries = /* @__PURE__ */ new Map();
|
|
4243
|
+
}
|
|
4244
|
+
update(world) {
|
|
4245
|
+
const entityIds = world.query(InstancedMeshComponent);
|
|
4246
|
+
const alive = new Set(entityIds);
|
|
4247
|
+
for (const trackedId of this.geometrySignatures.keys()) {
|
|
4248
|
+
if (!alive.has(trackedId)) this.geometrySignatures.delete(trackedId);
|
|
4249
|
+
}
|
|
4250
|
+
for (const trackedId of this.loadingEntities) {
|
|
4251
|
+
if (!alive.has(trackedId)) this.loadingEntities.delete(trackedId);
|
|
4252
|
+
}
|
|
4253
|
+
for (const trackedId of this.modelMeshEntries.keys()) {
|
|
4254
|
+
if (!alive.has(trackedId)) this.modelMeshEntries.delete(trackedId);
|
|
4255
|
+
}
|
|
4256
|
+
for (const entityId of entityIds) {
|
|
4257
|
+
const comp = world.getComponent(
|
|
4258
|
+
entityId,
|
|
4259
|
+
InstancedMeshComponent
|
|
4260
|
+
);
|
|
4261
|
+
if (!comp) continue;
|
|
4262
|
+
const objectRef = world.getComponent(entityId, Object3DRef);
|
|
4263
|
+
const anchor = objectRef?.object ?? null;
|
|
4264
|
+
if (!anchor) continue;
|
|
4265
|
+
const instanceCount = comp.instances.length;
|
|
4266
|
+
const geometrySignature = comp.meshKind === "model" ? `model:${comp.modelPath}:${instanceCount}` : `${comp.meshKind}:${JSON.stringify(comp.meshParameters)}:${instanceCount}`;
|
|
4267
|
+
const needsRebuild = comp.instancedMesh === null || this.geometrySignatures.get(entityId) !== geometrySignature;
|
|
4268
|
+
if (needsRebuild) {
|
|
4269
|
+
if (comp.instancedMesh) {
|
|
4270
|
+
anchor.remove(comp.instancedMesh);
|
|
4271
|
+
if (comp.instancedMesh.isInstancedMesh) {
|
|
4272
|
+
disposePrimitiveInstancedMesh(comp.instancedMesh);
|
|
4273
|
+
} else {
|
|
4274
|
+
disposeModelGroup(comp.instancedMesh);
|
|
4275
|
+
}
|
|
4276
|
+
comp.instancedMesh = null;
|
|
4277
|
+
}
|
|
4278
|
+
this.loadingEntities.delete(entityId);
|
|
4279
|
+
this.modelMeshEntries.delete(entityId);
|
|
4280
|
+
if (comp.meshKind === "model") {
|
|
4281
|
+
if (comp.modelPath && !this.loadingEntities.has(entityId)) {
|
|
4282
|
+
this.loadingEntities.add(entityId);
|
|
4283
|
+
const targetSignature = geometrySignature;
|
|
4284
|
+
const targetEntityId = entityId;
|
|
4285
|
+
loadGLTF(comp.modelPath).then((gltf) => {
|
|
4286
|
+
if (!world.hasEntity(targetEntityId)) {
|
|
4287
|
+
this.loadingEntities.delete(targetEntityId);
|
|
4288
|
+
return;
|
|
4289
|
+
}
|
|
4290
|
+
const currentComp = world.getComponent(
|
|
4291
|
+
targetEntityId,
|
|
4292
|
+
InstancedMeshComponent
|
|
4293
|
+
);
|
|
4294
|
+
if (!currentComp) {
|
|
4295
|
+
this.loadingEntities.delete(targetEntityId);
|
|
4296
|
+
return;
|
|
4297
|
+
}
|
|
4298
|
+
const currentSig = `model:${currentComp.modelPath}:${currentComp.instances.length}`;
|
|
4299
|
+
if (currentSig !== targetSignature) {
|
|
4300
|
+
this.loadingEntities.delete(targetEntityId);
|
|
4301
|
+
return;
|
|
4302
|
+
}
|
|
4303
|
+
const currentRef = world.getComponent(targetEntityId, Object3DRef);
|
|
4304
|
+
const currentAnchor = currentRef?.object ?? null;
|
|
4305
|
+
if (!currentAnchor) {
|
|
4306
|
+
this.loadingEntities.delete(targetEntityId);
|
|
4307
|
+
return;
|
|
4308
|
+
}
|
|
4309
|
+
const count2 = Math.max(1, currentComp.instances.length);
|
|
4310
|
+
const entries = [];
|
|
4311
|
+
gltf.scene.updateWorldMatrix(true, true);
|
|
4312
|
+
gltf.scene.traverse((child) => {
|
|
4313
|
+
const meshChild = child;
|
|
4314
|
+
if (!meshChild.isMesh) return;
|
|
4315
|
+
const geometry2 = meshChild.geometry.clone();
|
|
4316
|
+
const sourceMaterial = Array.isArray(meshChild.material) ? meshChild.material.map((m) => m.clone()) : meshChild.material.clone();
|
|
4317
|
+
meshChild.updateWorldMatrix(true, false);
|
|
4318
|
+
const localMatrix = meshChild.matrixWorld.clone();
|
|
4319
|
+
const instancedMesh2 = new THREE13__namespace.InstancedMesh(
|
|
4320
|
+
geometry2,
|
|
4321
|
+
Array.isArray(sourceMaterial) ? sourceMaterial : sourceMaterial,
|
|
4322
|
+
count2
|
|
4323
|
+
);
|
|
4324
|
+
instancedMesh2.castShadow = currentComp.castShadow;
|
|
4325
|
+
instancedMesh2.receiveShadow = currentComp.receiveShadow;
|
|
4326
|
+
for (let i = 0; i < count2; i++) {
|
|
4327
|
+
const inst = currentComp.instances[i] ?? {
|
|
4328
|
+
position: { x: 0, y: 0, z: 0 },
|
|
4329
|
+
rotation: { x: 0, y: 0, z: 0 },
|
|
4330
|
+
scale: { x: 1, y: 1, z: 1 }
|
|
4331
|
+
};
|
|
4332
|
+
instanceTransformToMatrix4(inst, _matrix);
|
|
4333
|
+
_modelMatrix.multiplyMatrices(_matrix, localMatrix);
|
|
4334
|
+
instancedMesh2.setMatrixAt(i, _modelMatrix);
|
|
4335
|
+
}
|
|
4336
|
+
instancedMesh2.instanceMatrix.needsUpdate = true;
|
|
4337
|
+
entries.push({ localMatrix, instancedMesh: instancedMesh2 });
|
|
4338
|
+
});
|
|
4339
|
+
if (entries.length === 0) {
|
|
4340
|
+
this.loadingEntities.delete(targetEntityId);
|
|
4341
|
+
return;
|
|
4342
|
+
}
|
|
4343
|
+
const group = new THREE13__namespace.Group();
|
|
4344
|
+
for (const entry of entries) {
|
|
4345
|
+
group.add(entry.instancedMesh);
|
|
4346
|
+
}
|
|
4347
|
+
currentAnchor.add(group);
|
|
4348
|
+
currentComp.instancedMesh = group;
|
|
4349
|
+
this.modelMeshEntries.set(targetEntityId, entries);
|
|
4350
|
+
this.geometrySignatures.set(targetEntityId, targetSignature);
|
|
4351
|
+
this.loadingEntities.delete(targetEntityId);
|
|
4352
|
+
}).catch(() => {
|
|
4353
|
+
this.loadingEntities.delete(targetEntityId);
|
|
4354
|
+
});
|
|
4355
|
+
}
|
|
4356
|
+
continue;
|
|
4357
|
+
}
|
|
4358
|
+
const count = Math.max(1, instanceCount);
|
|
4359
|
+
const geometry = buildGeometry(comp);
|
|
4360
|
+
const material = new THREE13__namespace.MeshStandardMaterial({ color: "#ffffff" });
|
|
4361
|
+
const instancedMesh = new THREE13__namespace.InstancedMesh(geometry, material, count);
|
|
4362
|
+
instancedMesh.castShadow = comp.castShadow;
|
|
4363
|
+
instancedMesh.receiveShadow = comp.receiveShadow;
|
|
4364
|
+
for (let i = 0; i < count; i++) {
|
|
4365
|
+
const inst = comp.instances[i] ?? {
|
|
4366
|
+
position: { x: 0, y: 0, z: 0 },
|
|
4367
|
+
rotation: { x: 0, y: 0, z: 0 },
|
|
4368
|
+
scale: { x: 1, y: 1, z: 1 }
|
|
4369
|
+
};
|
|
4370
|
+
instanceTransformToMatrix4(inst, _matrix);
|
|
4371
|
+
instancedMesh.setMatrixAt(i, _matrix);
|
|
4372
|
+
}
|
|
4373
|
+
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
4374
|
+
anchor.add(instancedMesh);
|
|
4375
|
+
comp.instancedMesh = instancedMesh;
|
|
4376
|
+
this.geometrySignatures.set(entityId, geometrySignature);
|
|
4377
|
+
} else {
|
|
4378
|
+
if (comp.meshKind === "model") {
|
|
4379
|
+
const entries = this.modelMeshEntries.get(entityId);
|
|
4380
|
+
if (entries) {
|
|
4381
|
+
const count = comp.instances.length;
|
|
4382
|
+
for (const entry of entries) {
|
|
4383
|
+
for (let i = 0; i < count; i++) {
|
|
4384
|
+
instanceTransformToMatrix4(comp.instances[i], _matrix);
|
|
4385
|
+
_modelMatrix.multiplyMatrices(_matrix, entry.localMatrix);
|
|
4386
|
+
entry.instancedMesh.setMatrixAt(i, _modelMatrix);
|
|
4387
|
+
}
|
|
4388
|
+
entry.instancedMesh.instanceMatrix.needsUpdate = true;
|
|
4389
|
+
entry.instancedMesh.castShadow = comp.castShadow;
|
|
4390
|
+
entry.instancedMesh.receiveShadow = comp.receiveShadow;
|
|
4391
|
+
}
|
|
4392
|
+
}
|
|
4393
|
+
} else {
|
|
4394
|
+
const im = comp.instancedMesh;
|
|
4395
|
+
const count = comp.instances.length;
|
|
4396
|
+
for (let i = 0; i < count; i++) {
|
|
4397
|
+
instanceTransformToMatrix4(comp.instances[i], _matrix);
|
|
4398
|
+
im.setMatrixAt(i, _matrix);
|
|
4399
|
+
}
|
|
4400
|
+
im.instanceMatrix.needsUpdate = true;
|
|
4401
|
+
im.castShadow = comp.castShadow;
|
|
4402
|
+
im.receiveShadow = comp.receiveShadow;
|
|
4403
|
+
}
|
|
4404
|
+
}
|
|
4405
|
+
}
|
|
4406
|
+
}
|
|
4407
|
+
};
|
|
4408
|
+
__name(_InstancedMeshSystem, "InstancedMeshSystem");
|
|
4409
|
+
var InstancedMeshSystem = _InstancedMeshSystem;
|
|
4071
4410
|
|
|
4072
4411
|
// core/systems/RenderSystem.ts
|
|
4073
4412
|
var _RenderSystem = class _RenderSystem {
|
|
@@ -5103,6 +5442,7 @@ exports.AudioSystem = AudioSystem;
|
|
|
5103
5442
|
exports.CameraSyncSystem = CameraSyncSystem;
|
|
5104
5443
|
exports.EnvironmentSyncSystem = EnvironmentSyncSystem;
|
|
5105
5444
|
exports.InputSystem = InputSystem;
|
|
5445
|
+
exports.InstancedMeshSystem = InstancedMeshSystem;
|
|
5106
5446
|
exports.KeyboardKeys = KeyboardKeys;
|
|
5107
5447
|
exports.LightSyncSystem = LightSyncSystem;
|
|
5108
5448
|
exports.MaterialSyncSystem = MaterialSyncSystem;
|