@series-inc/rundot-3d-engine 0.5.8 → 0.5.9

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.
@@ -296,6 +296,11 @@ declare class MeshColliderComponent extends Component {
296
296
  * Returns a flat Float32Array of [x,y,z, x,y,z, ...] in local space.
297
297
  */
298
298
  private static collectVertices;
299
+ /**
300
+ * Compute bounding box size and center from a mesh group, matching the editor's approach.
301
+ * Transforms sub-mesh bounding boxes through their local matrices so offset meshes are handled.
302
+ */
303
+ private static computeBounds;
299
304
  protected onCreate(): void;
300
305
  getRigidBody(): RigidBodyComponentThree | null;
301
306
  }
@@ -161,10 +161,40 @@ var MeshColliderComponent = class extends Component {
161
161
  });
162
162
  return new Float32Array(allVertices);
163
163
  }
164
+ /**
165
+ * Compute bounding box size and center from a mesh group, matching the editor's approach.
166
+ * Transforms sub-mesh bounding boxes through their local matrices so offset meshes are handled.
167
+ */
168
+ static computeBounds(meshGroup, scale) {
169
+ const box = new THREE2.Box3();
170
+ let foundMesh = false;
171
+ meshGroup.traverse((child) => {
172
+ if (child instanceof THREE2.Mesh && child.geometry) {
173
+ foundMesh = true;
174
+ if (!child.geometry.boundingBox) {
175
+ child.geometry.computeBoundingBox();
176
+ }
177
+ if (child.geometry.boundingBox) {
178
+ const localBox = child.geometry.boundingBox.clone();
179
+ localBox.applyMatrix4(child.matrix);
180
+ box.union(localBox);
181
+ }
182
+ }
183
+ });
184
+ if (!foundMesh || box.isEmpty()) return null;
185
+ const size = new THREE2.Vector3();
186
+ box.getSize(size);
187
+ size.multiply(scale);
188
+ const center = new THREE2.Vector3();
189
+ box.getCenter(center);
190
+ center.multiply(scale);
191
+ return { size, center };
192
+ }
164
193
  onCreate() {
165
194
  const stowkit = StowKitSystem.getInstance();
166
195
  const scale = this.gameObject.scale.clone();
167
196
  stowkit.getMesh(this.meshName).then((meshGroup) => {
197
+ if (!this.isAttached()) return;
168
198
  if (this.colliderType === "convex_hull") {
169
199
  const vertices = MeshColliderComponent.collectVertices(meshGroup, scale);
170
200
  if (vertices.length < 9) {
@@ -175,17 +205,19 @@ var MeshColliderComponent = class extends Component {
175
205
  type: this.bodyType,
176
206
  shape: "convex_hull" /* CONVEX_HULL */,
177
207
  vertices,
208
+ centerOffset: new THREE2.Vector3(0, 0, 0),
178
209
  isSensor: this.isSensor,
179
210
  enableCollisionEvents: this.enableCollisionEvents
180
211
  });
181
212
  this.gameObject.addComponent(this.rigidBody);
182
213
  } else {
183
- const bounds = stowkit.getBounds(meshGroup);
214
+ const bounds = MeshColliderComponent.computeBounds(meshGroup, scale);
184
215
  if (bounds) {
185
- const scaledBounds = bounds.clone().multiply(scale);
186
- this.rigidBody = RigidBodyComponentThree.fromBounds(scaledBounds, {
216
+ this.rigidBody = new RigidBodyComponentThree({
187
217
  type: this.bodyType,
188
218
  shape: "box" /* BOX */,
219
+ size: bounds.size,
220
+ centerOffset: bounds.center,
189
221
  isSensor: this.isSensor,
190
222
  enableCollisionEvents: this.enableCollisionEvents
191
223
  });