@hivey/cli 0.9.60 → 0.9.62
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/native/darwin-arm64/hivey +0 -0
- package/package.json +1 -1
- package/repo/skills/hivey/scripts/new_wiki.py +12 -0
- package/repo/skills/hivey-agent-map/SKILL.md +36 -3
- package/repo/skills/hivey-agent-map/scripts/agent_map.py +16 -6
- package/repo/skills/hivey-agent-map/scripts/office/OutlineEffect.js +539 -0
- package/repo/skills/hivey-agent-map/scripts/office/RoomEnvironment.js +148 -0
- package/repo/skills/hivey-agent-map/scripts/office/loaders/GLTFLoader.js +4663 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/LICENSE-kenney-space-kit.txt +23 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/LICENSE-kenney-space-station-kit.txt +28 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/LICENSE-robot.txt +2 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/astronautA.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/astronautB.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/barrels.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/barrels_rail.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/craft_cargoA.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/craft_racer.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/craft_speederA.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/desk_chairArms.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/desk_computer.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/machine_generator.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/machine_generatorLarge.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/machine_wireless.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/robot.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/satelliteDish_detailed.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/satelliteDish_large.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/station/Textures/colormap.png.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/station/chair-cushion-headrest.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/station/computer-system.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/station/computer-wide.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/station/container-flat.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/station/container-tall.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/station/container-wide.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/station/display-wall-wide.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/models/station/pipe-ring-colored.glb.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/music/README.txt +2 -0
- package/repo/skills/hivey-agent-map/scripts/office/music/space.mp3.b64 +1 -0
- package/repo/skills/hivey-agent-map/scripts/office/office.html +179 -0
- package/repo/skills/hivey-agent-map/scripts/office/office.js +754 -0
- package/repo/skills/hivey-agent-map/scripts/office/postprocessing/EffectComposer.js +231 -0
- package/repo/skills/hivey-agent-map/scripts/office/postprocessing/MaskPass.js +104 -0
- package/repo/skills/hivey-agent-map/scripts/office/postprocessing/OutputPass.js +95 -0
- package/repo/skills/hivey-agent-map/scripts/office/postprocessing/Pass.js +95 -0
- package/repo/skills/hivey-agent-map/scripts/office/postprocessing/RenderPass.js +99 -0
- package/repo/skills/hivey-agent-map/scripts/office/postprocessing/ShaderPass.js +77 -0
- package/repo/skills/hivey-agent-map/scripts/office/postprocessing/UnrealBloomPass.js +415 -0
- package/repo/skills/hivey-agent-map/scripts/office/shaders/CopyShader.js +45 -0
- package/repo/skills/hivey-agent-map/scripts/office/shaders/LuminosityHighPassShader.js +66 -0
- package/repo/skills/hivey-agent-map/scripts/office/shaders/OutputShader.js +81 -0
- package/repo/skills/hivey-agent-map/scripts/office/ship.js +578 -0
- package/repo/skills/hivey-agent-map/scripts/office/three.module.min.js +6 -0
- package/repo/skills/hivey-agent-map/scripts/office/utils/BufferGeometryUtils.js +1375 -0
- package/repo/skills/hivey-agent-map/scripts/office/utils/SkeletonUtils.js +413 -0
- package/repo/skills/hivey-agent-map/scripts/office.py +522 -0
- package/repo/skills/hivey-agent-map/scripts/report.py +105 -2
- package/repo/skills/hivey-agent-map/scripts/serve.py +190 -9
- package/repo/skills/hivey-create-wiki/SKILL.md +27 -2
- package/repo/skills/hivey-swarm-creator/SKILL.md +4 -0
- package/repo/skills/hivey-swarm-creator/references/wiki-memory.md +3 -0
- package/repo/skills/hivey-wiki-lint/SKILL.md +7 -2
|
Binary file
|
package/package.json
CHANGED
|
@@ -45,6 +45,18 @@ write what they learn, so knowledge survives restarts and new sessions.
|
|
|
45
45
|
3. New finding or decision: add it to the right page (create one if none fits), add the page
|
|
46
46
|
to `index.md`, and a line to `log.md`.
|
|
47
47
|
4. Prefer updating a page over creating a near-duplicate. Cite the `raw/` file a fact came from.
|
|
48
|
+
5. Label every important claim, so a later reader knows what to trust:
|
|
49
|
+
- **verified**: checked, with its source (a `raw/` file, file:line, command and output, URL);
|
|
50
|
+
- **hypothesis**: believed but not checked yet; never build on it as if it were fact;
|
|
51
|
+
- **decision**: a choice someone made, with who and why.
|
|
52
|
+
A claim one agent reported but nobody checked is a hypothesis. When a hypothesis is checked,
|
|
53
|
+
relabel it (or remove it if wrong) instead of adding a correction next to it.
|
|
54
|
+
|
|
55
|
+
## Safety
|
|
56
|
+
- Never write secrets (keys, tokens, passwords) into the wiki: write the envsave ID or the
|
|
57
|
+
variable name. hivey's wiki guard blocks writes that look like a secret.
|
|
58
|
+
- If a write is blocked because another agent is editing the page, wait, re-read the page,
|
|
59
|
+
then apply your change.
|
|
48
60
|
"""
|
|
49
61
|
|
|
50
62
|
MEMORY = """
|
|
@@ -104,8 +104,8 @@ surprising link). If archify is missing, give the stats as Markdown tables and t
|
|
|
104
104
|
|
|
105
105
|
```bash
|
|
106
106
|
hivey agent-map open # the latest report; builds the first one when none exists
|
|
107
|
-
hivey agent-map nightly [--model
|
|
108
|
-
hivey agent-map schedule install [--at 06:30] [--model
|
|
107
|
+
hivey agent-map nightly [--model sonnet] # a full report now (also: --no-llm, --open)
|
|
108
|
+
hivey agent-map schedule install [--at 06:30] [--model sonnet] # | remove | status
|
|
109
109
|
```
|
|
110
110
|
|
|
111
111
|
- **hivey menu → agent map** runs `hivey agent-map open`: it opens `agent-stats.html`,
|
|
@@ -162,7 +162,7 @@ hivey agent-map schedule install [--at 06:30] [--model haiku] # | remove | sta
|
|
|
162
162
|
why a job or agent is not working, read its entry in `snapshot.json` (`jobs[].errors`, `tail`,
|
|
163
163
|
`agent_logs`) or open this page, then the full log it names.
|
|
164
164
|
- **`nightly`** (`report.py`): scan → stats page written and finalized by code (no LLM) → last night's
|
|
165
|
-
`map.json` copied in → one `claude -p --model
|
|
165
|
+
`map.json` copied in → one `claude -p --model sonnet` run (in the report folder, limited tools) that
|
|
166
166
|
confirms new links and updates the map → if the model fails or breaks the map, last night's map is
|
|
167
167
|
rendered unchanged. `reports/latest` moves only when the stats page passed; the 30 newest reports
|
|
168
168
|
are kept. About 2 minutes and $0.03 with Haiku. Log: `nightly.log` and `llm.log` in the report.
|
|
@@ -179,6 +179,39 @@ hivey agent-map schedule install [--at 06:30] [--model haiku] # | remove | sta
|
|
|
179
179
|
- When you are the nightly model: follow the prompt you were given, change only `map.json`,
|
|
180
180
|
`agent-map.html` and `links.json` (through `link`), and stop after the map passes.
|
|
181
181
|
|
|
182
|
+
## Agent office (what every agent does now)
|
|
183
|
+
|
|
184
|
+
`hivey agent-map office` (hivey menu → agent office) opens http://127.0.0.1:42817/office/: every live
|
|
185
|
+
agent in hivey at a desk in a 3D office, one room per space. Solo agents, extra sessions in a space and
|
|
186
|
+
each swarm's coordinator get a desk; a swarm's workers and critics stand beside their coordinator's desk.
|
|
187
|
+
|
|
188
|
+
- **Reads** each desk's terminal (`hivey pane read`, any CLI) and its Claude Code session log (context
|
|
189
|
+
size = input + cache tokens of the last reply, model, last prompt, the session recap, last replies and
|
|
190
|
+
tools). `office.py run` writes `~/.hivey/agent-map/reports/office/office.json`.
|
|
191
|
+
- **Summarizes** with Sonnet (`claude -p --model sonnet`, no tools, no settings, no session saved), in
|
|
192
|
+
batches of 10, only the desks whose terminal or log changed (`~/.hivey/agent-map/office-cache.json`):
|
|
193
|
+
current job, a speech-bubble line, up to 3 achievements, next step, what to answer when it waits
|
|
194
|
+
for you, and keep / compact / clear advice. `--no-llm` (or a failed call) falls back to the recap.
|
|
195
|
+
- **Refreshes** every 5 minutes while the page is open (the server's office clock; the page polls every
|
|
196
|
+
15 s), or now with ⟳ / `r`.
|
|
197
|
+
- **Page**: Office (Three.js r160, MIT, vendored in `scripts/office/` with RoomEnvironment, OutlineEffect and the bloom
|
|
198
|
+
post-processing; `ship.js` builds the scene: the deck of a spacecraft floating in front of a galaxy, viewports, hull
|
|
199
|
+
light strips, an observation lounge with a holotable, galley, server racks, plant pods; the crew are mini robots,
|
|
200
|
+
one per desk, glass visor eyes in the status colour, team-coloured ear pods; ✨ HD (bloom) or 🎨 comic, `t`; only working agents move, a blocked one waves, labels
|
|
201
|
+
give way by urgency so hundreds stay readable), Board (cards by what needs you), List (sortable rows).
|
|
202
|
+
The top strip lists who is blocked or asked you something. Click an agent: `hivey agent focus` plus
|
|
203
|
+
the exact Terminal/iTerm tab running hivey comes forward. Right-click or ⓘ: details (context gauge,
|
|
204
|
+
terminal tail). Compact / Clear type `/compact` or `/clear` into an agent that is not working (two
|
|
205
|
+
clicks).
|
|
206
|
+
|
|
207
|
+
- **Models and music** (`scripts/office/models/`, `music/`, stored as `.b64` because skills install text files;
|
|
208
|
+
`office.py` decodes them into the page folder): the animated crew robot (RobotExpressive, Tomás Laulhé /
|
|
209
|
+
Quaternius, CC0: Idle + nods when working, Wave when blocked, ThumbsUp when done, Sitting when idle), Kenney
|
|
210
|
+
Space Kit and Space Station Kit pieces (CC0: desks, chairs, generators, dishes, small craft, astronauts,
|
|
211
|
+
consoles, crates), licences in `models/LICENSE-*`; a MusicGen space ambient loop, 🔇/🎵 or `m`.
|
|
212
|
+
- **CEO**: the space named `ceo` gets the captain's bridge, its own room in the ship's nose (gold trim, main
|
|
213
|
+
viewscreen); its master sits at the captain's console.
|
|
214
|
+
|
|
182
215
|
## Spend log (`hivey_spend.py`)
|
|
183
216
|
|
|
184
217
|
Calls made through Claude Code, Codex and Grok CLI are already counted from their own transcripts, and
|
|
@@ -8,10 +8,13 @@
|
|
|
8
8
|
add one entry to the spend log
|
|
9
9
|
agent_map.py link FROM TO --via WHAT [--evidence TEXT] [--remove]
|
|
10
10
|
confirm (or remove) a link between two nodes
|
|
11
|
-
agent_map.py nightly [--model
|
|
11
|
+
agent_map.py nightly [--model sonnet] [--no-llm] [--open]
|
|
12
12
|
a full report in ~/.hivey/agent-map/reports/<date>/
|
|
13
13
|
agent_map.py open open the latest report (hivey menu → agent map)
|
|
14
|
-
agent_map.py
|
|
14
|
+
agent_map.py office [open|run] [--no-llm] the agent office: every live agent at a desk, its current
|
|
15
|
+
job (terminal + session log, summed up by Sonnet), context
|
|
16
|
+
and compact/clear advice (hivey menu → agent office)
|
|
17
|
+
agent_map.py schedule [install|remove|status|offer] [--at 06:30] [--model sonnet]
|
|
15
18
|
agent_map.py schedule token --command "envsave get es_…" long-lived Claude login for the run
|
|
16
19
|
the nightly launchd run (com.hivey.agent-map)
|
|
17
20
|
|
|
@@ -1057,22 +1060,26 @@ def main() -> int:
|
|
|
1057
1060
|
lg.add_argument("--note")
|
|
1058
1061
|
nt = sub.add_parser("nightly", help="scan, stats page, map update with a cheap model, reports/latest")
|
|
1059
1062
|
nt.add_argument("--days", type=int, default=7)
|
|
1060
|
-
nt.add_argument("--model", default="
|
|
1063
|
+
nt.add_argument("--model", default="sonnet")
|
|
1061
1064
|
nt.add_argument("--no-llm", action="store_true", help="no model run: last night's map, unchanged")
|
|
1062
1065
|
nt.add_argument("--open", action="store_true", help="open the report when done")
|
|
1063
1066
|
en = sub.add_parser("enhance", help="re-apply hivey's layer (navbar, colours, info) to a report")
|
|
1064
1067
|
en.add_argument("folder", nargs="?", default=str(STATE / "reports" / "latest"))
|
|
1065
1068
|
op = sub.add_parser("open", help="open the latest report (builds the first one if there is none)")
|
|
1066
|
-
op.add_argument("--model", default="
|
|
1069
|
+
op.add_argument("--model", default="sonnet")
|
|
1067
1070
|
sc = sub.add_parser("schedule", help="the nightly launchd run: install | remove | status")
|
|
1068
1071
|
sc.add_argument("action", choices=["install", "remove", "status", "offer", "token"], nargs="?", default="status")
|
|
1069
1072
|
sc.add_argument("--command", help='token: the command printing the `claude setup-token` token, '
|
|
1070
1073
|
'e.g. "envsave get es_…" ("" = the normal claude login)')
|
|
1071
1074
|
sc.add_argument("--at", default="06:30", help="HH:MM, local time (default 06:30, after the night's jobs)")
|
|
1072
|
-
sc.add_argument("--model", default="
|
|
1075
|
+
sc.add_argument("--model", default="sonnet")
|
|
1073
1076
|
rf = sub.add_parser("refresh", help="new scan into the latest report's pages, no model (the Refresh button)")
|
|
1074
1077
|
rf.add_argument("--days", type=int, default=7)
|
|
1075
1078
|
sub.add_parser("serve", help="serve the report pages on 127.0.0.1 (`open` starts it)")
|
|
1079
|
+
of = sub.add_parser("office", help="the agent office: what every live agent does now (open | run)")
|
|
1080
|
+
of.add_argument("action", choices=["open", "run"], nargs="?", default="open")
|
|
1081
|
+
of.add_argument("--no-llm", action="store_true", help="run: summaries from the session recap, no model")
|
|
1082
|
+
of.add_argument("--model", default="sonnet")
|
|
1076
1083
|
cx = sub.add_parser("context", help="context window per agent: list, or set standard | 1M")
|
|
1077
1084
|
cx.add_argument("agents", nargs="*", help="agent names (as on the Sessions page) or folders")
|
|
1078
1085
|
cx.add_argument("--set", choices=["standard", "1M", "1m"], help="standard = 200k, compacts early; 1M = large")
|
|
@@ -1123,10 +1130,13 @@ def main() -> int:
|
|
|
1123
1130
|
return 0 if entry else 1
|
|
1124
1131
|
if a.cmd == "refresh":
|
|
1125
1132
|
import report
|
|
1126
|
-
return report.refresh(scan, a.days, "
|
|
1133
|
+
return report.refresh(scan, a.days, "sonnet")
|
|
1127
1134
|
if a.cmd == "serve":
|
|
1128
1135
|
import serve
|
|
1129
1136
|
return serve.serve()
|
|
1137
|
+
if a.cmd == "office":
|
|
1138
|
+
import office
|
|
1139
|
+
return office.open_page(a.model) if a.action == "open" else office.run(a.model, not a.no_llm)
|
|
1130
1140
|
if a.cmd == "context":
|
|
1131
1141
|
return context_cmd(a.agents, a.set)
|
|
1132
1142
|
if a.cmd == "link":
|
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BackSide,
|
|
3
|
+
Color,
|
|
4
|
+
ShaderMaterial,
|
|
5
|
+
UniformsLib,
|
|
6
|
+
UniformsUtils
|
|
7
|
+
} from './three.module.min.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Reference: https://en.wikipedia.org/wiki/Cel_shading
|
|
11
|
+
*
|
|
12
|
+
* API
|
|
13
|
+
*
|
|
14
|
+
* 1. Traditional
|
|
15
|
+
*
|
|
16
|
+
* const effect = new OutlineEffect( renderer );
|
|
17
|
+
*
|
|
18
|
+
* function render() {
|
|
19
|
+
*
|
|
20
|
+
* effect.render( scene, camera );
|
|
21
|
+
*
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* 2. VR compatible
|
|
25
|
+
*
|
|
26
|
+
* const effect = new OutlineEffect( renderer );
|
|
27
|
+
* let renderingOutline = false;
|
|
28
|
+
*
|
|
29
|
+
* scene.onAfterRender = function () {
|
|
30
|
+
*
|
|
31
|
+
* if ( renderingOutline ) return;
|
|
32
|
+
*
|
|
33
|
+
* renderingOutline = true;
|
|
34
|
+
*
|
|
35
|
+
* effect.renderOutline( scene, camera );
|
|
36
|
+
*
|
|
37
|
+
* renderingOutline = false;
|
|
38
|
+
*
|
|
39
|
+
* };
|
|
40
|
+
*
|
|
41
|
+
* function render() {
|
|
42
|
+
*
|
|
43
|
+
* renderer.render( scene, camera );
|
|
44
|
+
*
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* // How to set default outline parameters
|
|
48
|
+
* new OutlineEffect( renderer, {
|
|
49
|
+
* defaultThickness: 0.01,
|
|
50
|
+
* defaultColor: [ 0, 0, 0 ],
|
|
51
|
+
* defaultAlpha: 0.8,
|
|
52
|
+
* defaultKeepAlive: true // keeps outline material in cache even if material is removed from scene
|
|
53
|
+
* } );
|
|
54
|
+
*
|
|
55
|
+
* // How to set outline parameters for each material
|
|
56
|
+
* material.userData.outlineParameters = {
|
|
57
|
+
* thickness: 0.01,
|
|
58
|
+
* color: [ 0, 0, 0 ],
|
|
59
|
+
* alpha: 0.8,
|
|
60
|
+
* visible: true,
|
|
61
|
+
* keepAlive: true
|
|
62
|
+
* };
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
class OutlineEffect {
|
|
66
|
+
|
|
67
|
+
constructor( renderer, parameters = {} ) {
|
|
68
|
+
|
|
69
|
+
this.enabled = true;
|
|
70
|
+
|
|
71
|
+
const defaultThickness = parameters.defaultThickness !== undefined ? parameters.defaultThickness : 0.003;
|
|
72
|
+
const defaultColor = new Color().fromArray( parameters.defaultColor !== undefined ? parameters.defaultColor : [ 0, 0, 0 ] );
|
|
73
|
+
const defaultAlpha = parameters.defaultAlpha !== undefined ? parameters.defaultAlpha : 1.0;
|
|
74
|
+
const defaultKeepAlive = parameters.defaultKeepAlive !== undefined ? parameters.defaultKeepAlive : false;
|
|
75
|
+
|
|
76
|
+
// object.material.uuid -> outlineMaterial or
|
|
77
|
+
// object.material[ n ].uuid -> outlineMaterial
|
|
78
|
+
// save at the outline material creation and release
|
|
79
|
+
// if it's unused removeThresholdCount frames
|
|
80
|
+
// unless keepAlive is true.
|
|
81
|
+
const cache = {};
|
|
82
|
+
|
|
83
|
+
const removeThresholdCount = 60;
|
|
84
|
+
|
|
85
|
+
// outlineMaterial.uuid -> object.material or
|
|
86
|
+
// outlineMaterial.uuid -> object.material[ n ]
|
|
87
|
+
// save before render and release after render.
|
|
88
|
+
const originalMaterials = {};
|
|
89
|
+
|
|
90
|
+
// object.uuid -> originalOnBeforeRender
|
|
91
|
+
// save before render and release after render.
|
|
92
|
+
const originalOnBeforeRenders = {};
|
|
93
|
+
|
|
94
|
+
//this.cache = cache; // for debug
|
|
95
|
+
|
|
96
|
+
const uniformsOutline = {
|
|
97
|
+
outlineThickness: { value: defaultThickness },
|
|
98
|
+
outlineColor: { value: defaultColor },
|
|
99
|
+
outlineAlpha: { value: defaultAlpha }
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const vertexShader = [
|
|
103
|
+
'#include <common>',
|
|
104
|
+
'#include <uv_pars_vertex>',
|
|
105
|
+
'#include <displacementmap_pars_vertex>',
|
|
106
|
+
'#include <fog_pars_vertex>',
|
|
107
|
+
'#include <morphtarget_pars_vertex>',
|
|
108
|
+
'#include <skinning_pars_vertex>',
|
|
109
|
+
'#include <logdepthbuf_pars_vertex>',
|
|
110
|
+
'#include <clipping_planes_pars_vertex>',
|
|
111
|
+
|
|
112
|
+
'uniform float outlineThickness;',
|
|
113
|
+
|
|
114
|
+
'vec4 calculateOutline( vec4 pos, vec3 normal, vec4 skinned ) {',
|
|
115
|
+
' float thickness = outlineThickness;',
|
|
116
|
+
' const float ratio = 1.0;', // TODO: support outline thickness ratio for each vertex
|
|
117
|
+
' vec4 pos2 = projectionMatrix * modelViewMatrix * vec4( skinned.xyz + normal, 1.0 );',
|
|
118
|
+
// NOTE: subtract pos2 from pos because BackSide objectNormal is negative
|
|
119
|
+
' vec4 norm = normalize( pos - pos2 );',
|
|
120
|
+
' return pos + norm * thickness * pos.w * ratio;',
|
|
121
|
+
'}',
|
|
122
|
+
|
|
123
|
+
'void main() {',
|
|
124
|
+
|
|
125
|
+
' #include <uv_vertex>',
|
|
126
|
+
|
|
127
|
+
' #include <beginnormal_vertex>',
|
|
128
|
+
' #include <morphnormal_vertex>',
|
|
129
|
+
' #include <skinbase_vertex>',
|
|
130
|
+
' #include <skinnormal_vertex>',
|
|
131
|
+
|
|
132
|
+
' #include <begin_vertex>',
|
|
133
|
+
' #include <morphtarget_vertex>',
|
|
134
|
+
' #include <skinning_vertex>',
|
|
135
|
+
' #include <displacementmap_vertex>',
|
|
136
|
+
' #include <project_vertex>',
|
|
137
|
+
|
|
138
|
+
' vec3 outlineNormal = - objectNormal;', // the outline material is always rendered with BackSide
|
|
139
|
+
|
|
140
|
+
' gl_Position = calculateOutline( gl_Position, outlineNormal, vec4( transformed, 1.0 ) );',
|
|
141
|
+
|
|
142
|
+
' #include <logdepthbuf_vertex>',
|
|
143
|
+
' #include <clipping_planes_vertex>',
|
|
144
|
+
' #include <fog_vertex>',
|
|
145
|
+
|
|
146
|
+
'}',
|
|
147
|
+
|
|
148
|
+
].join( '\n' );
|
|
149
|
+
|
|
150
|
+
const fragmentShader = [
|
|
151
|
+
|
|
152
|
+
'#include <common>',
|
|
153
|
+
'#include <fog_pars_fragment>',
|
|
154
|
+
'#include <logdepthbuf_pars_fragment>',
|
|
155
|
+
'#include <clipping_planes_pars_fragment>',
|
|
156
|
+
|
|
157
|
+
'uniform vec3 outlineColor;',
|
|
158
|
+
'uniform float outlineAlpha;',
|
|
159
|
+
|
|
160
|
+
'void main() {',
|
|
161
|
+
|
|
162
|
+
' #include <clipping_planes_fragment>',
|
|
163
|
+
' #include <logdepthbuf_fragment>',
|
|
164
|
+
|
|
165
|
+
' gl_FragColor = vec4( outlineColor, outlineAlpha );',
|
|
166
|
+
|
|
167
|
+
' #include <tonemapping_fragment>',
|
|
168
|
+
' #include <colorspace_fragment>',
|
|
169
|
+
' #include <fog_fragment>',
|
|
170
|
+
' #include <premultiplied_alpha_fragment>',
|
|
171
|
+
|
|
172
|
+
'}'
|
|
173
|
+
|
|
174
|
+
].join( '\n' );
|
|
175
|
+
|
|
176
|
+
function createMaterial() {
|
|
177
|
+
|
|
178
|
+
return new ShaderMaterial( {
|
|
179
|
+
type: 'OutlineEffect',
|
|
180
|
+
uniforms: UniformsUtils.merge( [
|
|
181
|
+
UniformsLib[ 'fog' ],
|
|
182
|
+
UniformsLib[ 'displacementmap' ],
|
|
183
|
+
uniformsOutline
|
|
184
|
+
] ),
|
|
185
|
+
vertexShader: vertexShader,
|
|
186
|
+
fragmentShader: fragmentShader,
|
|
187
|
+
side: BackSide
|
|
188
|
+
} );
|
|
189
|
+
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function getOutlineMaterialFromCache( originalMaterial ) {
|
|
193
|
+
|
|
194
|
+
let data = cache[ originalMaterial.uuid ];
|
|
195
|
+
|
|
196
|
+
if ( data === undefined ) {
|
|
197
|
+
|
|
198
|
+
data = {
|
|
199
|
+
material: createMaterial(),
|
|
200
|
+
used: true,
|
|
201
|
+
keepAlive: defaultKeepAlive,
|
|
202
|
+
count: 0
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
cache[ originalMaterial.uuid ] = data;
|
|
206
|
+
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
data.used = true;
|
|
210
|
+
|
|
211
|
+
return data.material;
|
|
212
|
+
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function getOutlineMaterial( originalMaterial ) {
|
|
216
|
+
|
|
217
|
+
const outlineMaterial = getOutlineMaterialFromCache( originalMaterial );
|
|
218
|
+
|
|
219
|
+
originalMaterials[ outlineMaterial.uuid ] = originalMaterial;
|
|
220
|
+
|
|
221
|
+
updateOutlineMaterial( outlineMaterial, originalMaterial );
|
|
222
|
+
|
|
223
|
+
return outlineMaterial;
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function isCompatible( object ) {
|
|
228
|
+
|
|
229
|
+
const geometry = object.geometry;
|
|
230
|
+
const hasNormals = ( geometry !== undefined ) && ( geometry.attributes.normal !== undefined );
|
|
231
|
+
|
|
232
|
+
return ( object.isMesh === true && object.material !== undefined && hasNormals === true );
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function setOutlineMaterial( object ) {
|
|
237
|
+
|
|
238
|
+
if ( isCompatible( object ) === false ) return;
|
|
239
|
+
|
|
240
|
+
if ( Array.isArray( object.material ) ) {
|
|
241
|
+
|
|
242
|
+
for ( let i = 0, il = object.material.length; i < il; i ++ ) {
|
|
243
|
+
|
|
244
|
+
object.material[ i ] = getOutlineMaterial( object.material[ i ] );
|
|
245
|
+
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
} else {
|
|
249
|
+
|
|
250
|
+
object.material = getOutlineMaterial( object.material );
|
|
251
|
+
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
originalOnBeforeRenders[ object.uuid ] = object.onBeforeRender;
|
|
255
|
+
object.onBeforeRender = onBeforeRender;
|
|
256
|
+
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function restoreOriginalMaterial( object ) {
|
|
260
|
+
|
|
261
|
+
if ( isCompatible( object ) === false ) return;
|
|
262
|
+
|
|
263
|
+
if ( Array.isArray( object.material ) ) {
|
|
264
|
+
|
|
265
|
+
for ( let i = 0, il = object.material.length; i < il; i ++ ) {
|
|
266
|
+
|
|
267
|
+
object.material[ i ] = originalMaterials[ object.material[ i ].uuid ];
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
} else {
|
|
272
|
+
|
|
273
|
+
object.material = originalMaterials[ object.material.uuid ];
|
|
274
|
+
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
object.onBeforeRender = originalOnBeforeRenders[ object.uuid ];
|
|
278
|
+
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function onBeforeRender( renderer, scene, camera, geometry, material ) {
|
|
282
|
+
|
|
283
|
+
const originalMaterial = originalMaterials[ material.uuid ];
|
|
284
|
+
|
|
285
|
+
// just in case
|
|
286
|
+
if ( originalMaterial === undefined ) return;
|
|
287
|
+
|
|
288
|
+
updateUniforms( material, originalMaterial );
|
|
289
|
+
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function updateUniforms( material, originalMaterial ) {
|
|
293
|
+
|
|
294
|
+
const outlineParameters = originalMaterial.userData.outlineParameters;
|
|
295
|
+
|
|
296
|
+
material.uniforms.outlineAlpha.value = originalMaterial.opacity;
|
|
297
|
+
|
|
298
|
+
if ( outlineParameters !== undefined ) {
|
|
299
|
+
|
|
300
|
+
if ( outlineParameters.thickness !== undefined ) material.uniforms.outlineThickness.value = outlineParameters.thickness;
|
|
301
|
+
if ( outlineParameters.color !== undefined ) material.uniforms.outlineColor.value.fromArray( outlineParameters.color );
|
|
302
|
+
if ( outlineParameters.alpha !== undefined ) material.uniforms.outlineAlpha.value = outlineParameters.alpha;
|
|
303
|
+
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if ( originalMaterial.displacementMap ) {
|
|
307
|
+
|
|
308
|
+
material.uniforms.displacementMap.value = originalMaterial.displacementMap;
|
|
309
|
+
material.uniforms.displacementScale.value = originalMaterial.displacementScale;
|
|
310
|
+
material.uniforms.displacementBias.value = originalMaterial.displacementBias;
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function updateOutlineMaterial( material, originalMaterial ) {
|
|
317
|
+
|
|
318
|
+
if ( material.name === 'invisible' ) return;
|
|
319
|
+
|
|
320
|
+
const outlineParameters = originalMaterial.userData.outlineParameters;
|
|
321
|
+
|
|
322
|
+
material.fog = originalMaterial.fog;
|
|
323
|
+
material.toneMapped = originalMaterial.toneMapped;
|
|
324
|
+
material.premultipliedAlpha = originalMaterial.premultipliedAlpha;
|
|
325
|
+
material.displacementMap = originalMaterial.displacementMap;
|
|
326
|
+
|
|
327
|
+
if ( outlineParameters !== undefined ) {
|
|
328
|
+
|
|
329
|
+
if ( originalMaterial.visible === false ) {
|
|
330
|
+
|
|
331
|
+
material.visible = false;
|
|
332
|
+
|
|
333
|
+
} else {
|
|
334
|
+
|
|
335
|
+
material.visible = ( outlineParameters.visible !== undefined ) ? outlineParameters.visible : true;
|
|
336
|
+
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
material.transparent = ( outlineParameters.alpha !== undefined && outlineParameters.alpha < 1.0 ) ? true : originalMaterial.transparent;
|
|
340
|
+
|
|
341
|
+
if ( outlineParameters.keepAlive !== undefined ) cache[ originalMaterial.uuid ].keepAlive = outlineParameters.keepAlive;
|
|
342
|
+
|
|
343
|
+
} else {
|
|
344
|
+
|
|
345
|
+
material.transparent = originalMaterial.transparent;
|
|
346
|
+
material.visible = originalMaterial.visible;
|
|
347
|
+
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if ( originalMaterial.wireframe === true || originalMaterial.depthTest === false ) material.visible = false;
|
|
351
|
+
|
|
352
|
+
if ( originalMaterial.clippingPlanes ) {
|
|
353
|
+
|
|
354
|
+
material.clipping = true;
|
|
355
|
+
|
|
356
|
+
material.clippingPlanes = originalMaterial.clippingPlanes;
|
|
357
|
+
material.clipIntersection = originalMaterial.clipIntersection;
|
|
358
|
+
material.clipShadows = originalMaterial.clipShadows;
|
|
359
|
+
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
material.version = originalMaterial.version; // update outline material if necessary
|
|
363
|
+
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function cleanupCache() {
|
|
367
|
+
|
|
368
|
+
let keys;
|
|
369
|
+
|
|
370
|
+
// clear originialMaterials
|
|
371
|
+
keys = Object.keys( originalMaterials );
|
|
372
|
+
|
|
373
|
+
for ( let i = 0, il = keys.length; i < il; i ++ ) {
|
|
374
|
+
|
|
375
|
+
originalMaterials[ keys[ i ] ] = undefined;
|
|
376
|
+
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// clear originalOnBeforeRenders
|
|
380
|
+
keys = Object.keys( originalOnBeforeRenders );
|
|
381
|
+
|
|
382
|
+
for ( let i = 0, il = keys.length; i < il; i ++ ) {
|
|
383
|
+
|
|
384
|
+
originalOnBeforeRenders[ keys[ i ] ] = undefined;
|
|
385
|
+
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// remove unused outlineMaterial from cache
|
|
389
|
+
keys = Object.keys( cache );
|
|
390
|
+
|
|
391
|
+
for ( let i = 0, il = keys.length; i < il; i ++ ) {
|
|
392
|
+
|
|
393
|
+
const key = keys[ i ];
|
|
394
|
+
|
|
395
|
+
if ( cache[ key ].used === false ) {
|
|
396
|
+
|
|
397
|
+
cache[ key ].count ++;
|
|
398
|
+
|
|
399
|
+
if ( cache[ key ].keepAlive === false && cache[ key ].count > removeThresholdCount ) {
|
|
400
|
+
|
|
401
|
+
delete cache[ key ];
|
|
402
|
+
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
} else {
|
|
406
|
+
|
|
407
|
+
cache[ key ].used = false;
|
|
408
|
+
cache[ key ].count = 0;
|
|
409
|
+
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
this.render = function ( scene, camera ) {
|
|
417
|
+
|
|
418
|
+
if ( this.enabled === false ) {
|
|
419
|
+
|
|
420
|
+
renderer.render( scene, camera );
|
|
421
|
+
return;
|
|
422
|
+
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const currentAutoClear = renderer.autoClear;
|
|
426
|
+
renderer.autoClear = this.autoClear;
|
|
427
|
+
|
|
428
|
+
renderer.render( scene, camera );
|
|
429
|
+
|
|
430
|
+
renderer.autoClear = currentAutoClear;
|
|
431
|
+
|
|
432
|
+
this.renderOutline( scene, camera );
|
|
433
|
+
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
this.renderOutline = function ( scene, camera ) {
|
|
437
|
+
|
|
438
|
+
const currentAutoClear = renderer.autoClear;
|
|
439
|
+
const currentSceneAutoUpdate = scene.matrixWorldAutoUpdate;
|
|
440
|
+
const currentSceneBackground = scene.background;
|
|
441
|
+
const currentShadowMapEnabled = renderer.shadowMap.enabled;
|
|
442
|
+
|
|
443
|
+
scene.matrixWorldAutoUpdate = false;
|
|
444
|
+
scene.background = null;
|
|
445
|
+
renderer.autoClear = false;
|
|
446
|
+
renderer.shadowMap.enabled = false;
|
|
447
|
+
|
|
448
|
+
scene.traverse( setOutlineMaterial );
|
|
449
|
+
|
|
450
|
+
renderer.render( scene, camera );
|
|
451
|
+
|
|
452
|
+
scene.traverse( restoreOriginalMaterial );
|
|
453
|
+
|
|
454
|
+
cleanupCache();
|
|
455
|
+
|
|
456
|
+
scene.matrixWorldAutoUpdate = currentSceneAutoUpdate;
|
|
457
|
+
scene.background = currentSceneBackground;
|
|
458
|
+
renderer.autoClear = currentAutoClear;
|
|
459
|
+
renderer.shadowMap.enabled = currentShadowMapEnabled;
|
|
460
|
+
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
/*
|
|
464
|
+
* See #9918
|
|
465
|
+
*
|
|
466
|
+
* The following property copies and wrapper methods enable
|
|
467
|
+
* OutlineEffect to be called from other *Effect, like
|
|
468
|
+
*
|
|
469
|
+
* effect = new StereoEffect( new OutlineEffect( renderer ) );
|
|
470
|
+
*
|
|
471
|
+
* function render () {
|
|
472
|
+
*
|
|
473
|
+
* effect.render( scene, camera );
|
|
474
|
+
*
|
|
475
|
+
* }
|
|
476
|
+
*/
|
|
477
|
+
this.autoClear = renderer.autoClear;
|
|
478
|
+
this.domElement = renderer.domElement;
|
|
479
|
+
this.shadowMap = renderer.shadowMap;
|
|
480
|
+
|
|
481
|
+
this.clear = function ( color, depth, stencil ) {
|
|
482
|
+
|
|
483
|
+
renderer.clear( color, depth, stencil );
|
|
484
|
+
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
this.getPixelRatio = function () {
|
|
488
|
+
|
|
489
|
+
return renderer.getPixelRatio();
|
|
490
|
+
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
this.setPixelRatio = function ( value ) {
|
|
494
|
+
|
|
495
|
+
renderer.setPixelRatio( value );
|
|
496
|
+
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
this.getSize = function ( target ) {
|
|
500
|
+
|
|
501
|
+
return renderer.getSize( target );
|
|
502
|
+
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
this.setSize = function ( width, height, updateStyle ) {
|
|
506
|
+
|
|
507
|
+
renderer.setSize( width, height, updateStyle );
|
|
508
|
+
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
this.setViewport = function ( x, y, width, height ) {
|
|
512
|
+
|
|
513
|
+
renderer.setViewport( x, y, width, height );
|
|
514
|
+
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
this.setScissor = function ( x, y, width, height ) {
|
|
518
|
+
|
|
519
|
+
renderer.setScissor( x, y, width, height );
|
|
520
|
+
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
this.setScissorTest = function ( boolean ) {
|
|
524
|
+
|
|
525
|
+
renderer.setScissorTest( boolean );
|
|
526
|
+
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
this.setRenderTarget = function ( renderTarget ) {
|
|
530
|
+
|
|
531
|
+
renderer.setRenderTarget( renderTarget );
|
|
532
|
+
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
export { OutlineEffect };
|