Update runtime scene build to filter disabled entities and interactions
This commit is contained in:
@@ -18,7 +18,7 @@ import {
|
|||||||
createPlayerStartMovementTemplate,
|
createPlayerStartMovementTemplate,
|
||||||
createPlayerStartInputBindings,
|
createPlayerStartInputBindings,
|
||||||
getEntityInstances,
|
getEntityInstances,
|
||||||
getPrimaryPlayerStartEntity,
|
getPrimaryEnabledPlayerStartEntity,
|
||||||
type EntityInstance,
|
type EntityInstance,
|
||||||
type PlayerStartInputBindings,
|
type PlayerStartInputBindings,
|
||||||
type PlayerStartJumpSettings,
|
type PlayerStartJumpSettings,
|
||||||
@@ -46,6 +46,7 @@ export interface RuntimeBrushFace {
|
|||||||
export interface RuntimeBoxBrushInstance {
|
export interface RuntimeBoxBrushInstance {
|
||||||
id: string;
|
id: string;
|
||||||
kind: "box";
|
kind: "box";
|
||||||
|
visible: boolean;
|
||||||
center: Vec3;
|
center: Vec3;
|
||||||
rotationDegrees: Vec3;
|
rotationDegrees: Vec3;
|
||||||
size: Vec3;
|
size: Vec3;
|
||||||
@@ -159,7 +160,7 @@ export interface RuntimeInteractable {
|
|||||||
position: Vec3;
|
position: Vec3;
|
||||||
radius: number;
|
radius: number;
|
||||||
prompt: string;
|
prompt: string;
|
||||||
enabled: boolean;
|
interactionEnabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RuntimeSceneExit {
|
export interface RuntimeSceneExit {
|
||||||
@@ -167,7 +168,7 @@ export interface RuntimeSceneExit {
|
|||||||
position: Vec3;
|
position: Vec3;
|
||||||
radius: number;
|
radius: number;
|
||||||
prompt: string;
|
prompt: string;
|
||||||
enabled: boolean;
|
interactionEnabled: boolean;
|
||||||
targetSceneId: string;
|
targetSceneId: string;
|
||||||
targetEntryEntityId: string;
|
targetEntryEntityId: string;
|
||||||
}
|
}
|
||||||
@@ -199,6 +200,7 @@ export interface RuntimeModelInstance {
|
|||||||
instanceId: string;
|
instanceId: string;
|
||||||
assetId: string;
|
assetId: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
|
visible: boolean;
|
||||||
position: Vec3;
|
position: Vec3;
|
||||||
rotationDegrees: Vec3;
|
rotationDegrees: Vec3;
|
||||||
scale: Vec3;
|
scale: Vec3;
|
||||||
@@ -248,7 +250,7 @@ export interface BuildRuntimeSceneOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function resolveRuntimeNavigationMode(
|
export function resolveRuntimeNavigationMode(
|
||||||
playerStartEntity: ReturnType<typeof getPrimaryPlayerStartEntity>,
|
playerStartEntity: ReturnType<typeof getPrimaryEnabledPlayerStartEntity>,
|
||||||
authoredOverride?: RuntimeNavigationMode
|
authoredOverride?: RuntimeNavigationMode
|
||||||
): RuntimeNavigationMode {
|
): RuntimeNavigationMode {
|
||||||
if (authoredOverride !== undefined) {
|
if (authoredOverride !== undefined) {
|
||||||
@@ -361,6 +363,7 @@ function buildRuntimeBrush(brush: BoxBrush, document: SceneDocument): RuntimeBox
|
|||||||
return {
|
return {
|
||||||
id: brush.id,
|
id: brush.id,
|
||||||
kind: "box",
|
kind: "box",
|
||||||
|
visible: brush.visible,
|
||||||
center: cloneVec3(brush.center),
|
center: cloneVec3(brush.center),
|
||||||
rotationDegrees: cloneVec3(brush.rotationDegrees),
|
rotationDegrees: cloneVec3(brush.rotationDegrees),
|
||||||
size: cloneVec3(brush.size),
|
size: cloneVec3(brush.size),
|
||||||
@@ -457,6 +460,7 @@ function buildRuntimeModelInstance(modelInstance: SceneDocument["modelInstances"
|
|||||||
instanceId: modelInstance.id,
|
instanceId: modelInstance.id,
|
||||||
assetId: modelInstance.assetId,
|
assetId: modelInstance.assetId,
|
||||||
name: modelInstance.name,
|
name: modelInstance.name,
|
||||||
|
visible: modelInstance.visible,
|
||||||
position: cloneVec3(modelInstance.position),
|
position: cloneVec3(modelInstance.position),
|
||||||
rotationDegrees: cloneVec3(modelInstance.rotationDegrees),
|
rotationDegrees: cloneVec3(modelInstance.rotationDegrees),
|
||||||
scale: cloneVec3(modelInstance.scale),
|
scale: cloneVec3(modelInstance.scale),
|
||||||
@@ -561,6 +565,10 @@ function buildRuntimeSceneCollections(document: SceneDocument): RuntimeSceneColl
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (const entity of getEntityInstances(document.entities)) {
|
for (const entity of getEntityInstances(document.entities)) {
|
||||||
|
if (!entity.enabled) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
switch (entity.kind) {
|
switch (entity.kind) {
|
||||||
case "pointLight":
|
case "pointLight":
|
||||||
localLights.pointLights.push({
|
localLights.pointLights.push({
|
||||||
@@ -639,7 +647,7 @@ function buildRuntimeSceneCollections(document: SceneDocument): RuntimeSceneColl
|
|||||||
position: cloneVec3(entity.position),
|
position: cloneVec3(entity.position),
|
||||||
radius: entity.radius,
|
radius: entity.radius,
|
||||||
prompt: entity.prompt,
|
prompt: entity.prompt,
|
||||||
enabled: entity.enabled
|
interactionEnabled: entity.interactionEnabled
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "sceneExit":
|
case "sceneExit":
|
||||||
@@ -648,7 +656,7 @@ function buildRuntimeSceneCollections(document: SceneDocument): RuntimeSceneColl
|
|||||||
position: cloneVec3(entity.position),
|
position: cloneVec3(entity.position),
|
||||||
radius: entity.radius,
|
radius: entity.radius,
|
||||||
prompt: entity.prompt,
|
prompt: entity.prompt,
|
||||||
enabled: entity.enabled,
|
interactionEnabled: entity.interactionEnabled,
|
||||||
targetSceneId: entity.targetSceneId,
|
targetSceneId: entity.targetSceneId,
|
||||||
targetEntryEntityId: entity.targetEntryEntityId
|
targetEntryEntityId: entity.targetEntryEntityId
|
||||||
});
|
});
|
||||||
@@ -669,7 +677,7 @@ function assertNever(value: never): never {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildRuntimePlayerShape(
|
function buildRuntimePlayerShape(
|
||||||
playerStartEntity: ReturnType<typeof getPrimaryPlayerStartEntity>
|
playerStartEntity: ReturnType<typeof getPrimaryEnabledPlayerStartEntity>
|
||||||
): FirstPersonPlayerShape {
|
): FirstPersonPlayerShape {
|
||||||
if (playerStartEntity === null) {
|
if (playerStartEntity === null) {
|
||||||
return FIRST_PERSON_PLAYER_SHAPE;
|
return FIRST_PERSON_PLAYER_SHAPE;
|
||||||
@@ -734,7 +742,7 @@ function resolveRuntimeSpawn(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function buildRuntimeSceneFromDocument(document: SceneDocument, options: BuildRuntimeSceneOptions = {}): RuntimeSceneDefinition {
|
export function buildRuntimeSceneFromDocument(document: SceneDocument, options: BuildRuntimeSceneOptions = {}): RuntimeSceneDefinition {
|
||||||
const playerStartEntity = getPrimaryPlayerStartEntity(document.entities);
|
const playerStartEntity = getPrimaryEnabledPlayerStartEntity(document.entities);
|
||||||
const navigationMode = resolveRuntimeNavigationMode(
|
const navigationMode = resolveRuntimeNavigationMode(
|
||||||
playerStartEntity,
|
playerStartEntity,
|
||||||
options.navigationMode
|
options.navigationMode
|
||||||
@@ -745,14 +753,15 @@ export function buildRuntimeSceneFromDocument(document: SceneDocument, options:
|
|||||||
loadedModelAssets: options.loadedModelAssets
|
loadedModelAssets: options.loadedModelAssets
|
||||||
});
|
});
|
||||||
|
|
||||||
const brushes = Object.values(document.brushes).map((brush) => buildRuntimeBrush(brush, document));
|
const enabledBrushes = Object.values(document.brushes).filter((brush) => brush.enabled);
|
||||||
|
const brushes = enabledBrushes.map((brush) => buildRuntimeBrush(brush, document));
|
||||||
const colliders: RuntimeSceneCollider[] = [];
|
const colliders: RuntimeSceneCollider[] = [];
|
||||||
const volumes: RuntimeBoxVolumeCollection = {
|
const volumes: RuntimeBoxVolumeCollection = {
|
||||||
fog: [],
|
fog: [],
|
||||||
water: []
|
water: []
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const brush of Object.values(document.brushes)) {
|
for (const brush of enabledBrushes) {
|
||||||
if (brush.volume.mode === "none") {
|
if (brush.volume.mode === "none") {
|
||||||
colliders.push(buildRuntimeCollider(brush));
|
colliders.push(buildRuntimeCollider(brush));
|
||||||
continue;
|
continue;
|
||||||
@@ -765,9 +774,36 @@ export function buildRuntimeSceneFromDocument(document: SceneDocument, options:
|
|||||||
|
|
||||||
volumes.water.push(buildRuntimeWaterVolume(brush));
|
volumes.water.push(buildRuntimeWaterVolume(brush));
|
||||||
}
|
}
|
||||||
const modelInstances = getModelInstances(document.modelInstances).map(buildRuntimeModelInstance);
|
const enabledModelInstances = getModelInstances(document.modelInstances).filter((modelInstance) => modelInstance.enabled);
|
||||||
|
const modelInstances = enabledModelInstances.map(buildRuntimeModelInstance);
|
||||||
const collections = buildRuntimeSceneCollections(document);
|
const collections = buildRuntimeSceneCollections(document);
|
||||||
const interactionLinks = getInteractionLinks(document.interactionLinks).map((link) => cloneInteractionLink(link));
|
const enabledBrushIds = new Set(enabledBrushes.map((brush) => brush.id));
|
||||||
|
const enabledModelInstanceIds = new Set(enabledModelInstances.map((modelInstance) => modelInstance.id));
|
||||||
|
const enabledEntityIds = new Set(
|
||||||
|
getEntityInstances(document.entities)
|
||||||
|
.filter((entity) => entity.enabled)
|
||||||
|
.map((entity) => entity.id)
|
||||||
|
);
|
||||||
|
const interactionLinks = getInteractionLinks(document.interactionLinks)
|
||||||
|
.filter((link) => {
|
||||||
|
if (!enabledEntityIds.has(link.sourceEntityId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (link.action.type) {
|
||||||
|
case "teleportPlayer":
|
||||||
|
return enabledEntityIds.has(link.action.targetEntityId);
|
||||||
|
case "toggleVisibility":
|
||||||
|
return enabledBrushIds.has(link.action.targetBrushId);
|
||||||
|
case "playAnimation":
|
||||||
|
case "stopAnimation":
|
||||||
|
return enabledModelInstanceIds.has(link.action.targetModelInstanceId);
|
||||||
|
case "playSound":
|
||||||
|
case "stopSound":
|
||||||
|
return enabledEntityIds.has(link.action.targetSoundEmitterId);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map((link) => cloneInteractionLink(link));
|
||||||
const playerCollider = buildRuntimePlayerShape(playerStartEntity);
|
const playerCollider = buildRuntimePlayerShape(playerStartEntity);
|
||||||
const playerMovement = buildRuntimePlayerMovement(
|
const playerMovement = buildRuntimePlayerMovement(
|
||||||
playerStartEntity?.movementTemplate
|
playerStartEntity?.movementTemplate
|
||||||
@@ -776,7 +812,7 @@ export function buildRuntimeSceneFromDocument(document: SceneDocument, options:
|
|||||||
playerStartEntity?.inputBindings
|
playerStartEntity?.inputBindings
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const modelInstance of getModelInstances(document.modelInstances)) {
|
for (const modelInstance of enabledModelInstances) {
|
||||||
const asset = document.assets[modelInstance.assetId];
|
const asset = document.assets[modelInstance.assetId];
|
||||||
|
|
||||||
if (asset === undefined || asset.kind !== "model") {
|
if (asset === undefined || asset.kind !== "model") {
|
||||||
|
|||||||
Reference in New Issue
Block a user