Update version references and refactor collider generation logic
This commit is contained in:
@@ -1489,7 +1489,7 @@ export function migrateSceneDocument(source: unknown): SceneDocument {
|
|||||||
const assets = readAssets(source.assets);
|
const assets = readAssets(source.assets);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
version: ENTITY_NAMES_SCENE_DOCUMENT_VERSION,
|
version: SCENE_DOCUMENT_VERSION,
|
||||||
name: expectString(source.name, "name"),
|
name: expectString(source.name, "name"),
|
||||||
world: readWorldSettings(source.world),
|
world: readWorldSettings(source.world),
|
||||||
materials,
|
materials,
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {
|
|||||||
Mesh,
|
Mesh,
|
||||||
Quaternion,
|
Quaternion,
|
||||||
Vector3,
|
Vector3,
|
||||||
type BufferAttribute,
|
|
||||||
type BufferGeometry
|
type BufferGeometry
|
||||||
} from "three";
|
} from "three";
|
||||||
|
|
||||||
@@ -206,7 +205,13 @@ function computeWorldBoundsFromLocalBox(localBounds: GeneratedColliderBounds, mo
|
|||||||
return computeBoundsFromPoints(corners.map((corner) => corner.applyMatrix4(modelMatrix)));
|
return computeBoundsFromPoints(corners.map((corner) => corner.applyMatrix4(modelMatrix)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function readIndexedVertex(position: BufferAttribute, index: number, matrix: Matrix4): Vector3 {
|
interface PositionLikeAttribute {
|
||||||
|
getX(index: number): number;
|
||||||
|
getY(index: number): number;
|
||||||
|
getZ(index: number): number;
|
||||||
|
}
|
||||||
|
|
||||||
|
function readIndexedVertex(position: PositionLikeAttribute, index: number, matrix: Matrix4): Vector3 {
|
||||||
return new Vector3(position.getX(index), position.getY(index), position.getZ(index)).applyMatrix4(matrix);
|
return new Vector3(position.getX(index), position.getY(index), position.getZ(index)).applyMatrix4(matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import RAPIER from "@dimforge/rapier3d-compat";
|
import RAPIER from "@dimforge/rapier3d-compat";
|
||||||
import { Euler, MathUtils, Quaternion, Vector3 } from "three";
|
import { Euler, MathUtils, Quaternion } from "three";
|
||||||
|
|
||||||
import type { Vec3 } from "../core/vector";
|
import type { Vec3 } from "../core/vector";
|
||||||
import type {
|
import type {
|
||||||
@@ -18,14 +18,6 @@ const COLLISION_EPSILON = 1e-5;
|
|||||||
|
|
||||||
let rapierInitPromise: Promise<typeof RAPIER> | null = null;
|
let rapierInitPromise: Promise<typeof RAPIER> | null = null;
|
||||||
|
|
||||||
function cloneVec3(vector: Vec3): Vec3 {
|
|
||||||
return {
|
|
||||||
x: vector.x,
|
|
||||||
y: vector.y,
|
|
||||||
z: vector.z
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function componentScale(vector: Vec3, scale: Vec3): Vec3 {
|
function componentScale(vector: Vec3, scale: Vec3): Vec3 {
|
||||||
return {
|
return {
|
||||||
x: vector.x * scale.x,
|
x: vector.x * scale.x,
|
||||||
|
|||||||
@@ -510,7 +510,11 @@ export class RuntimeHost {
|
|||||||
name: modelInstance.name,
|
name: modelInstance.name,
|
||||||
position: modelInstance.position,
|
position: modelInstance.position,
|
||||||
rotationDegrees: modelInstance.rotationDegrees,
|
rotationDegrees: modelInstance.rotationDegrees,
|
||||||
scale: modelInstance.scale
|
scale: modelInstance.scale,
|
||||||
|
collision: {
|
||||||
|
mode: "none",
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
asset,
|
asset,
|
||||||
loadedAsset,
|
loadedAsset,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { BoxGeometry } from "three";
|
||||||
|
|
||||||
import { createBoxBrush } from "../../src/document/brushes";
|
import { createBoxBrush } from "../../src/document/brushes";
|
||||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||||
@@ -15,6 +16,7 @@ import { createTeleportPlayerInteractionLink, createToggleVisibilityInteractionL
|
|||||||
import { createModelInstance } from "../../src/assets/model-instances";
|
import { createModelInstance } from "../../src/assets/model-instances";
|
||||||
import { createProjectAssetStorageKey, type AudioAssetRecord } from "../../src/assets/project-assets";
|
import { createProjectAssetStorageKey, type AudioAssetRecord } from "../../src/assets/project-assets";
|
||||||
import { buildRuntimeSceneFromDocument } from "../../src/runtime-three/runtime-scene-build";
|
import { buildRuntimeSceneFromDocument } from "../../src/runtime-three/runtime-scene-build";
|
||||||
|
import { createFixtureLoadedModelAssetFromGeometry } from "../helpers/model-collider-fixtures";
|
||||||
|
|
||||||
describe("buildRuntimeSceneFromDocument", () => {
|
describe("buildRuntimeSceneFromDocument", () => {
|
||||||
it("builds runtime brush data, colliders, and an authored player spawn from the document", () => {
|
it("builds runtime brush data, colliders, and an authored player spawn from the document", () => {
|
||||||
@@ -286,6 +288,7 @@ describe("buildRuntimeSceneFromDocument", () => {
|
|||||||
expect(runtimeScene.colliders).toEqual([
|
expect(runtimeScene.colliders).toEqual([
|
||||||
{
|
{
|
||||||
kind: "box",
|
kind: "box",
|
||||||
|
source: "brush",
|
||||||
brushId: "brush-room-floor",
|
brushId: "brush-room-floor",
|
||||||
min: {
|
min: {
|
||||||
x: -4,
|
x: -4,
|
||||||
@@ -526,4 +529,65 @@ describe("buildRuntimeSceneFromDocument", () => {
|
|||||||
})
|
})
|
||||||
).toThrow("First-person run requires an authored Player Start");
|
).toThrow("First-person run requires an authored Player Start");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("adds generated imported-model colliders to the runtime scene build", () => {
|
||||||
|
const floorBrush = createBoxBrush({
|
||||||
|
id: "brush-runtime-floor",
|
||||||
|
center: {
|
||||||
|
x: 0,
|
||||||
|
y: -0.5,
|
||||||
|
z: 0
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
x: 8,
|
||||||
|
y: 1,
|
||||||
|
z: 8
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const { asset, loadedAsset } = createFixtureLoadedModelAssetFromGeometry("asset-runtime-collider", new BoxGeometry(1, 2, 1));
|
||||||
|
const modelInstance = createModelInstance({
|
||||||
|
id: "model-instance-runtime-collider",
|
||||||
|
assetId: asset.id,
|
||||||
|
position: {
|
||||||
|
x: 2,
|
||||||
|
y: 1,
|
||||||
|
z: 0
|
||||||
|
},
|
||||||
|
collision: {
|
||||||
|
mode: "static",
|
||||||
|
visible: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const runtimeScene = buildRuntimeSceneFromDocument(
|
||||||
|
{
|
||||||
|
...createEmptySceneDocument({ name: "Imported Collider Scene" }),
|
||||||
|
assets: {
|
||||||
|
[asset.id]: asset
|
||||||
|
},
|
||||||
|
brushes: {
|
||||||
|
[floorBrush.id]: floorBrush
|
||||||
|
},
|
||||||
|
modelInstances: {
|
||||||
|
[modelInstance.id]: modelInstance
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loadedModelAssets: {
|
||||||
|
[asset.id]: loadedAsset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(runtimeScene.colliders).toHaveLength(2);
|
||||||
|
expect(runtimeScene.colliders[1]).toMatchObject({
|
||||||
|
source: "modelInstance",
|
||||||
|
instanceId: modelInstance.id,
|
||||||
|
assetId: asset.id,
|
||||||
|
kind: "trimesh",
|
||||||
|
mode: "static",
|
||||||
|
visible: true
|
||||||
|
});
|
||||||
|
expect(runtimeScene.sceneBounds?.max.y).toBeGreaterThanOrEqual(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -585,6 +585,64 @@ describe("scene document JSON", () => {
|
|||||||
expect(parseSceneDocumentJson(serializeSceneDocument(document))).toEqual(document);
|
expect(parseSceneDocumentJson(serializeSceneDocument(document))).toEqual(document);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("round-trips authored model-instance collision settings", () => {
|
||||||
|
const asset = {
|
||||||
|
id: "asset-model-collider",
|
||||||
|
kind: "model",
|
||||||
|
sourceName: "collision-test.glb",
|
||||||
|
mimeType: "model/gltf-binary",
|
||||||
|
storageKey: createProjectAssetStorageKey("asset-model-collider"),
|
||||||
|
byteLength: 64,
|
||||||
|
metadata: {
|
||||||
|
kind: "model",
|
||||||
|
format: "glb",
|
||||||
|
sceneName: "Collision Test Scene",
|
||||||
|
nodeCount: 1,
|
||||||
|
meshCount: 1,
|
||||||
|
materialNames: [],
|
||||||
|
textureNames: [],
|
||||||
|
animationNames: [],
|
||||||
|
boundingBox: {
|
||||||
|
min: {
|
||||||
|
x: -1,
|
||||||
|
y: 0,
|
||||||
|
z: -1
|
||||||
|
},
|
||||||
|
max: {
|
||||||
|
x: 1,
|
||||||
|
y: 2,
|
||||||
|
z: 1
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
x: 2,
|
||||||
|
y: 2,
|
||||||
|
z: 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
warnings: []
|
||||||
|
}
|
||||||
|
} satisfies ModelAssetRecord;
|
||||||
|
const modelInstance = createModelInstance({
|
||||||
|
id: "model-instance-collider",
|
||||||
|
assetId: asset.id,
|
||||||
|
collision: {
|
||||||
|
mode: "dynamic",
|
||||||
|
visible: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const document = {
|
||||||
|
...createEmptySceneDocument({ name: "Model Collision Scene" }),
|
||||||
|
assets: {
|
||||||
|
[asset.id]: asset
|
||||||
|
},
|
||||||
|
modelInstances: {
|
||||||
|
[modelInstance.id]: modelInstance
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(parseSceneDocumentJson(serializeSceneDocument(document))).toEqual(document);
|
||||||
|
});
|
||||||
|
|
||||||
it("round-trips canonical interaction links", () => {
|
it("round-trips canonical interaction links", () => {
|
||||||
const triggerVolume = createTriggerVolumeEntity({
|
const triggerVolume = createTriggerVolumeEntity({
|
||||||
id: "entity-trigger-main"
|
id: "entity-trigger-main"
|
||||||
|
|||||||
Reference in New Issue
Block a user