Avatars
This commit is contained in:
parent
3d6de0b9c8
commit
472a870b71
|
@ -17,6 +17,7 @@
|
|||
"@babylonjs/core": "5",
|
||||
"@syndicate-lang/core": "*",
|
||||
"@syndicate-lang/html": "*",
|
||||
"@syndicate-lang/timer": "*",
|
||||
"@syndicate-lang/ws-relay": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -2,7 +2,7 @@ version 1 .
|
|||
|
||||
Sprite = <sprite @name string @shape Shape> .
|
||||
|
||||
Shape = Sphere / Box / Light / Ground / Scale / Move / Rotate / @many [Shape ...] / Texture / Color / Name / Floor .
|
||||
Shape = Sphere / Box / Light / Ground / Scale / Move / Rotate / @many [Shape ...] / Texture / Color / Name / Floor / Nonphysical .
|
||||
|
||||
Sphere = <sphere> .
|
||||
Box = <box> .
|
||||
|
@ -30,3 +30,5 @@ Color =
|
|||
Name = <name @base string @shape Shape> .
|
||||
|
||||
Floor = <floor @shape Shape> .
|
||||
|
||||
Nonphysical = <nonphysical @shape Shape> .
|
||||
|
|
75
src/index.ts
75
src/index.ts
|
@ -1,5 +1,6 @@
|
|||
import { Dataspace, Embedded, Reader, Ref, Schemas, Sturdy } from "@syndicate-lang/core";
|
||||
import { is, Dataspace, Embedded, Reader, Ref, Schemas, Sturdy } from "@syndicate-lang/core";
|
||||
import * as html from "@syndicate-lang/html";
|
||||
import * as timer from "@syndicate-lang/timer";
|
||||
import * as wsRelay from "@syndicate-lang/ws-relay";
|
||||
import * as wakeDetector from './wake-detector.js';
|
||||
import * as Shapes from './gen/shapes.js';
|
||||
|
@ -8,19 +9,26 @@ import {
|
|||
Engine,
|
||||
Mesh,
|
||||
Scene,
|
||||
TargetCamera,
|
||||
WebXRCamera,
|
||||
} from '@babylonjs/core/Legacy/legacy';
|
||||
|
||||
import { activeFloorMeshes, ShapeTree } from './shapes.js';
|
||||
import { startEngine, CreatedScene } from './engine.js';
|
||||
import { uuid } from './uuid.js';
|
||||
|
||||
assertion type SceneHandle(ds: Embedded<Ref>);
|
||||
|
||||
function interpretScene(scene: Scene, sceneDs: Ref) {
|
||||
function interpretScene(myId: string, scene: Scene, sceneDs: Ref) {
|
||||
at sceneDs {
|
||||
during Shapes.Sprite({ "name": $name: string }) => spawn named `sprite:${name}` {
|
||||
console.log('+shape', name);
|
||||
on stop console.log('-shape', name);
|
||||
spriteMain(name, scene, sceneDs);
|
||||
if (name === myId) {
|
||||
console.log('ignoring sprite', name);
|
||||
} else {
|
||||
console.log('+shape', name);
|
||||
on stop console.log('-shape', name);
|
||||
spriteMain(name, scene, sceneDs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +38,6 @@ function spriteMain(name: string, scene: Scene, sceneDs: Ref) {
|
|||
let currentShape = ShapeTree.empty(name, scene);
|
||||
on stop currentShape.remove();
|
||||
during Shapes.Sprite({ "name": name, "shape": $shape: Shapes.Shape }) => {
|
||||
console.log('=shape', name, shape);
|
||||
currentShape = currentShape.reconcile(name, shape);
|
||||
}
|
||||
}
|
||||
|
@ -62,8 +69,59 @@ function bootApp(ds: Ref, scene: Scene) {
|
|||
|
||||
at remoteDs {
|
||||
during SceneHandle($sceneDs_e: Embedded) => {
|
||||
const id = uuid();
|
||||
const sceneDs = sceneDs_e.embeddedValue;
|
||||
interpretScene(scene, sceneDs);
|
||||
interpretScene(id, scene, sceneDs);
|
||||
|
||||
field position: Shapes.Vector3 = Shapes.Vector3({ x:0, y:0, z:0 });
|
||||
field rotation: Shapes.Vector3 = Shapes.Vector3({ x:0, y:0, z:0 });
|
||||
|
||||
at ds {
|
||||
on message timer.PeriodicTick(100) => {
|
||||
const camera = scene.cameras[0];
|
||||
if (camera && camera instanceof TargetCamera) {
|
||||
const newPosition = Shapes.Vector3(camera.position);
|
||||
const newRotation = Shapes.Vector3(camera instanceof WebXRCamera
|
||||
? camera.rotationQuaternion.toEulerAngles()
|
||||
: camera.rotation);
|
||||
if (!is(Shapes.fromVector3(position.value), Shapes.fromVector3(newPosition))) {
|
||||
position.value = newPosition;
|
||||
}
|
||||
if (!is(Shapes.fromVector3(rotation.value), Shapes.fromVector3(newRotation))) {
|
||||
rotation.value = newRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
at sceneDs {
|
||||
assert Shapes.Sprite({
|
||||
name: id,
|
||||
shape: Shapes.Shape.Nonphysical(Shapes.Nonphysical(
|
||||
Shapes.Shape.Move(Shapes.Move({
|
||||
v: position.value,
|
||||
shape: Shapes.Shape.many([
|
||||
Shapes.Shape.Move(Shapes.Move({
|
||||
v: Shapes.Vector3({ x: 0, y: -0.9, z: 0}),
|
||||
shape: Shapes.Shape.Rotate(Shapes.Rotate.euler({
|
||||
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()),
|
||||
})),
|
||||
})),
|
||||
})),
|
||||
Shapes.Shape.Rotate(Shapes.Rotate.euler({
|
||||
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()),
|
||||
})),
|
||||
})),
|
||||
]),
|
||||
})))),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +137,8 @@ window.addEventListener('load', async () => {
|
|||
}));
|
||||
Dataspace.boot(ds => {
|
||||
html.boot(ds);
|
||||
wsRelay.boot(ds, true);
|
||||
timer.boot(ds);
|
||||
wsRelay.boot(ds, false);
|
||||
wakeDetector.boot(ds);
|
||||
bootApp(ds, scene);
|
||||
});
|
||||
|
|
|
@ -75,9 +75,6 @@ export class ShapeTree<N extends Node = Node> {
|
|||
public node: N,
|
||||
) {
|
||||
this.shapePreserve = Shapes.fromShape(this.shape);
|
||||
if (this.node instanceof AbstractMesh) {
|
||||
this.node.checkCollisions = true;
|
||||
}
|
||||
}
|
||||
|
||||
reconcile(name: string, shape: Shapes.Shape): ShapeTree {
|
||||
|
@ -85,7 +82,11 @@ export class ShapeTree<N extends Node = Node> {
|
|||
return this;
|
||||
} else {
|
||||
this.remove();
|
||||
return build(name, this.scene, shape, {});
|
||||
return build(name, this.scene, shape, {
|
||||
collisions: m => {
|
||||
m.node.checkCollisions = true;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,6 +235,14 @@ export function build(name: string, scene: Scene, shape: Shapes.Shape, customize
|
|||
},
|
||||
});
|
||||
|
||||
case "Nonphysical":
|
||||
return build(name, scene, shape.value.shape, {
|
||||
... customize,
|
||||
collisions: m => {
|
||||
m.node.checkCollisions = false;
|
||||
},
|
||||
});
|
||||
|
||||
default:
|
||||
((_shape: never) => {
|
||||
console.error('Unsupported shape variant', shape);
|
||||
|
|
|
@ -76,6 +76,13 @@
|
|||
dependencies:
|
||||
"@syndicate-lang/core" "^0.11.8"
|
||||
|
||||
"@syndicate-lang/timer@*":
|
||||
version "0.11.9"
|
||||
resolved "https://registry.yarnpkg.com/@syndicate-lang/timer/-/timer-0.11.9.tgz#16cb30233b7fad6492655a808c5afc5cd48de160"
|
||||
integrity sha512-znEHxRxVdgll0xlCgeZ1WUsw4bFmPBo/V3F4CZwxHyF6iBAqdhW4kSbmo322bGA3s1H0kzrfTQTlD9hQaSIKZQ==
|
||||
dependencies:
|
||||
"@syndicate-lang/core" "^0.11.8"
|
||||
|
||||
"@syndicate-lang/ts-plugin@*":
|
||||
version "0.11.9"
|
||||
resolved "https://registry.yarnpkg.com/@syndicate-lang/ts-plugin/-/ts-plugin-0.11.9.tgz#58d956d55ffc8310199e22f7a9b6056a5cb13a8f"
|
||||
|
|
Loading…
Reference in New Issue