diff --git a/TODO b/TODO new file mode 100644 index 0000000..8dddc4d --- /dev/null +++ b/TODO @@ -0,0 +1,4 @@ +portals to other scenes +collision events +touch events/interactions +motion with xr without a controller diff --git a/protocols/schemas/shapes.prs b/protocols/schemas/shapes.prs index feb296d..800fbad 100644 --- a/protocols/schemas/shapes.prs +++ b/protocols/schemas/shapes.prs @@ -2,7 +2,9 @@ version 1 . Sprite = . -Shape = Sphere / Box / Light / Ground / Scale / Move / Rotate / @many [Shape ...] / Texture / Color / Name / Floor / Nonphysical . +Shape = Mesh / Light / Scale / Move / Rotate / @many [Shape ...] / Texture / Color / Name / Floor / Nonphysical / CSG . + +Mesh = Sphere / Box / Ground . Sphere = . Box = . @@ -33,3 +35,13 @@ Name = . Floor = . Nonphysical = . + +CSG = . + +CSGExpr = +/ +/ +/ +/ +/ +. diff --git a/scene/example.pr b/scene/example.pr index 2e8614e..0b3ad50 100644 --- a/scene/example.pr +++ b/scene/example.pr @@ -3,12 +3,12 @@ + - >>>> + >>>> + @@ -17,8 +17,34 @@ >>>>> + >>>> + >>>>> + + + + > + > + > + ]>>>>> + + + + >>>>> + + + + + >>>>> [] diff --git a/src/engine.ts b/src/engine.ts index 60e01f9..809638e 100644 --- a/src/engine.ts +++ b/src/engine.ts @@ -83,6 +83,7 @@ export async function startEngine( camera = new FreeCamera("camera", initialPos, scene); camera.minZ = 0.1; camera.rotation = initialRotation; + camera.speed = 0.5; camera.attachControl(canvas, true); } const sm = xrAvailable ? xr.baseExperience.sessionManager : null; diff --git a/src/index.ts b/src/index.ts index cc8535d..1a91702 100644 --- a/src/index.ts +++ b/src/index.ts @@ -77,7 +77,8 @@ function bootApp(ds: Ref, scene: Scene) { field rotation: Shapes.Vector3 = Shapes.Vector3({ x:0, y:0, z:0 }); at ds { - on message timer.PeriodicTick(100) => { + const refreshPeriod = Math.floor(1000 / 30); + on message timer.PeriodicTick(refreshPeriod) => { const camera = scene.cameras[0]; if (camera && camera instanceof TargetCamera) { const newPosition = Shapes.Vector3(camera.position); @@ -107,7 +108,7 @@ function bootApp(ds: Ref, scene: Scene) { v: Shapes.Vector3({ x: 0, y: rotation.value.y, z: 0 }), shape: Shapes.Shape.Scale(Shapes.Scale({ v: Shapes.Vector3({ x: 0.4, y: 1.4, z: 0.1 }), - shape: Shapes.Shape.Box(Shapes.Box()), + shape: Shapes.Shape.Mesh(Shapes.Mesh.Box(Shapes.Box())), })), })), })), @@ -115,7 +116,7 @@ function bootApp(ds: Ref, scene: Scene) { v: rotation.value, shape: Shapes.Shape.Scale(Shapes.Scale({ v: Shapes.Vector3({ x:0.15, y:0.23, z:0.18 }), - shape: Shapes.Shape.Box(Shapes.Box()), + shape: Shapes.Shape.Mesh(Shapes.Mesh.Box(Shapes.Box())), })), })), ]), diff --git a/src/shapes.ts b/src/shapes.ts index 7f41b18..371e1a7 100644 --- a/src/shapes.ts +++ b/src/shapes.ts @@ -1,5 +1,4 @@ import { - AbstractMesh, Color3, CSG, HemisphericLight, @@ -123,16 +122,31 @@ function applyCustomizer(m: ShapeTree, c: MeshCustomizer) { export function build(name: string, scene: Scene, shape: Shapes.Shape, customize: MeshCustomizer): ShapeTree { switch (shape._variant) { - case "Sphere": { - const t = new ShapeTree(scene, shape, MeshBuilder.CreateSphere(name, {}, scene)); - applyCustomizer(t, customize); - return t; - } + case "Mesh": { + const mesh = shape.value; + switch (mesh._variant) { + case "Sphere": { + const t = new ShapeTree(scene, shape, MeshBuilder.CreateSphere(name, {}, scene)); + applyCustomizer(t, customize); + return t; + } - case "Box": { - const t = new ShapeTree(scene, shape, MeshBuilder.CreateBox(name, {}, scene)); - applyCustomizer(t, customize); - return t; + case "Box": { + const t = new ShapeTree(scene, shape, MeshBuilder.CreateBox(name, {}, scene)); + applyCustomizer(t, customize); + return t; + } + + case "Ground": { + const v = v2(mesh.value.size); + const t = new ShapeTree( + scene, + shape, + MeshBuilder.CreateGround(name, { width: v.x, height: v.y }, scene)); + applyCustomizer(t, customize); + return t; + } + } } case "Light": @@ -141,16 +155,6 @@ export function build(name: string, scene: Scene, shape: Shapes.Shape, customize shape, new HemisphericLight(name, v3(shape.value.v), scene)); - case "Ground": { - const v = v2(shape.value.size); - const t = new ShapeTree( - scene, - shape, - MeshBuilder.CreateGround(name, { width: v.x, height: v.y }, scene)); - applyCustomizer(t, customize); - return t; - } - case "Scale": { const t = ShapeTree.transform(name, scene, shape); t.node.scaling = v3(shape.value.v); @@ -246,6 +250,10 @@ export function build(name: string, scene: Scene, shape: Shapes.Shape, customize }, }); + case "CSG": { + throw new Error("unimplemented"); + } + default: ((_shape: never) => { console.error('Unsupported shape variant', shape);