This commit is contained in:
Tony Garnock-Jones 2023-01-05 22:03:35 +01:00
parent dd49f1f4f1
commit 5a34b929d8
6 changed files with 81 additions and 29 deletions

4
TODO Normal file
View File

@ -0,0 +1,4 @@
portals to other scenes
collision events
touch events/interactions
motion with xr without a controller

View File

@ -2,7 +2,9 @@ version 1 .
Sprite = <sprite @name string @shape Shape> .
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 = <sphere> .
Box = <box> .
@ -33,3 +35,13 @@ Name = <name @base string @shape Shape> .
Floor = <floor @shape Shape> .
Nonphysical = <nonphysical @shape Shape> .
CSG = <csg @expr CSGExpr> .
CSGExpr =
/ <mesh @shape Shape>
/ <subtract @base CSGExpr @more [CSGExpr ...]>
/ <union @shapes [CSGExpr ...]>
/ <intersect @shapes [CSGExpr ...]>
/ <invert @shape CSGExpr>
.

View File

@ -3,12 +3,12 @@
<sprite "ground"
<texture
"textures/grass-256x256.jpg"
<v 0.1 0.1>
<v 0.01 0.01>
<v 0.0 0.0>
<floor <ground <v 30.0 30.0>>>>>
<floor <ground <v 300.0 300.0>>>>>
<sprite "box"
<move <v 6.0 2.5 8.0>
<move <v -6.0 1.0 8.0>
<scale <v 10.0 0.1 10.0>
<texture "textures/oak-herringbone-5e80fb40b00c9-1200.jpg"
<v 0.1 0.1>
@ -17,8 +17,34 @@
<floor <box>>>>>>
<sprite "box2"
<move <v -1.0 0.5 3.0>
<move <v -500.0 0.5 3.0>
<floor
<color 1.0 0.0 0.0 0.5 <box>>>>>
<color 0.0 0.0 1.0 1.0
<scale <v 1000.0 1.0 1.0> <box>>>>>>
<sprite "steps"
<color 0.0 0.5 0.0
<move <v 0.0 0.0 3.5>
<scale <v 1.0 1.0 3.0>
<texture "textures/oak-herringbone-5e80fb40b00c9-1200.jpg"
[
<move <v 0.0 0.25 0.0> <box>>
<move <v 1.0 0.0 0.0> <box>>
<move <v 2.0 -0.25 0.0> <box>>
]>>>>>
<sprite "ball"
<move <v 0.0 2.0 3.0>
<scale <v 1.0 3.0 1.0>
<color 1.0 1.0 0.0
<floor
<sphere>>>>>>
<sprite "plans"
<texture "plans/signal-2022-12-27-125451_002.jpeg"
<move <v 0.0 1.0 -10.0>
<rotate <v 0.5 0.0 0.0>
<scale <v 2.0 2.0 0.1>
<box>>>>>>
[]

View File

@ -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;

View File

@ -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())),
})),
})),
]),

View File

@ -1,5 +1,4 @@
import {
AbstractMesh,
Color3,
CSG,
HemisphericLight,
@ -123,16 +122,31 @@ function applyCustomizer(m: ShapeTree<Mesh>, c: MeshCustomizer) {
export function build(name: string, scene: Scene, shape: Shapes.Shape, customize: MeshCustomizer): ShapeTree {
switch (shape._variant) {
case "Sphere": {
const t = new ShapeTree<Mesh>(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<Mesh>(scene, shape, MeshBuilder.CreateSphere(name, {}, scene));
applyCustomizer(t, customize);
return t;
}
case "Box": {
const t = new ShapeTree<Mesh>(scene, shape, MeshBuilder.CreateBox(name, {}, scene));
applyCustomizer(t, customize);
return t;
case "Box": {
const t = new ShapeTree<Mesh>(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);