Fix findUsages/undo/node-lookup bugs, split Viewport and Editor, share command and inspector helpers
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1eb28314cf
commit
f140c2fd77
58 files changed
+1969
-1171
No files matched your search
+5
-12
@@ -4,6 +4,7 @@ import type { Asset } from '../core/model/Asset';
|
||||
import { isPlaceableType } from '../core/model/AssetTypes';
|
||||
import { instantiateContainer } from '../core/model/container';
|
||||
import { findObject } from '../core/model/hierarchy';
|
||||
import { descendantsBelow } from '../core/model/walk';
|
||||
import { findAsset, findScene, type Project } from '../core/model/Project';
|
||||
import { createSceneObject, type SceneObject } from '../core/model/SceneObject';
|
||||
import { footprintContains } from '../core/properties/bounds';
|
||||
@@ -71,7 +72,7 @@ export class World {
|
||||
const keep = new Set<Entity>();
|
||||
for (const object of scene.objects) {
|
||||
const asset = findAsset(this.project, object.assetId);
|
||||
if (!asset || asset.type === 'scene') continue;
|
||||
if (!asset || !isPlaceableType(asset.type)) continue;
|
||||
keep.add(this.materialize(object, asset));
|
||||
}
|
||||
for (let i = this.entities.length - 1; i >= 0; i--) if (!keep.has(this.entities[i]!)) this.entities.splice(i, 1);
|
||||
@@ -121,7 +122,7 @@ export class World {
|
||||
entity.parent = parentEntity;
|
||||
for (const child of created.slice(1)) {
|
||||
const childAsset = findAsset(this.project, child.assetId);
|
||||
if (!childAsset || childAsset.type === 'scene') continue;
|
||||
if (!childAsset || !isPlaceableType(childAsset.type)) continue;
|
||||
this.materialize(child, childAsset).parent = this.findByObjectId(child.parentId) ?? null;
|
||||
}
|
||||
this.structureChanged = true;
|
||||
@@ -144,7 +145,7 @@ export class World {
|
||||
for (let i = scene.objects.length - 1; i >= 0; i--) {
|
||||
const object = scene.objects[i]!;
|
||||
const asset = findAsset(this.project, object.assetId);
|
||||
if (asset && asset.type !== 'scene' && !alive.has(object.id)) scene.objects.splice(i, 1);
|
||||
if (asset && isPlaceableType(asset.type) && !alive.has(object.id)) scene.objects.splice(i, 1);
|
||||
}
|
||||
for (const entity of this.entities) {
|
||||
const object = findObject(scene, entity.objectId);
|
||||
@@ -219,15 +220,7 @@ export class World {
|
||||
|
||||
/** Everything parented below an entity, at any depth. */
|
||||
descendantsOf(entity: Entity): Entity[] {
|
||||
const result: Entity[] = [];
|
||||
const visit = (parent: Entity) => {
|
||||
for (const child of this.childrenOf(parent)) {
|
||||
result.push(child);
|
||||
visit(child);
|
||||
}
|
||||
};
|
||||
visit(entity);
|
||||
return result;
|
||||
return descendantsBelow(entity, (parent) => this.childrenOf(parent), (child) => child);
|
||||
}
|
||||
|
||||
findByObjectId(objectId: string): Entity | undefined {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { isHandleEnabled, worldPositionOf } from '../../core/graph';
|
||||
import { parentChain } from '../../core/model/walk';
|
||||
import { axisCorrection, colliderShape, colliderSize, isTrigger, type PlaneAxis, shapesOverlap } from '../../core/properties/collider';
|
||||
import type { Entity } from '../Entity';
|
||||
import type { World } from '../World';
|
||||
@@ -136,7 +137,7 @@ function penetration(a: Entity, b: Entity, axis: PlaneAxis, dir: 1 | -1): number
|
||||
|
||||
/** Whether `collider` belongs to `entity` or to something parented (at any depth) under it. */
|
||||
function travelsWith(collider: Entity, entity: Entity): boolean {
|
||||
for (let e: Entity | null = collider; e; e = e.parent) if (e === entity) return true;
|
||||
for (const e of parentChain(collider, (c) => c.parent)) if (e === entity) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -159,7 +160,7 @@ export function bodyOf(collider: Entity): Entity {
|
||||
}
|
||||
|
||||
/** A collider stands for itself; any other entity stands for its direct collider children. */
|
||||
export function collidersOf(world: World, entity: Entity): Entity[] {
|
||||
function collidersOf(world: World, entity: Entity): Entity[] {
|
||||
if (entity.type === 'collider') return [entity];
|
||||
return world.childrenOf(entity).filter((e) => e.type === 'collider' && isHandleEnabled(e));
|
||||
}
|
||||
Reference in new issue
Block a user