@wardic/three 0.0.0-stage → 1.3.1
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/LICENSE +21 -0
- package/README.md +84 -2
- package/THIRD_PARTY_NOTICES.md +145 -0
- package/dist/TestStage.d.ts +45 -0
- package/dist/TestStage.d.ts.map +1 -0
- package/dist/TestStage.js +140 -0
- package/dist/TestStage.js.map +1 -0
- package/dist/ThreeColours.d.ts +53 -0
- package/dist/ThreeColours.d.ts.map +1 -0
- package/dist/ThreeColours.js +246 -0
- package/dist/ThreeColours.js.map +1 -0
- package/dist/ThreeDrag.d.ts +82 -0
- package/dist/ThreeDrag.d.ts.map +1 -0
- package/dist/ThreeDrag.js +243 -0
- package/dist/ThreeDrag.js.map +1 -0
- package/dist/ThreeInput.d.ts +69 -0
- package/dist/ThreeInput.d.ts.map +1 -0
- package/dist/ThreeInput.js +592 -0
- package/dist/ThreeInput.js.map +1 -0
- package/dist/ThreeInstances.d.ts +47 -0
- package/dist/ThreeInstances.d.ts.map +1 -0
- package/dist/ThreeInstances.js +392 -0
- package/dist/ThreeInstances.js.map +1 -0
- package/dist/ThreeRenderer.d.ts +45 -0
- package/dist/ThreeRenderer.d.ts.map +1 -0
- package/dist/ThreeRenderer.js +121 -0
- package/dist/ThreeRenderer.js.map +1 -0
- package/dist/ThreeValues.d.ts +15 -0
- package/dist/ThreeValues.d.ts.map +1 -0
- package/dist/ThreeValues.js +61 -0
- package/dist/ThreeValues.js.map +1 -0
- package/dist/WardicThree.d.ts +207 -0
- package/dist/WardicThree.d.ts.map +1 -0
- package/dist/WardicThree.js +162 -0
- package/dist/WardicThree.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/dev.d.ts +10 -0
- package/dist/internal/dev.d.ts.map +1 -0
- package/dist/internal/dev.js +11 -0
- package/dist/internal/dev.js.map +1 -0
- package/dist/internal/dev.production.d.ts +8 -0
- package/dist/internal/dev.production.d.ts.map +1 -0
- package/dist/internal/dev.production.js +8 -0
- package/dist/internal/dev.production.js.map +1 -0
- package/dist/internal/lookup.d.ts +29 -0
- package/dist/internal/lookup.d.ts.map +1 -0
- package/dist/internal/lookup.js +245 -0
- package/dist/internal/lookup.js.map +1 -0
- package/dist/internal/shared-material.d.ts +8 -0
- package/dist/internal/shared-material.d.ts.map +1 -0
- package/dist/internal/shared-material.js +95 -0
- package/dist/internal/shared-material.js.map +1 -0
- package/dist/solid/feature.d.ts +42 -0
- package/dist/solid/feature.d.ts.map +1 -0
- package/dist/solid/feature.js +2 -0
- package/dist/solid/feature.js.map +1 -0
- package/dist/solid/scene-batch.d.ts +10 -0
- package/dist/solid/scene-batch.d.ts.map +1 -0
- package/dist/solid/scene-batch.js +436 -0
- package/dist/solid/scene-batch.js.map +1 -0
- package/dist/solid/scene-object.d.ts +27 -0
- package/dist/solid/scene-object.d.ts.map +1 -0
- package/dist/solid/scene-object.js +111 -0
- package/dist/solid/scene-object.js.map +1 -0
- package/dist/solid/stage-batches.d.ts +10 -0
- package/dist/solid/stage-batches.d.ts.map +1 -0
- package/dist/solid/stage-batches.js +6 -0
- package/dist/solid/stage-batches.js.map +1 -0
- package/dist/solid/stage-drag.d.ts +4 -0
- package/dist/solid/stage-drag.d.ts.map +1 -0
- package/dist/solid/stage-drag.js +19 -0
- package/dist/solid/stage-drag.js.map +1 -0
- package/dist/solid/stage.d.ts +107 -0
- package/dist/solid/stage.d.ts.map +1 -0
- package/dist/solid/stage.js +320 -0
- package/dist/solid/stage.js.map +1 -0
- package/dist/solid/test-stage.d.ts +29 -0
- package/dist/solid/test-stage.d.ts.map +1 -0
- package/dist/solid/test-stage.js +16 -0
- package/dist/solid/test-stage.js.map +1 -0
- package/dist/solid.d.ts +55 -0
- package/dist/solid.d.ts.map +1 -0
- package/dist/solid.js +9 -0
- package/dist/solid.js.map +1 -0
- package/package.json +99 -4
- package/src/TestStage.ts +177 -0
- package/src/ThreeColours.ts +259 -0
- package/src/ThreeDrag.ts +341 -0
- package/src/ThreeInput.ts +744 -0
- package/src/ThreeInstances.ts +481 -0
- package/src/ThreeRenderer.ts +159 -0
- package/src/ThreeValues.ts +69 -0
- package/src/WardicThree.ts +364 -0
- package/src/index.ts +26 -0
- package/src/internal/dev.production.ts +7 -0
- package/src/internal/dev.ts +10 -0
- package/src/internal/lookup.ts +247 -0
- package/src/internal/shared-material.ts +101 -0
- package/src/solid/feature.ts +38 -0
- package/src/solid/scene-batch.ts +490 -0
- package/src/solid/scene-object.ts +145 -0
- package/src/solid/stage-batches.ts +13 -0
- package/src/solid/stage-drag.ts +26 -0
- package/src/solid/stage.ts +409 -0
- package/src/solid/test-stage.ts +40 -0
- package/src/solid.ts +111 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 the Wardic contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,85 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @wardic/three
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Wardic for three.js: Motion's `animate` on a scene's meshes, materials, cameras, lights and uniforms, on frames your Host loop pumps. Its keys are Motion's names, typed by three's own types.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import * as WardicThree from "@wardic/three/WardicThree"
|
|
7
|
+
|
|
8
|
+
const wardic = WardicThree.make()
|
|
9
|
+
renderer.setAnimationLoop((time) => {
|
|
10
|
+
wardic.frame(time) // Wardic's writes for this frame, before it's drawn
|
|
11
|
+
renderer.render(scene, camera)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
wardic.animate(cube, { y: 2, rotateY: 180 }, { type: "spring", bounce: 0.3 })
|
|
15
|
+
await wardic.animate(cube, { opacity: 0 }, { duration: 0.4 })
|
|
16
|
+
wardic.animate(camera, { fov: 35, z: 8 })
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- **Transform keys** are Motion's: `x`, `y` and `z` move `position`; `rotateX`, `rotateY` and `rotateZ` turn `rotation`, in degrees; `scale` sets all three scales, and `scaleX`, `scaleY` and `scaleZ` one each. Each frame they're written in one call per vector.
|
|
20
|
+
- **Any other key** is the object's own number (a camera's `fov`, a light's `intensity`), else its material's (`opacity`, `roughness`), a `ShaderMaterial` uniform's (`uProgress`), a TSL uniform node's, or a vector's axis (`normalScaleX`).
|
|
21
|
+
- **Types:** `animate(cube, { rotatY: 90 })` is a type error, and a camera suggests its projection keys.
|
|
22
|
+
- **A shared material** changes on every mesh that uses it. In development, Wardic warns at the first key it finds on one, naming the other meshes.
|
|
23
|
+
- **three's rules after a write:** a camera's projection keys update its projection matrix, and an `opacity` below 1 draws its material transparent.
|
|
24
|
+
- **Units:** `x`, `y` and `z` are metres, so a spring rests within millimetres. Give `make({ unitScale: 1 })` for a scene in pixels.
|
|
25
|
+
- **Reduced motion** snaps the transforms and a camera's `fov` and `zoom`, and fades the rest.
|
|
26
|
+
- **Colours** (`color`, `emissive`, a uniform's `Color`) take a CSS colour, a hex number or a `Color`, and blend in linear light, three's: red to blue passes `#bc00bc`. A spring keeps a colour's speed through a change of target.
|
|
27
|
+
- **A Batch** moves many objects on the same keys as one run: `wardic.batch(meshes)`. A value can be a function of a member's index: `animate(swarm, { y: (i) => i * 2, color: (i) => palette[i % 5] })`.
|
|
28
|
+
- **An `InstancedMesh`'s instances** are a Batch too, `wardic.batch(instanced)`, each moved by its transforms and its instance colour. Each frame, Wardic writes the matrices of the instances that moved, uploads only that span, and keeps the mesh's bounding sphere around them, so culling and picking stay right.
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
const swarm = wardic.batch(instanced)
|
|
32
|
+
wardic.animate(swarm, { y: (i) => rowY(i), rotateY: 90 }, { type: "spring", delay: stagger(0.002) })
|
|
33
|
+
wardic.animate(swarm.at(42), { scale: 1.4, color: "#ff8800" })
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- **Hover and press:** given its canvas, camera and scene, a runtime's `hover(subject, onStart)` and `press(subject, onStart)` work on the scene's objects, a Batch's members and an `InstancedMesh`'s instances. The pointer hits the nearest drawn object under it, cast once a frame, so hover follows what moves under a still pointer.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
const wardic = WardicThree.make({ canvas: renderer.domElement, camera, scene })
|
|
40
|
+
wardic.hover(crate, () => {
|
|
41
|
+
wardic.animate(crate, { scale: 1.1 })
|
|
42
|
+
return () => wardic.animate(crate, { scale: 1 })
|
|
43
|
+
})
|
|
44
|
+
wardic.press(swarm, (event) => (end, { success }) => {
|
|
45
|
+
if (success) select(event.member)
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- **Tests:** `@wardic/three/TestStage` runs a scene with no renderer and no page, in Node: `stage.pointer.over(crate)`, then `stage.frame()`.
|
|
50
|
+
|
|
51
|
+
## With Solid 2
|
|
52
|
+
|
|
53
|
+
`@wardic/three/solid` runs a scene for a component: `createStage` mounts the canvas, keeps it sized and runs the Host loop, and under `<WardicStage>` its hooks work on the scene's objects. `solid-js`, `@solidjs/web` and `@wardic/solid` are optional peers, needed only for this subpath.
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
import { createFrameEffect, createSceneObject, createStage, stageDrag, ward, WardicStage } from "@wardic/three/solid"
|
|
57
|
+
|
|
58
|
+
const stage = createStage({ renderer: () => new WebGLRenderer({ antialias: true }), scene, camera, frameloop: "demand" })
|
|
59
|
+
|
|
60
|
+
const Crate = (props: { mesh: Mesh }) => {
|
|
61
|
+
const crate = ward(props.mesh, { initial: { scale: 0 }, animate: { scale: 1 }, whileHover: { y: 0.3, color: "#4fd1c5" }, drag: true })
|
|
62
|
+
// In the Host loop, after Wardic's writes and before the render: the crate's shadow shrinks as it rises.
|
|
63
|
+
createFrameEffect(() => crate.read("y")(), (y) => {
|
|
64
|
+
shadow.scale.setScalar(1 - y / 2)
|
|
65
|
+
})
|
|
66
|
+
return crate.held
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
<WardicStage value={stage}>
|
|
70
|
+
<div class="viewport" ref={stage} />
|
|
71
|
+
<Crate mesh={crate} />
|
|
72
|
+
</WardicStage>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
- **`createStage`** takes a renderer or a function making one (called once the page has settled, so a server never does), a scene and a camera. `frameloop: "demand"` draws only while something moves, a Frame effect applies, or after `invalidate()`. `{ wardic }` adopts a runtime made outside Solid, whose maker pumps its frames.
|
|
76
|
+
- **`ward(mesh, config)`** under the Stage takes `initial`, `animate`, `transition`, `variants`, `whileHover` and `whileTap`. A ward with variants and no names of its own follows the nearest ward above its object in three's graph, not Solid's tree. `read(key)` gives the object's keys at their types, a number on it as an `Accessor<number>`, from its own value until the ward moves it.
|
|
77
|
+
- **`createSceneObject(mesh, config)`** adds an object to the scene as its ward starts (its `parent`, else the one it has, else the scene) and removes it once its `exit` lands. `dispose: true` disposes its geometries and materials then.
|
|
78
|
+
- **Drag and Batches are features,** each code only a scene that uses it carries: `createStage({ …, features: [stageDrag, stageBatches] })`. `ward(mesh, { drag })` drags on the plane facing the camera, a `dragPlane`, or an axis; `createBatch({ object, … })` or `createBatch({ instances, … })` animates meshes or an `InstancedMesh`'s instances as one run.
|
|
79
|
+
- **The sensors** take a scene's object: `createHover(mesh)`, `createPress(mesh)`, `createDrag(mesh)`.
|
|
80
|
+
- **A scene's hooks alone:** `ward`, `createBatch` and the sensors from here are `@wardic/solid`'s for a scene's objects, without the page's code. A three.js scene and one ward come to 243 KB gzipped this way, against 300 through `@wardic/solid`'s `ward`, which takes a page's element too. A page with both can use either.
|
|
81
|
+
- **Tests:** `@wardic/three/solid`'s `TestStage.make` is a Stage too, so a component's hooks run in Node with no renderer.
|
|
82
|
+
|
|
83
|
+
The [3D guide](https://wardic.dev/guides/3d) shows it with live scenes; the [three.js reference](https://wardic.dev/reference/three) has every module, and `@wardic/three/solid`'s hooks are in the [Solid reference](https://wardic.dev/reference/solid/scenes/create-stage).
|
|
84
|
+
|
|
85
|
+
Shipped from Wardic 1.3 (#564), versioned with `@wardic/core`, `@wardic/dom`, `@wardic/test`, `@wardic/foldkit` and `@wardic/object`. `@wardic/three/solid` runs on the app's own `@wardic/solid`, 2.1 or a later 2.x.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
Wardic follows the API of [Motion](https://motion.dev) for React, and parts of its source are ported from Motion's: rewritten in Wardic's own style, keeping Motion's algorithms, formulas and constants so the results match. Motion is MIT licensed, and its notice follows.
|
|
4
|
+
|
|
5
|
+
## Motion
|
|
6
|
+
|
|
7
|
+
https://github.com/motiondivision/motion
|
|
8
|
+
|
|
9
|
+
Ported from Motion's source:
|
|
10
|
+
|
|
11
|
+
- `@wardic/core`:
|
|
12
|
+
- `Box` and `Projection`: the projection geometry (`motion-dom`'s `projection/geometry`: `models`, `delta-calc`, `delta-apply`, `applyTreeDeltas`);
|
|
13
|
+
- `Spring`: the solver for a spring's stiffness and damping from its duration and bounce (`findSpring`);
|
|
14
|
+
- `Velocity`: a gesture's velocity from its points (`getVelocity`);
|
|
15
|
+
- `Reorder`: moving an item, and the axis a list runs on (`moveItem`, `detectAxis`);
|
|
16
|
+
- `AutoScroll`: scrolling a container while an item is dragged near its edge (`autoScrollIfNeeded`).
|
|
17
|
+
- `@wardic/dom`:
|
|
18
|
+
- the projection transform (`buildProjectionTransform`);
|
|
19
|
+
- the scroll offsets (`render/dom/scroll/offsets`).
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
The MIT License (MIT)
|
|
23
|
+
|
|
24
|
+
Copyright (c) 2024 [Motion](https://motion.dev) B.V.
|
|
25
|
+
|
|
26
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
27
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
28
|
+
in the Software without restriction, including without limitation the rights
|
|
29
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
30
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
31
|
+
furnished to do so, subject to the following conditions:
|
|
32
|
+
|
|
33
|
+
The above copyright notice and this permission notice shall be included in all
|
|
34
|
+
copies or substantial portions of the Software.
|
|
35
|
+
|
|
36
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
37
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
38
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
39
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
40
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
41
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
42
|
+
SOFTWARE.
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Manrope
|
|
46
|
+
|
|
47
|
+
https://github.com/googlefonts/manrope
|
|
48
|
+
|
|
49
|
+
The docs site serves Manrope for its headings (`site/public/fonts/manrope-latin.woff2`, its variable weights 600 to 800, Latin only, with its licence beside it as `OFL.txt`), and Wardic's wordmark is "wardic" set in Manrope ExtraBold and outlined (`brand/`, and the docs header's logo, `site/src/components/logo-paths.ts`). Manrope is licensed under the SIL Open Font License, Version 1.1.
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
Copyright 2018 The Manrope Project Authors (https://github.com/googlefonts/manrope)
|
|
53
|
+
|
|
54
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
55
|
+
This license is copied below, and is also available with a FAQ at:
|
|
56
|
+
http://scripts.sil.org/OFL
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
-----------------------------------------------------------
|
|
60
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
61
|
+
-----------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
PREAMBLE
|
|
64
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
65
|
+
development of collaborative font projects, to support the font creation
|
|
66
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
67
|
+
open framework in which fonts may be shared and improved in partnership
|
|
68
|
+
with others.
|
|
69
|
+
|
|
70
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
71
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
72
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
73
|
+
redistributed and/or sold with any software provided that any reserved
|
|
74
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
75
|
+
however, cannot be released under any other type of license. The
|
|
76
|
+
requirement for fonts to remain under this license does not apply
|
|
77
|
+
to any document created using the fonts or their derivatives.
|
|
78
|
+
|
|
79
|
+
DEFINITIONS
|
|
80
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
81
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
82
|
+
include source files, build scripts and documentation.
|
|
83
|
+
|
|
84
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
85
|
+
copyright statement(s).
|
|
86
|
+
|
|
87
|
+
"Original Version" refers to the collection of Font Software components as
|
|
88
|
+
distributed by the Copyright Holder(s).
|
|
89
|
+
|
|
90
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
91
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
92
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
93
|
+
new environment.
|
|
94
|
+
|
|
95
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
96
|
+
writer or other person who contributed to the Font Software.
|
|
97
|
+
|
|
98
|
+
PERMISSION & CONDITIONS
|
|
99
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
100
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
101
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
102
|
+
Software, subject to the following conditions:
|
|
103
|
+
|
|
104
|
+
1) Neither the Font Software nor any of its individual components,
|
|
105
|
+
in Original or Modified Versions, may be sold by itself.
|
|
106
|
+
|
|
107
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
108
|
+
redistributed and/or sold with any software, provided that each copy
|
|
109
|
+
contains the above copyright notice and this license. These can be
|
|
110
|
+
included either as stand-alone text files, human-readable headers or
|
|
111
|
+
in the appropriate machine-readable metadata fields within text or
|
|
112
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
113
|
+
|
|
114
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
115
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
116
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
117
|
+
presented to the users.
|
|
118
|
+
|
|
119
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
120
|
+
Software shall not be used to promote, endorse or advertise any
|
|
121
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
122
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
123
|
+
permission.
|
|
124
|
+
|
|
125
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
126
|
+
must be distributed entirely under this license, and must not be
|
|
127
|
+
distributed under any other license. The requirement for fonts to
|
|
128
|
+
remain under this license does not apply to any document created
|
|
129
|
+
using the Font Software.
|
|
130
|
+
|
|
131
|
+
TERMINATION
|
|
132
|
+
This license becomes null and void if any of the above conditions are
|
|
133
|
+
not met.
|
|
134
|
+
|
|
135
|
+
DISCLAIMER
|
|
136
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
137
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
138
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
139
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
140
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
141
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
142
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
143
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
144
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
145
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Camera, Object3D } from "three";
|
|
2
|
+
import * as WardicThree from "./WardicThree.ts";
|
|
3
|
+
/** `make`'s options: the scene, its camera, the stand-in canvas's size, and `WardicThree.make`'s. */
|
|
4
|
+
export interface Options extends Omit<WardicThree.Options, "canvas" | "camera" | "scene" | "window" | "now"> {
|
|
5
|
+
readonly scene: Object3D;
|
|
6
|
+
readonly camera: Camera;
|
|
7
|
+
/** The stand-in canvas's size, in CSS pixels, at the page's top left. */
|
|
8
|
+
readonly size: {
|
|
9
|
+
readonly width: number;
|
|
10
|
+
readonly height: number;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** A mouse over the stand-in canvas. */
|
|
14
|
+
export interface TestPointer {
|
|
15
|
+
/** Moves it to where `target` is drawn: a scene object's middle, a Batch member's, an instance's. */
|
|
16
|
+
readonly over: (target: object) => void;
|
|
17
|
+
/** Moves it to `x`, `y` on the canvas, in CSS pixels. */
|
|
18
|
+
readonly at: (x: number, y: number) => void;
|
|
19
|
+
/** Presses its main button where it is. */
|
|
20
|
+
readonly down: () => void;
|
|
21
|
+
/** Releases it where it is. */
|
|
22
|
+
readonly up: () => void;
|
|
23
|
+
/** The platform cancels its press. */
|
|
24
|
+
readonly cancel: () => void;
|
|
25
|
+
/** Takes it off the canvas. */
|
|
26
|
+
readonly leave: () => void;
|
|
27
|
+
/** Where it is now, in CSS pixels. */
|
|
28
|
+
readonly position: () => {
|
|
29
|
+
readonly x: number;
|
|
30
|
+
readonly y: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** A test's scene runtime: `WardicThree`'s, its frames pumped by `frame`, with a pointer. */
|
|
34
|
+
export interface TestStage extends Omit<WardicThree.WardicThree, "frame"> {
|
|
35
|
+
/** One frame of the Host loop, `ms` after the last (1/60 s): Wardic's frame on the scene as it's built, then its matrices, as a render makes them. */
|
|
36
|
+
readonly frame: (ms?: number) => void;
|
|
37
|
+
/** The stage's time now, in ms. */
|
|
38
|
+
readonly now: () => number;
|
|
39
|
+
readonly pointer: TestPointer;
|
|
40
|
+
/** The stand-in canvas the pointer's events reach. */
|
|
41
|
+
readonly canvas: EventTarget;
|
|
42
|
+
}
|
|
43
|
+
/** A scene runtime for a test, on a stand-in canvas of `options.size`. */
|
|
44
|
+
export declare const make: (options: Options) => TestStage;
|
|
45
|
+
//# sourceMappingURL=TestStage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestStage.d.ts","sourceRoot":"","sources":["../src/TestStage.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAG7C,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAG/C,qGAAqG;AACrG,MAAM,WAAW,OAAQ,SAAQ,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IAC1G,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CACnE;AAED,wCAAwC;AACxC,MAAM,WAAW,WAAW;IAC1B,qGAAqG;IACrG,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC,yDAAyD;IACzD,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3C,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAA;IACzB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,IAAI,CAAA;IACvB,sCAAsC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAA;IAC3B,+BAA+B;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,IAAI,CAAA;IAC1B,sCAAsC;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM;QAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACpE;AAED,6FAA6F;AAC7F,MAAM,WAAW,SAAU,SAAQ,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,OAAO,CAAC;IACvE,sJAAsJ;IACtJ,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IACrC,mCAAmC;IACnC,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAA;IAC1B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAA;IAC7B,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAC7B;AA+BD,0EAA0E;AAC1E,eAAO,MAAM,IAAI,YAAa,OAAO,KAAG,SA2EvC,CAAA"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A scene's runtime for tests, with no renderer and no page: `WardicThree.make` on a stand-in canvas,
|
|
3
|
+
* its frames pumped by `frame()`, and a pointer that hovers and presses objects through the scene's own
|
|
4
|
+
* input, hit by three's real raycast. It runs in Node.
|
|
5
|
+
*
|
|
6
|
+
* - **`frame(ms?)`** runs one frame of the Host loop, 1/60 s on by default: Wardic's raycast and writes
|
|
7
|
+
* against the scene as it's built, as though the page had drawn it, then its matrices made current, as a
|
|
8
|
+
* render makes them.
|
|
9
|
+
* - **`pointer`** moves a mouse over the stand-in canvas: `over(mesh)` to where `mesh` is drawn, `at(x, y)`,
|
|
10
|
+
* `down()`, `up()`, `cancel()` and `leave()`. A frame then finds what's under it, as on a page.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import * as TestStage from "@wardic/three/TestStage"
|
|
14
|
+
*
|
|
15
|
+
* const stage = TestStage.make({ scene, camera, size: { width: 800, height: 600 } })
|
|
16
|
+
* stage.hover(crate, () => {
|
|
17
|
+
* stage.animate(crate, { scale: 1.1 })
|
|
18
|
+
* return () => stage.animate(crate, { scale: 1 })
|
|
19
|
+
* })
|
|
20
|
+
* stage.pointer.over(crate)
|
|
21
|
+
* stage.frame()
|
|
22
|
+
*/
|
|
23
|
+
// `@wardic/three/TestStage` (#883's PR 5a; ADR-0073 decision 26, amended by *Amendment (#883)*, PR 5's Q2
|
|
24
|
+
// and Q6): it stays in `@wardic/three` at 1.3 (ADR-0073, *1.3's release*), beside the runtime it drives,
|
|
25
|
+
// so `@wardic/test` takes no three.js peers. `stage.ward` and `<WardicStage value={stage}>` came with
|
|
26
|
+
// steps 3 and 4.
|
|
27
|
+
import * as Predicate from "effect/Predicate";
|
|
28
|
+
import * as Rec from "effect/Record";
|
|
29
|
+
import { Matrix4, Vector3 } from "three";
|
|
30
|
+
import * as ThreeInstances from "./ThreeInstances.js";
|
|
31
|
+
import * as WardicThree from "./WardicThree.js";
|
|
32
|
+
import * as ObjectBatch from "@wardic/object/ObjectBatch";
|
|
33
|
+
/** A pointer event as the stand-in dispatches it: an `Event` with a `PointerEvent`'s fields. */
|
|
34
|
+
const pointerEvent = (type, fields) => Object.defineProperties(new Event(type), Rec.map(fields, (value) => ({ value })));
|
|
35
|
+
/** Where `target` is drawn, in world space: an instance's geometry's middle through its matrix, an object's through its own. */
|
|
36
|
+
const worldMiddleOf = (target) => {
|
|
37
|
+
const middle = new Vector3();
|
|
38
|
+
const subject = memberOf(target);
|
|
39
|
+
if (ThreeInstances.isInstance(subject)) {
|
|
40
|
+
const mesh = subject.mesh;
|
|
41
|
+
if (Predicate.isNull(mesh.geometry.boundingSphere))
|
|
42
|
+
mesh.geometry.computeBoundingSphere();
|
|
43
|
+
middle.copy(mesh.geometry.boundingSphere.center);
|
|
44
|
+
return middle.applyMatrix4(mesh.getMatrixAt(subject.index, new Matrix4())).applyMatrix4(mesh.matrixWorld);
|
|
45
|
+
}
|
|
46
|
+
const object = subject;
|
|
47
|
+
const geometry = object.geometry;
|
|
48
|
+
if (Predicate.isUndefined(geometry))
|
|
49
|
+
return object.getWorldPosition(middle);
|
|
50
|
+
if (Predicate.isNull(geometry.boundingSphere))
|
|
51
|
+
geometry.computeBoundingSphere();
|
|
52
|
+
return object.localToWorld(middle.copy(geometry.boundingSphere.center));
|
|
53
|
+
};
|
|
54
|
+
/** A Batch member's handle as its member: a mesh, or an instance; anything else as it is. */
|
|
55
|
+
const memberOf = (target) => {
|
|
56
|
+
if (Predicate.isUndefined(ObjectBatch.entryOf(target)))
|
|
57
|
+
return target;
|
|
58
|
+
const handle = target;
|
|
59
|
+
if (Predicate.isNumber(handle.i) && Predicate.isNotUndefined(handle.batch))
|
|
60
|
+
return handle.batch.members[handle.i];
|
|
61
|
+
throw new Error("TestStage: pointer.over takes one object, a Batch's member (batch.at(i)) or an instance, not a whole Batch.");
|
|
62
|
+
};
|
|
63
|
+
/** A scene runtime for a test, on a stand-in canvas of `options.size`. */
|
|
64
|
+
export const make = (options) => {
|
|
65
|
+
const { width, height } = options.size;
|
|
66
|
+
const canvas = new EventTarget();
|
|
67
|
+
canvas.getBoundingClientRect = () => ({ left: 0, top: 0, width, height });
|
|
68
|
+
// The page's window, where a held pointer's events are heard.
|
|
69
|
+
const page = new EventTarget();
|
|
70
|
+
let time = 0;
|
|
71
|
+
const runtime = WardicThree.make({ ...options, canvas, window: page, now: () => time });
|
|
72
|
+
const { scene, camera } = options;
|
|
73
|
+
/** The scene's and the camera's matrices, made current as a render makes them. */
|
|
74
|
+
const draw = () => {
|
|
75
|
+
scene.updateMatrixWorld();
|
|
76
|
+
camera.updateMatrixWorld();
|
|
77
|
+
};
|
|
78
|
+
let x = 0;
|
|
79
|
+
let y = 0;
|
|
80
|
+
let over = false;
|
|
81
|
+
let buttons = 0;
|
|
82
|
+
/** A pointer event at the pointer, reaching the window in its capture phase and then the canvas, as a page's does. */
|
|
83
|
+
const dispatch = (type, button) => {
|
|
84
|
+
const event = pointerEvent(type, { clientX: x, clientY: y, pointerId: 1, pointerType: "mouse", isPrimary: true, button, buttons, timeStamp: time });
|
|
85
|
+
if (type !== "pointerenter" && type !== "pointerleave")
|
|
86
|
+
page.dispatchEvent(event);
|
|
87
|
+
canvas.dispatchEvent(event);
|
|
88
|
+
};
|
|
89
|
+
const moveTo = (nextX, nextY) => {
|
|
90
|
+
x = nextX;
|
|
91
|
+
y = nextY;
|
|
92
|
+
if (!over) {
|
|
93
|
+
over = true;
|
|
94
|
+
dispatch("pointerenter", -1);
|
|
95
|
+
}
|
|
96
|
+
dispatch("pointermove", -1);
|
|
97
|
+
};
|
|
98
|
+
const pointer = {
|
|
99
|
+
over: (target) => {
|
|
100
|
+
// Where it's drawn as it's built now.
|
|
101
|
+
draw();
|
|
102
|
+
const ndc = worldMiddleOf(target).project(camera);
|
|
103
|
+
moveTo(((ndc.x + 1) / 2) * width, ((1 - ndc.y) / 2) * height);
|
|
104
|
+
},
|
|
105
|
+
at: moveTo,
|
|
106
|
+
down: () => {
|
|
107
|
+
buttons = 1;
|
|
108
|
+
dispatch("pointerdown", 0);
|
|
109
|
+
},
|
|
110
|
+
up: () => {
|
|
111
|
+
buttons = 0;
|
|
112
|
+
dispatch("pointerup", 0);
|
|
113
|
+
},
|
|
114
|
+
cancel: () => {
|
|
115
|
+
buttons = 0;
|
|
116
|
+
dispatch("pointercancel", 0);
|
|
117
|
+
},
|
|
118
|
+
leave: () => {
|
|
119
|
+
if (!over)
|
|
120
|
+
return;
|
|
121
|
+
over = false;
|
|
122
|
+
dispatch("pointerleave", -1);
|
|
123
|
+
},
|
|
124
|
+
position: () => ({ x, y }),
|
|
125
|
+
};
|
|
126
|
+
return {
|
|
127
|
+
...runtime,
|
|
128
|
+
frame: (ms = 1000 / 60) => {
|
|
129
|
+
time += ms;
|
|
130
|
+
// What a test built since the last frame, as though the page had drawn it: the raycast hits it there.
|
|
131
|
+
draw();
|
|
132
|
+
runtime.frame(time);
|
|
133
|
+
draw();
|
|
134
|
+
},
|
|
135
|
+
now: () => time,
|
|
136
|
+
pointer,
|
|
137
|
+
canvas,
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
//# sourceMappingURL=TestStage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestStage.js","sourceRoot":"","sources":["../src/TestStage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,0GAA0G;AAC1G,yGAAyG;AACzG,sGAAsG;AACtG,iBAAiB;AACjB,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,GAAG,MAAM,eAAe,CAAA;AAEpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACxC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,WAAW,MAAM,4BAA4B,CAAA;AAuCzD,gGAAgG;AAChG,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,MAA2D,EAAS,EAAE,CACxG,MAAM,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;AAEnF,gIAAgI;AAChI,MAAM,aAAa,GAAG,CAAC,MAAc,EAAW,EAAE;IAChD,MAAM,MAAM,GAAG,IAAI,OAAO,EAAE,CAAA;IAC5B,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAA;IAChC,IAAI,cAAc,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAyL,CAAA;QAC9M,IAAI,SAAS,CAAC,MAAM,CAAC,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AAO,GAAG,CAAC,CAAA;YACX,QAAQ,CAAC,eAAe,EAAE,CAAC,CAAC,CAAA;QAC9B,CAAC;QACD,KAAK,EAAE,GAAG,EAAE;YACV,IAAI,CAAC,IAAI;gBAAE,OAAM;YACjB,IAAI,GAAG,KAAK,CAAA;YACZ,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,CAAA;QAC9B,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;KAC3B,CAAA;IAED,OAAO;QACL,GAAG,OAAO;QACV,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,GAAG,EAAE,EAAE,EAAE;YACxB,IAAI,IAAI,EAAE,CAAA;YACV,sGAAsG;YACtG,IAAI,EAAE,CAAA;YACN,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YACnB,IAAI,EAAE,CAAA;QACR,CAAC;QACD,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;QACf,OAAO;QACP,MAAM;KACP,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A scene's colours, as Wardic animates them: in linear light, three's working space, each as three
|
|
3
|
+
* channel keys. A colour key's target (a CSS colour, a hex number, or a three `Color`, copied) is read
|
|
4
|
+
* once into its linear channels, `color` into `colorR`, `colorG` and `colorB`, which springs move as
|
|
5
|
+
* they move `x`, keeping their speed through a change of target, and which the writer sets on the
|
|
6
|
+
* `Color` itself. Red to blue passes `#bc00bc`, as three's own `Color.lerp` does.
|
|
7
|
+
*
|
|
8
|
+
* A channel rests by its share of the distance it goes, as a blended key's progress does, so a move
|
|
9
|
+
* from black to a near black animates, and every colour lands in the same time.
|
|
10
|
+
*
|
|
11
|
+
* A Batch's colours split the same way: one for every member, two stops, or a function of a member's
|
|
12
|
+
* index, each member's colour read once. An `InstancedMesh`'s instance's `color` is its instance colour.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import * as ThreeColours from "@wardic/three/ThreeColours"
|
|
16
|
+
*
|
|
17
|
+
* ThreeColours.split(mesh, { color: "#0000ff", opacity: 1 })
|
|
18
|
+
* // { opacity: 1, colorR: 0, colorG: 0, colorB: 1 }
|
|
19
|
+
*/
|
|
20
|
+
import * as UnitScale from "@wardic/core/UnitScale";
|
|
21
|
+
/** A colour key's value: a CSS colour (`"#00f"`, `"rgb(0 0 255)"`, `"blue"`), a hex number (`0x0000ff`), or a three `Color`, copied. */
|
|
22
|
+
export type ColourValue = string | number | {
|
|
23
|
+
readonly isColor: true;
|
|
24
|
+
};
|
|
25
|
+
/** The suffixes of a colour's channel keys: `colorR`, `colorG`, `colorB`. */
|
|
26
|
+
export declare const CHANNELS: readonly ["R", "G", "B"];
|
|
27
|
+
/** Whether `key` names a colour's channel: `colorR`, `emissiveG`, `uTintB`. */
|
|
28
|
+
export declare const isChannel: (key: string) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* A scene's unit scale: `x`, `y` and `z` at `scale` of Motion's units, a colour's channels by their
|
|
31
|
+
* share of the distance, every other key at 1.
|
|
32
|
+
*/
|
|
33
|
+
export declare const unitScale: (scale: number) => UnitScale.Rule;
|
|
34
|
+
/**
|
|
35
|
+
* A call's target and options on `subject`, each colour key split into its channels: its value or
|
|
36
|
+
* keyframes, its `transitionEnd`, and a colour's entry in the target's `transition` or the options,
|
|
37
|
+
* which runs each of its channels without an entry of its own, whichever the target names. A target
|
|
38
|
+
* and options with no colour come back as they are. For a Batch, `subject` is a member, and a value may
|
|
39
|
+
* be two stops or a function of a member's index.
|
|
40
|
+
*/
|
|
41
|
+
export declare const splitCall: (subject: unknown, target: unknown, options: unknown) => readonly [target: unknown, options: unknown];
|
|
42
|
+
/** `target` on `subject`, each colour key split into its channels. */
|
|
43
|
+
export declare const split: (subject: object, target: Readonly<Record<string, unknown>>) => Readonly<Record<string, unknown>>;
|
|
44
|
+
/**
|
|
45
|
+
* A ward's config on a scene's Subject, each colour key split into its channels in linear light,
|
|
46
|
+
* as a call's are (`splitCall`): each target's values, an accessor's as it's read, each variant's (a
|
|
47
|
+
* function's as it's called), and the transition's colour entries. `subjectNow` is the Subject now, read
|
|
48
|
+
* as each is split, so an accessor Subject's colours are its current one's. Every other key is as given.
|
|
49
|
+
*/
|
|
50
|
+
export declare const splitConfig: (subjectNow: () => unknown, config: Readonly<Record<string, unknown>>) => Readonly<Record<string, unknown>>;
|
|
51
|
+
/** The `keys` of a Batch made of `given` (an `InstancedMesh`, or a list), each colour key given as its three channels. */
|
|
52
|
+
export declare const splitBatchKeys: (given: unknown, keys: ReadonlyArray<string>) => ReadonlyArray<string>;
|
|
53
|
+
//# sourceMappingURL=ThreeColours.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThreeColours.d.ts","sourceRoot":"","sources":["../src/ThreeColours.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAA;AAkBnD,wIAAwI;AACxI,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAA;CAAE,CAAA;AAEtE,6EAA6E;AAC7E,eAAO,MAAM,QAAQ,YAAI,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAA;AAKhD,+EAA+E;AAC/E,eAAO,MAAM,SAAS,QAAS,MAAM,KAAG,OAAgC,CAAA;AAKxE;;;GAGG;AACH,eAAO,MAAM,SAAS,UAAW,MAAM,KAAG,SAAS,CAAC,IAMnD,CAAA;AA6GD;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,YAAa,OAAO,UAAU,OAAO,WAAW,OAAO,KAAG,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAG1H,CAAA;AAED,sEAAsE;AACtE,eAAO,MAAM,KAAK,YAAa,MAAM,UAAU,QAAQ,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