@opsydyn/effect-three 0.3.0 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -0
- package/README.md +15 -1
- package/dist/{index-8cf8t6by.js → index-re3rrfwd.js} +2935 -104
- package/dist/index-re3rrfwd.js.map +56 -0
- package/dist/index-ttwy0znv.js +145 -0
- package/dist/index-ttwy0znv.js.map +12 -0
- package/dist/index.js +557 -147
- package/dist/index.js.map +8 -6
- package/dist/kernel/bodies.d.ts +20 -1
- package/dist/kernel/bodies.d.ts.map +1 -1
- package/dist/kernel/boxSelect.d.ts +22 -0
- package/dist/kernel/boxSelect.d.ts.map +1 -0
- package/dist/kernel/build.d.ts +165 -7
- package/dist/kernel/build.d.ts.map +1 -1
- package/dist/kernel/cameraShake.d.ts.map +1 -1
- package/dist/kernel/describeScene.d.ts +50 -0
- package/dist/kernel/describeScene.d.ts.map +1 -0
- package/dist/kernel/description.d.ts +223 -1
- package/dist/kernel/description.d.ts.map +1 -1
- package/dist/kernel/diff.d.ts +15 -0
- package/dist/kernel/diff.d.ts.map +1 -1
- package/dist/kernel/equality.d.ts +11 -1
- package/dist/kernel/equality.d.ts.map +1 -1
- package/dist/kernel/gizmo.d.ts +69 -0
- package/dist/kernel/gizmo.d.ts.map +1 -0
- package/dist/kernel/history.d.ts +61 -0
- package/dist/kernel/history.d.ts.map +1 -0
- package/dist/kernel/index.d.ts +19 -6
- package/dist/kernel/index.d.ts.map +1 -1
- package/dist/kernel/index.js +124 -3
- package/dist/kernel/index.js.map +1 -1
- package/dist/kernel/inspect.d.ts +85 -0
- package/dist/kernel/inspect.d.ts.map +1 -0
- package/dist/kernel/lineGeometry.d.ts +25 -0
- package/dist/kernel/lineGeometry.d.ts.map +1 -0
- package/dist/kernel/lockstep.d.ts +114 -0
- package/dist/kernel/lockstep.d.ts.map +1 -0
- package/dist/kernel/loop.d.ts.map +1 -1
- package/dist/kernel/materials.d.ts.map +1 -1
- package/dist/kernel/paintOrder.d.ts +53 -0
- package/dist/kernel/paintOrder.d.ts.map +1 -0
- package/dist/kernel/physics.d.ts +39 -0
- package/dist/kernel/physics.d.ts.map +1 -1
- package/dist/kernel/pivot.d.ts +54 -0
- package/dist/kernel/pivot.d.ts.map +1 -0
- package/dist/kernel/pointBuffers.d.ts +17 -0
- package/dist/kernel/pointBuffers.d.ts.map +1 -0
- package/dist/kernel/pointer.d.ts +31 -1
- package/dist/kernel/pointer.d.ts.map +1 -1
- package/dist/kernel/preview.d.ts +32 -0
- package/dist/kernel/preview.d.ts.map +1 -0
- package/dist/kernel/renderKit.d.ts +21 -1
- package/dist/kernel/renderKit.d.ts.map +1 -1
- package/dist/kernel/renderer.d.ts +6 -0
- package/dist/kernel/renderer.d.ts.map +1 -1
- package/dist/kernel/sceneChanges.d.ts +87 -0
- package/dist/kernel/sceneChanges.d.ts.map +1 -0
- package/dist/kernel/sceneGraph.d.ts +9 -1
- package/dist/kernel/sceneGraph.d.ts.map +1 -1
- package/dist/kernel/sceneIndex.d.ts +5 -0
- package/dist/kernel/sceneIndex.d.ts.map +1 -1
- package/dist/kernel/seeded.d.ts +9 -0
- package/dist/kernel/seeded.d.ts.map +1 -0
- package/dist/kernel/shots.d.ts +26 -0
- package/dist/kernel/shots.d.ts.map +1 -0
- package/dist/kernel/tape.d.ts +38 -0
- package/dist/kernel/tape.d.ts.map +1 -0
- package/dist/kernel/timeline.d.ts +60 -0
- package/dist/kernel/timeline.d.ts.map +1 -0
- package/dist/kernel/trail.d.ts +31 -0
- package/dist/kernel/trail.d.ts.map +1 -0
- package/dist/kernel/viewportGizmo.d.ts +25 -0
- package/dist/kernel/viewportGizmo.d.ts.map +1 -0
- package/dist/runtime/Inspector.d.ts +20 -0
- package/dist/runtime/Inspector.d.ts.map +1 -0
- package/dist/runtime/SceneFile.d.ts +462 -0
- package/dist/runtime/SceneFile.d.ts.map +1 -0
- package/dist/runtime/SceneSchema.d.ts +404 -0
- package/dist/runtime/SceneSchema.d.ts.map +1 -1
- package/dist/runtime/errors.d.ts +9 -0
- package/dist/runtime/errors.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +3 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/webgl/index.d.ts.map +1 -1
- package/dist/webgl/index.js +228 -3
- package/dist/webgl/index.js.map +6 -4
- package/dist/webgl/line.d.ts +4 -0
- package/dist/webgl/line.d.ts.map +1 -0
- package/dist/webgl/points.d.ts +4 -0
- package/dist/webgl/points.d.ts.map +1 -0
- package/dist/webgpu/index.d.ts.map +1 -1
- package/dist/webgpu/index.js +206 -26
- package/dist/webgpu/index.js.map +6 -4
- package/dist/webgpu/line.d.ts +4 -0
- package/dist/webgpu/line.d.ts.map +1 -0
- package/dist/webgpu/points.d.ts +4 -0
- package/dist/webgpu/points.d.ts.map +1 -0
- package/package.json +4 -2
- package/src/kernel/bodies.ts +299 -17
- package/src/kernel/boxSelect.ts +73 -0
- package/src/kernel/build.ts +374 -1
- package/src/kernel/cameraShake.ts +3 -13
- package/src/kernel/describeScene.ts +224 -0
- package/src/kernel/description.ts +243 -0
- package/src/kernel/diff.ts +39 -0
- package/src/kernel/equality.ts +123 -0
- package/src/kernel/gizmo.ts +478 -0
- package/src/kernel/history.ts +118 -0
- package/src/kernel/index.ts +110 -1
- package/src/kernel/inspect.ts +214 -0
- package/src/kernel/lineGeometry.ts +75 -0
- package/src/kernel/lockstep.ts +237 -0
- package/src/kernel/loop.ts +7 -0
- package/src/kernel/materials.ts +3 -0
- package/src/kernel/paintOrder.ts +274 -0
- package/src/kernel/physics.ts +86 -1
- package/src/kernel/pivot.ts +418 -0
- package/src/kernel/pointBuffers.ts +115 -0
- package/src/kernel/pointer.ts +98 -17
- package/src/kernel/preview.ts +467 -0
- package/src/kernel/renderKit.ts +23 -1
- package/src/kernel/renderer.ts +6 -0
- package/src/kernel/sceneChanges.ts +265 -0
- package/src/kernel/sceneGraph.ts +354 -11
- package/src/kernel/sceneIndex.ts +8 -0
- package/src/kernel/seeded.ts +18 -0
- package/src/kernel/shots.ts +167 -0
- package/src/kernel/tape.ts +124 -0
- package/src/kernel/timeline.ts +93 -0
- package/src/kernel/trail.ts +170 -0
- package/src/kernel/viewportGizmo.ts +194 -0
- package/src/runtime/Inspector.ts +43 -0
- package/src/runtime/SceneFile.ts +46 -0
- package/src/runtime/SceneSchema.ts +319 -0
- package/src/runtime/errors.ts +6 -0
- package/src/runtime/index.ts +3 -1
- package/src/webgl/index.ts +4 -0
- package/src/webgl/line.ts +66 -0
- package/src/webgl/points.ts +205 -0
- package/src/webgpu/index.ts +4 -0
- package/src/webgpu/line.ts +67 -0
- package/src/webgpu/points.ts +193 -0
- package/dist/index-8cf8t6by.js.map +0 -41
|
@@ -202,6 +202,7 @@ export const BasicMaterial = Schema.TaggedStruct('Basic', {
|
|
|
202
202
|
color: Rgb,
|
|
203
203
|
map: TextureId,
|
|
204
204
|
...surface,
|
|
205
|
+
depthTest: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(true))),
|
|
205
206
|
});
|
|
206
207
|
|
|
207
208
|
/** Matte material parameters. */
|
|
@@ -378,6 +379,21 @@ export const JointKind = Schema.Union([
|
|
|
378
379
|
}),
|
|
379
380
|
]);
|
|
380
381
|
|
|
382
|
+
/** A trail behind a moving node (Drei's `Trail`). */
|
|
383
|
+
export const Trail = absentAsNull(
|
|
384
|
+
Schema.Struct({
|
|
385
|
+
width: NonNegative,
|
|
386
|
+
length: NonNegative,
|
|
387
|
+
decay: NonNegative,
|
|
388
|
+
local: Schema.Boolean,
|
|
389
|
+
stride: NonNegative,
|
|
390
|
+
interval: NonNegative,
|
|
391
|
+
color: Rgb,
|
|
392
|
+
taper: Schema.Literals(['none', 'linear', 'quadratic']),
|
|
393
|
+
fade: Schema.Boolean,
|
|
394
|
+
}),
|
|
395
|
+
);
|
|
396
|
+
|
|
381
397
|
/** A joint between two bodies. */
|
|
382
398
|
export const Joint = Schema.Struct({
|
|
383
399
|
key: Schema.String,
|
|
@@ -389,11 +405,19 @@ export const Joint = Schema.Struct({
|
|
|
389
405
|
contacts: Schema.Boolean,
|
|
390
406
|
});
|
|
391
407
|
|
|
408
|
+
/** A count of physics steps. */
|
|
409
|
+
const StepCount = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
|
|
410
|
+
|
|
392
411
|
export const Physics = Schema.Struct({
|
|
393
412
|
gravity: Vec3,
|
|
394
413
|
paused: Schema.Boolean,
|
|
395
414
|
timeStep: Positive,
|
|
396
415
|
interpolate: Schema.Boolean,
|
|
416
|
+
until: absentAsNull(StepCount),
|
|
417
|
+
run: Schema.Int.pipe(Schema.withDecodingDefaultKey(Effect.succeed(0))),
|
|
418
|
+
snapshotAt: absentAsNull(StepCount),
|
|
419
|
+
from: absentAsNull(Schema.Struct({ step: StepCount, snapshot: Schema.NullOr(Schema.String) })),
|
|
420
|
+
keep: StepCount.pipe(Schema.withDecodingDefaultKey(Effect.succeed(0))),
|
|
397
421
|
debug: Schema.Boolean,
|
|
398
422
|
joints: Schema.Array(Joint),
|
|
399
423
|
});
|
|
@@ -411,6 +435,20 @@ export const MeshNode = Schema.TaggedStruct('Mesh', {
|
|
|
411
435
|
castShadow: Schema.Boolean,
|
|
412
436
|
receiveShadow: Schema.Boolean,
|
|
413
437
|
body: Schema.NullOr(Body),
|
|
438
|
+
edges: absentAsNull(
|
|
439
|
+
Schema.Struct({
|
|
440
|
+
threshold: NonNegative,
|
|
441
|
+
color: Rgb,
|
|
442
|
+
width: NonNegative,
|
|
443
|
+
worldUnits: Schema.Boolean,
|
|
444
|
+
dashed: Schema.Boolean,
|
|
445
|
+
dashSize: NonNegative,
|
|
446
|
+
gapSize: NonNegative,
|
|
447
|
+
opacity: NonNegative,
|
|
448
|
+
transparent: Schema.Boolean,
|
|
449
|
+
}),
|
|
450
|
+
),
|
|
451
|
+
trail: Trail,
|
|
414
452
|
});
|
|
415
453
|
|
|
416
454
|
/** One instance of an instances node. */
|
|
@@ -593,6 +631,76 @@ export const HemisphereLightNode = Schema.TaggedStruct('HemisphereLight', {
|
|
|
593
631
|
position: Vec3,
|
|
594
632
|
});
|
|
595
633
|
|
|
634
|
+
/** What points look like: dots, Drei's sparkles, or its stars. */
|
|
635
|
+
export const PointLook = Schema.Union([
|
|
636
|
+
Schema.TaggedStruct('Dots', {
|
|
637
|
+
positions: Schema.Array(Vec3),
|
|
638
|
+
colors: Schema.NullOr(Schema.Array(Rgb)),
|
|
639
|
+
sizes: Schema.NullOr(Schema.Array(NonNegative)),
|
|
640
|
+
color: Rgb,
|
|
641
|
+
size: NonNegative,
|
|
642
|
+
sizeAttenuation: Schema.Boolean,
|
|
643
|
+
round: Schema.Boolean,
|
|
644
|
+
opacity: NonNegative,
|
|
645
|
+
transparent: Schema.Boolean,
|
|
646
|
+
}),
|
|
647
|
+
Schema.TaggedStruct('Sparkles', {
|
|
648
|
+
count: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
649
|
+
speed: Schema.Finite,
|
|
650
|
+
opacity: NonNegative,
|
|
651
|
+
scale: Vec3,
|
|
652
|
+
size: Schema.NullOr(NonNegative),
|
|
653
|
+
color: Rgb,
|
|
654
|
+
noise: Vec3,
|
|
655
|
+
seed: Schema.Finite,
|
|
656
|
+
}),
|
|
657
|
+
Schema.TaggedStruct('Stars', {
|
|
658
|
+
radius: NonNegative,
|
|
659
|
+
depth: NonNegative,
|
|
660
|
+
count: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
661
|
+
factor: NonNegative,
|
|
662
|
+
saturation: NonNegative,
|
|
663
|
+
fade: Schema.Boolean,
|
|
664
|
+
speed: Schema.Finite,
|
|
665
|
+
seed: Schema.Finite,
|
|
666
|
+
}),
|
|
667
|
+
]);
|
|
668
|
+
|
|
669
|
+
/** Points (Drei's `Points`, `Sparkles` or `Stars`), drawn by the render kit. */
|
|
670
|
+
export const PointsNode = Schema.TaggedStruct('Points', {
|
|
671
|
+
key: Schema.String,
|
|
672
|
+
position: Vec3,
|
|
673
|
+
rotation: Rotation,
|
|
674
|
+
scale: Vec3,
|
|
675
|
+
transition: Transition,
|
|
676
|
+
behaviour: Schema.NullOr(Behave),
|
|
677
|
+
look: PointLook,
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
/** A line through points (Drei's `Line`), drawn by the render kit. */
|
|
681
|
+
export const LineNode = Schema.TaggedStruct('Line', {
|
|
682
|
+
key: Schema.String,
|
|
683
|
+
position: Vec3,
|
|
684
|
+
rotation: Rotation,
|
|
685
|
+
scale: Vec3,
|
|
686
|
+
transition: Transition,
|
|
687
|
+
behaviour: Schema.NullOr(Behave),
|
|
688
|
+
interactive: Schema.Boolean,
|
|
689
|
+
points: Schema.Array(Vec3),
|
|
690
|
+
segments: Schema.Boolean,
|
|
691
|
+
color: Rgb,
|
|
692
|
+
vertexColors: Schema.NullOr(Schema.Array(Rgb)),
|
|
693
|
+
width: NonNegative,
|
|
694
|
+
worldUnits: Schema.Boolean,
|
|
695
|
+
dashed: Schema.Boolean,
|
|
696
|
+
dashSize: NonNegative,
|
|
697
|
+
gapSize: NonNegative,
|
|
698
|
+
dashScale: NonNegative,
|
|
699
|
+
dashOffset: Schema.Finite,
|
|
700
|
+
opacity: NonNegative,
|
|
701
|
+
transparent: Schema.Boolean,
|
|
702
|
+
});
|
|
703
|
+
|
|
596
704
|
/** Any scene node. Groups nest recursively. */
|
|
597
705
|
export const SceneNode: Schema.Codec<KernelSceneNode, unknown> = Schema.Union([
|
|
598
706
|
Schema.TaggedStruct('Group', {
|
|
@@ -609,11 +717,14 @@ export const SceneNode: Schema.Codec<KernelSceneNode, unknown> = Schema.Union([
|
|
|
609
717
|
detail: absentAsNull(
|
|
610
718
|
Schema.Struct({ distances: Schema.Array(NonNegative), hysteresis: NonNegative }),
|
|
611
719
|
),
|
|
720
|
+
trail: Trail,
|
|
612
721
|
}),
|
|
613
722
|
MeshNode,
|
|
614
723
|
InstancesNode,
|
|
615
724
|
BorrowedNode,
|
|
616
725
|
LabelNode,
|
|
726
|
+
LineNode,
|
|
727
|
+
PointsNode,
|
|
617
728
|
ShaderGridNode,
|
|
618
729
|
AmbientLightNode,
|
|
619
730
|
DirectionalLightNode,
|
|
@@ -715,6 +826,26 @@ export const RenderTexture = Schema.Struct({
|
|
|
715
826
|
children: Schema.Array(SceneNode),
|
|
716
827
|
});
|
|
717
828
|
|
|
829
|
+
/** Where a HUD's origin sits on the canvas. */
|
|
830
|
+
export const HudAlignment = Schema.Literals([
|
|
831
|
+
'top-left',
|
|
832
|
+
'top-center',
|
|
833
|
+
'top-right',
|
|
834
|
+
'center-left',
|
|
835
|
+
'center-center',
|
|
836
|
+
'center-right',
|
|
837
|
+
'bottom-left',
|
|
838
|
+
'bottom-center',
|
|
839
|
+
'bottom-right',
|
|
840
|
+
]);
|
|
841
|
+
|
|
842
|
+
/** Nodes drawn over the scene, with their own camera in CSS pixels. */
|
|
843
|
+
export const Hud = Schema.Struct({
|
|
844
|
+
alignment: HudAlignment,
|
|
845
|
+
margin: Schema.Tuple([Schema.Finite, Schema.Finite]),
|
|
846
|
+
children: Schema.Array(SceneNode),
|
|
847
|
+
});
|
|
848
|
+
|
|
718
849
|
/** A complete scene description. */
|
|
719
850
|
/** A point to show HTML at. */
|
|
720
851
|
export const Overlay = Schema.Struct({
|
|
@@ -789,11 +920,23 @@ export const Xr = Schema.Struct({
|
|
|
789
920
|
/** Whether the scene claims the pointer's gestures from the page. */
|
|
790
921
|
export const Gestures = Schema.Literals(['page', 'scene']);
|
|
791
922
|
|
|
923
|
+
/** What an asset is: a glTF or GLB model, a colour texture, an HDR panorama, a typeface font. */
|
|
924
|
+
export const AssetKind = Schema.Literals(['model', 'texture', 'environment', 'font']);
|
|
925
|
+
|
|
926
|
+
/** An asset a scene asks for (`modelAsset` and the rest). */
|
|
927
|
+
export const Asset = Schema.Struct({
|
|
928
|
+
kind: AssetKind,
|
|
929
|
+
id: Schema.String,
|
|
930
|
+
url: Schema.String,
|
|
931
|
+
levels: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
932
|
+
});
|
|
933
|
+
|
|
792
934
|
export const SceneDescription = Schema.Struct({
|
|
793
935
|
camera: Camera,
|
|
794
936
|
gestures: Gestures,
|
|
795
937
|
views: Schema.Array(View),
|
|
796
938
|
renderTextures: Schema.Array(RenderTexture),
|
|
939
|
+
hud: absentAsNull(Hud),
|
|
797
940
|
overlays: Schema.Array(Overlay),
|
|
798
941
|
environment: Schema.NullOr(Environment),
|
|
799
942
|
sky: Schema.NullOr(Sky),
|
|
@@ -801,11 +944,42 @@ export const SceneDescription = Schema.Struct({
|
|
|
801
944
|
physics: Schema.NullOr(Physics),
|
|
802
945
|
xr: Schema.NullOr(Xr),
|
|
803
946
|
measure: Schema.Array(Schema.String),
|
|
947
|
+
assets: Schema.Array(Asset).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
804
948
|
render: RenderSettings,
|
|
805
949
|
resources: ResourceDefinitions,
|
|
806
950
|
children: Schema.Array(SceneNode),
|
|
807
951
|
});
|
|
808
952
|
|
|
953
|
+
/**
|
|
954
|
+
* Detail of asset loaded events: the asset, the level of detail now shown (0 for the
|
|
955
|
+
* coarsest of its `levels`, as many as it has levels for `url` itself) and whether that is
|
|
956
|
+
* the finest, and for a model its parts and clips.
|
|
957
|
+
*/
|
|
958
|
+
export const AssetLoadedDetail = Schema.Struct({
|
|
959
|
+
kind: AssetKind,
|
|
960
|
+
id: Schema.String,
|
|
961
|
+
url: Schema.String,
|
|
962
|
+
levels: Schema.Array(Schema.String),
|
|
963
|
+
level: Schema.Int,
|
|
964
|
+
final: Schema.Boolean,
|
|
965
|
+
/** Names of the objects inside a model, as hits report them in `part`. */
|
|
966
|
+
parts: Schema.Array(Schema.String),
|
|
967
|
+
/** Names of a model's animation clips. */
|
|
968
|
+
clips: Schema.Array(Schema.String),
|
|
969
|
+
});
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* Detail of asset failed events: the asset, and why its finest level could not be loaded
|
|
973
|
+
* (a coarser level shown before stays).
|
|
974
|
+
*/
|
|
975
|
+
export const AssetFailedDetail = Schema.Struct({
|
|
976
|
+
kind: AssetKind,
|
|
977
|
+
id: Schema.String,
|
|
978
|
+
url: Schema.String,
|
|
979
|
+
levels: Schema.Array(Schema.String),
|
|
980
|
+
reason: Schema.String,
|
|
981
|
+
});
|
|
982
|
+
|
|
809
983
|
/** Detail of pointer-leave events: the interactive mesh's key. */
|
|
810
984
|
export const KeyDetail = Schema.Struct({ key: Schema.String });
|
|
811
985
|
|
|
@@ -906,6 +1080,17 @@ export const CollisionDetail = Schema.Struct({
|
|
|
906
1080
|
started: Schema.Boolean,
|
|
907
1081
|
});
|
|
908
1082
|
|
|
1083
|
+
/**
|
|
1084
|
+
* Detail of physics reached events: the run and step a world on `physics({ until })`
|
|
1085
|
+
* reached, a checksum of its bodies' poses there, and at `snapshotAt` a snapshot of it.
|
|
1086
|
+
*/
|
|
1087
|
+
export const PhysicsReachedDetail = Schema.Struct({
|
|
1088
|
+
run: Schema.Int,
|
|
1089
|
+
step: StepCount,
|
|
1090
|
+
checksum: Schema.String,
|
|
1091
|
+
snapshot: Schema.optionalKey(Schema.String),
|
|
1092
|
+
});
|
|
1093
|
+
|
|
909
1094
|
const XrHand = Schema.Literals(['left', 'right', 'none']);
|
|
910
1095
|
|
|
911
1096
|
/** Detail of XR stick events: a thumbstick pushed past halfway, or let back. */
|
|
@@ -986,6 +1171,14 @@ export const AutoRotatedDetail = Schema.Struct({
|
|
|
986
1171
|
/** Detail of gesture events. */
|
|
987
1172
|
export const GestureDetail = Schema.Struct({ gesture: Gesture });
|
|
988
1173
|
|
|
1174
|
+
/** Detail of the end of a gesture that moved: the press's button, modifiers, mesh and view. */
|
|
1175
|
+
export const GestureEndDetail = Schema.Struct({
|
|
1176
|
+
button: Schema.Int,
|
|
1177
|
+
modifiers: Modifiers,
|
|
1178
|
+
key: Schema.optionalKey(Schema.String),
|
|
1179
|
+
view: Schema.optionalKey(Schema.String),
|
|
1180
|
+
});
|
|
1181
|
+
|
|
989
1182
|
/** A pointer interaction with an interactive mesh, or a miss. */
|
|
990
1183
|
export const SceneEvent = Schema.Union([
|
|
991
1184
|
Schema.TaggedStruct('PointerEnter', HitDetail.fields),
|
|
@@ -1001,11 +1194,13 @@ export const SceneEvent = Schema.Union([
|
|
|
1001
1194
|
Schema.TaggedStruct('Drag', DragDetail.fields),
|
|
1002
1195
|
Schema.TaggedStruct('DragEnd', DragDetail.fields),
|
|
1003
1196
|
Schema.TaggedStruct('Gesture', GestureDetail.fields),
|
|
1197
|
+
Schema.TaggedStruct('GestureEnd', GestureEndDetail.fields),
|
|
1004
1198
|
Schema.TaggedStruct('AutoRotated', AutoRotatedDetail.fields),
|
|
1005
1199
|
Schema.TaggedStruct('Collision', CollisionDetail.fields),
|
|
1006
1200
|
Schema.TaggedStruct('Measured', MeasuredDetail.fields),
|
|
1007
1201
|
Schema.TaggedStruct('LabelMeasured', LabelMeasuredDetail.fields),
|
|
1008
1202
|
Schema.TaggedStruct('ContactForce', ContactForceDetail.fields),
|
|
1203
|
+
Schema.TaggedStruct('PhysicsReached', PhysicsReachedDetail.fields),
|
|
1009
1204
|
Schema.TaggedStruct('XrStick', XrStickDetail.fields),
|
|
1010
1205
|
Schema.TaggedStruct('XrButton', XrButtonDetail.fields),
|
|
1011
1206
|
Schema.TaggedStruct('XrSurface', XrSurfaceDetail.fields),
|
|
@@ -1031,7 +1226,131 @@ export const DescriptionError = Schema.Union([
|
|
|
1031
1226
|
Schema.TaggedStruct('UnknownOverlayNode', { key: Schema.String, node: Schema.String }),
|
|
1032
1227
|
Schema.TaggedStruct('UnknownOverlayView', { key: Schema.String, view: Schema.String }),
|
|
1033
1228
|
Schema.TaggedStruct('UnknownMeasuredNode', { key: Schema.String }),
|
|
1229
|
+
Schema.TaggedStruct('DuplicateAssetId', { id: Schema.String }),
|
|
1034
1230
|
Schema.TaggedStruct('DuplicateJointKey', { key: Schema.String }),
|
|
1035
1231
|
Schema.TaggedStruct('UnknownJointBody', { joint: Schema.String, body: Schema.String }),
|
|
1036
1232
|
Schema.TaggedStruct('DuplicateRenderTextureId', { id: Schema.String }),
|
|
1037
1233
|
]);
|
|
1234
|
+
|
|
1235
|
+
/** Where an object is, for a transform gizmo: position, Euler angles and scale. */
|
|
1236
|
+
export const Placement = Schema.Struct({ position: Vec3, rotation: Vec3, scale: Vec3 });
|
|
1237
|
+
|
|
1238
|
+
const GizmoHandle = Schema.Literals(['x', 'y', 'z', 'xy', 'yz', 'xz', 'xyz']);
|
|
1239
|
+
|
|
1240
|
+
/** A transform gizmo's state, for keeping in a Model. */
|
|
1241
|
+
export const Gizmo = Schema.Struct({
|
|
1242
|
+
mode: Schema.Literals(['translate', 'rotate', 'scale']),
|
|
1243
|
+
space: Schema.Literals(['world', 'local']),
|
|
1244
|
+
size: Positive,
|
|
1245
|
+
translationSnap: Schema.NullOr(Positive),
|
|
1246
|
+
rotationSnap: Schema.NullOr(Positive),
|
|
1247
|
+
scaleSnap: Schema.NullOr(Positive),
|
|
1248
|
+
showX: Schema.Boolean,
|
|
1249
|
+
showY: Schema.Boolean,
|
|
1250
|
+
showZ: Schema.Boolean,
|
|
1251
|
+
hovered: Schema.NullOr(GizmoHandle),
|
|
1252
|
+
grab: Schema.NullOr(
|
|
1253
|
+
Schema.Struct({
|
|
1254
|
+
handle: GizmoHandle,
|
|
1255
|
+
start: Placement,
|
|
1256
|
+
from: Vec3,
|
|
1257
|
+
plane: Schema.Struct({ normal: Vec3, constant: Schema.Finite }),
|
|
1258
|
+
eye: Vec3,
|
|
1259
|
+
distance: Schema.Finite,
|
|
1260
|
+
}),
|
|
1261
|
+
),
|
|
1262
|
+
});
|
|
1263
|
+
|
|
1264
|
+
/** A branching history of `value`s (`History.make`), for a Model that keeps one. */
|
|
1265
|
+
export const History = <S extends Schema.Top>(value: S) =>
|
|
1266
|
+
Schema.Struct({
|
|
1267
|
+
entries: Schema.Array(
|
|
1268
|
+
Schema.Struct({
|
|
1269
|
+
id: Schema.Int,
|
|
1270
|
+
parent: Schema.NullOr(Schema.Int),
|
|
1271
|
+
label: Schema.String,
|
|
1272
|
+
value,
|
|
1273
|
+
next: Schema.NullOr(Schema.Int),
|
|
1274
|
+
}),
|
|
1275
|
+
),
|
|
1276
|
+
current: Schema.Int,
|
|
1277
|
+
});
|
|
1278
|
+
|
|
1279
|
+
/** A lockstep entry: an app's input, or the leader admitting a peer. */
|
|
1280
|
+
const LockstepEntry = <S extends Schema.Top>(input: S) =>
|
|
1281
|
+
Schema.Union([
|
|
1282
|
+
Schema.TaggedStruct('Input', { input }),
|
|
1283
|
+
Schema.TaggedStruct('Admit', { peer: Schema.String }),
|
|
1284
|
+
]);
|
|
1285
|
+
|
|
1286
|
+
/** One peer's lockstep packet for one turn, carrying the app's `input`s. */
|
|
1287
|
+
export const LockstepPacket = <S extends Schema.Top>(input: S) =>
|
|
1288
|
+
Schema.Struct({
|
|
1289
|
+
peer: Schema.String,
|
|
1290
|
+
turn: Schema.Int,
|
|
1291
|
+
entries: Schema.Array(LockstepEntry(input)),
|
|
1292
|
+
});
|
|
1293
|
+
|
|
1294
|
+
/** A lockstep member: the first turn it sends for, and the turn it stopped before. */
|
|
1295
|
+
export const LockstepMember = Schema.Struct({
|
|
1296
|
+
peer: Schema.String,
|
|
1297
|
+
from: Schema.Int,
|
|
1298
|
+
until: Schema.NullOr(Schema.Int),
|
|
1299
|
+
});
|
|
1300
|
+
|
|
1301
|
+
/** A lockstep session (`Lockstep.make`) over the app's `input`s, for a Model. */
|
|
1302
|
+
export const Lockstep = <S extends Schema.Top>(input: S) =>
|
|
1303
|
+
Schema.Struct({
|
|
1304
|
+
self: Schema.String,
|
|
1305
|
+
members: Schema.Array(LockstepMember),
|
|
1306
|
+
turn: Schema.Int,
|
|
1307
|
+
sent: Schema.Int,
|
|
1308
|
+
lead: Schema.Int,
|
|
1309
|
+
pending: Schema.Array(LockstepEntry(input)),
|
|
1310
|
+
received: Schema.Array(LockstepPacket(input)),
|
|
1311
|
+
});
|
|
1312
|
+
|
|
1313
|
+
/** A timeline of physics steps (`Timeline.make`) over the app's `input`s, for a Model. */
|
|
1314
|
+
export const Timeline = <S extends Schema.Top>(input: S) =>
|
|
1315
|
+
Schema.Struct({
|
|
1316
|
+
inputs: Schema.Array(Schema.Struct({ step: StepCount, input })),
|
|
1317
|
+
applied: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
1318
|
+
reached: Schema.NullOr(StepCount),
|
|
1319
|
+
frontier: StepCount,
|
|
1320
|
+
});
|
|
1321
|
+
|
|
1322
|
+
/** A measuring tape as data (`tape`), for a Model that keeps it. */
|
|
1323
|
+
export const Tape = Schema.Struct({
|
|
1324
|
+
from: Schema.NullOr(Vec3),
|
|
1325
|
+
to: Schema.NullOr(Vec3),
|
|
1326
|
+
pointer: Schema.NullOr(Vec3),
|
|
1327
|
+
snap: Schema.NullOr(Positive),
|
|
1328
|
+
});
|
|
1329
|
+
|
|
1330
|
+
/** A pivot handle: what it does, and its axis. */
|
|
1331
|
+
export const PivotHandle = Schema.Literals(
|
|
1332
|
+
(['arrow', 'slider', 'rotator', 'sphere'] as const).flatMap((kind) =>
|
|
1333
|
+
(['x', 'y', 'z'] as const).map((axis) => `${kind}-${axis}` as const),
|
|
1334
|
+
),
|
|
1335
|
+
);
|
|
1336
|
+
|
|
1337
|
+
/** Pivot controls as data (`pivot`), for a Model that keeps them. */
|
|
1338
|
+
export const Pivot = Schema.Struct({
|
|
1339
|
+
scale: Positive,
|
|
1340
|
+
depthTest: Schema.Boolean,
|
|
1341
|
+
disableAxes: Schema.Boolean,
|
|
1342
|
+
disableSliders: Schema.Boolean,
|
|
1343
|
+
disableRotations: Schema.Boolean,
|
|
1344
|
+
disableScaling: Schema.Boolean,
|
|
1345
|
+
hovered: Schema.NullOr(PivotHandle),
|
|
1346
|
+
grab: Schema.NullOr(
|
|
1347
|
+
Schema.Struct({
|
|
1348
|
+
handle: PivotHandle,
|
|
1349
|
+
start: Placement,
|
|
1350
|
+
point: Vec3,
|
|
1351
|
+
e1: Vec3,
|
|
1352
|
+
e2: Vec3,
|
|
1353
|
+
normal: Vec3,
|
|
1354
|
+
}),
|
|
1355
|
+
),
|
|
1356
|
+
});
|
package/src/runtime/errors.ts
CHANGED
|
@@ -12,6 +12,12 @@ export class InvalidScene extends Data.TaggedError('InvalidScene')<{
|
|
|
12
12
|
readonly error: DescriptionError;
|
|
13
13
|
}> {}
|
|
14
14
|
|
|
15
|
+
/** A scene file could not be read: not JSON, not a scene file, or not a scene. */
|
|
16
|
+
export class UnreadableScene extends Data.TaggedError('UnreadableScene')<{
|
|
17
|
+
/** Where and why, as the schema reports it. */
|
|
18
|
+
readonly issue: string;
|
|
19
|
+
}> {}
|
|
20
|
+
|
|
15
21
|
/** The renderer backend could not be created (for example, no WebGL2 context). */
|
|
16
22
|
export class RendererUnavailable extends Data.TaggedError('RendererUnavailable')<{
|
|
17
23
|
readonly cause: unknown;
|
package/src/runtime/index.ts
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
export { InvalidScene, RendererUnavailable } from './errors.ts';
|
|
6
|
+
export { InvalidScene, RendererUnavailable, UnreadableScene } from './errors.ts';
|
|
7
7
|
export * as FrameSource from './FrameSource.ts';
|
|
8
|
+
export * as Inspector from './Inspector.ts';
|
|
8
9
|
export * as ResourceRegistry from './ResourceRegistry.ts';
|
|
10
|
+
export * as SceneFile from './SceneFile.ts';
|
|
9
11
|
export * as SceneRuntime from './SceneRuntime.ts';
|
|
10
12
|
export * as SceneSchema from './SceneSchema.ts';
|
package/src/webgl/index.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { RenderKit } from '../kernel/renderKit.ts';
|
|
10
10
|
import { createContactShadows } from './contactShadows.ts';
|
|
11
|
+
import { hostLine } from './line.ts';
|
|
12
|
+
import { hostPoints } from './points.ts';
|
|
11
13
|
import { hostShaderGrid } from './shaderGrid.ts';
|
|
12
14
|
import { hostSky } from './sky.ts';
|
|
13
15
|
|
|
@@ -15,5 +17,7 @@ export const webglKit: RenderKit = {
|
|
|
15
17
|
shading: 'webgl',
|
|
16
18
|
sky: hostSky,
|
|
17
19
|
shaderGrid: hostShaderGrid,
|
|
20
|
+
line: hostLine,
|
|
21
|
+
points: hostPoints,
|
|
18
22
|
contactShadows: createContactShadows,
|
|
19
23
|
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The WebGL kit's lines: three's fat lines (`Line2`, `LineSegments2` and `LineMaterial`,
|
|
3
|
+
* which Drei's `Line` takes from three-stdlib), which size themselves to the viewport
|
|
4
|
+
* before each draw.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import { Group } from 'three';
|
|
9
|
+
import { Line2 } from 'three/addons/lines/Line2.js';
|
|
10
|
+
import { LineGeometry } from 'three/addons/lines/LineGeometry.js';
|
|
11
|
+
import { LineMaterial } from 'three/addons/lines/LineMaterial.js';
|
|
12
|
+
import { LineSegments2 } from 'three/addons/lines/LineSegments2.js';
|
|
13
|
+
import { LineSegmentsGeometry } from 'three/addons/lines/LineSegmentsGeometry.js';
|
|
14
|
+
|
|
15
|
+
import type { LineNode } from '../kernel/description.ts';
|
|
16
|
+
import { drawable, fillLineGeometry } from '../kernel/lineGeometry.ts';
|
|
17
|
+
import type { HostedLine } from '../kernel/renderKit.ts';
|
|
18
|
+
|
|
19
|
+
/** The material's look from the description; vertex colours want white, as Drei sets. */
|
|
20
|
+
const style = (material: LineMaterial, line: LineNode): void => {
|
|
21
|
+
material.color.setHex(line.vertexColors === null ? line.color : 0xffffff);
|
|
22
|
+
if (material.vertexColors !== (line.vertexColors !== null)) {
|
|
23
|
+
material.vertexColors = line.vertexColors !== null;
|
|
24
|
+
material.needsUpdate = true;
|
|
25
|
+
}
|
|
26
|
+
material.linewidth = line.width;
|
|
27
|
+
material.worldUnits = line.worldUnits;
|
|
28
|
+
material.dashed = line.dashed;
|
|
29
|
+
material.dashSize = line.dashSize;
|
|
30
|
+
material.gapSize = line.gapSize;
|
|
31
|
+
material.dashScale = line.dashScale;
|
|
32
|
+
material.dashOffset = line.dashOffset;
|
|
33
|
+
material.opacity = line.opacity;
|
|
34
|
+
material.transparent = line.transparent;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const draw = (line: LineNode, material: LineMaterial): LineSegments2 => {
|
|
38
|
+
const drawn = line.segments
|
|
39
|
+
? new LineSegments2(fillLineGeometry(new LineSegmentsGeometry(), line), material)
|
|
40
|
+
: new Line2(fillLineGeometry(new LineGeometry(), line), material);
|
|
41
|
+
drawn.computeLineDistances();
|
|
42
|
+
drawn.visible = drawable(line);
|
|
43
|
+
return drawn;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const hostLine = (first: LineNode): HostedLine => {
|
|
47
|
+
const object = new Group();
|
|
48
|
+
const material = new LineMaterial();
|
|
49
|
+
style(material, first);
|
|
50
|
+
let drawn = draw(first, material);
|
|
51
|
+
object.add(drawn);
|
|
52
|
+
return {
|
|
53
|
+
object,
|
|
54
|
+
update: (next) => {
|
|
55
|
+
style(material, next);
|
|
56
|
+
drawn.removeFromParent();
|
|
57
|
+
drawn.geometry.dispose();
|
|
58
|
+
drawn = draw(next, material);
|
|
59
|
+
object.add(drawn);
|
|
60
|
+
},
|
|
61
|
+
dispose: () => {
|
|
62
|
+
drawn.geometry.dispose();
|
|
63
|
+
material.dispose();
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
};
|