@pretty-chitty/core 1.2.15 → 1.2.17
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/dist/components/DemoWrapper.js +1 -1
- package/dist/components/DemoWrapper.js.map +1 -1
- package/dist/components/Gallery/GalleryViewer.d.ts.map +1 -1
- package/dist/components/Gallery/GalleryViewer.js +7 -2
- package/dist/components/Gallery/GalleryViewer.js.map +1 -1
- package/dist/components/SparkLineChart.d.ts.map +1 -1
- package/dist/components/SparkLineChart.js +37 -64
- package/dist/components/SparkLineChart.js.map +1 -1
- package/dist/components/Viewer.d.ts.map +1 -1
- package/dist/components/Viewer.js +12 -2
- package/dist/components/Viewer.js.map +1 -1
- package/dist/game/Chit.js +1 -1
- package/dist/game/Chit.js.map +1 -1
- package/dist/game/Game.d.ts +6 -0
- package/dist/game/Game.d.ts.map +1 -1
- package/dist/game/badAiTransport/BadAIClientPrompts.d.ts +3 -1
- package/dist/game/badAiTransport/BadAIClientPrompts.d.ts.map +1 -1
- package/dist/game/badAiTransport/BadAIClientPrompts.js +11 -5
- package/dist/game/badAiTransport/BadAIClientPrompts.js.map +1 -1
- package/dist/hooks/useWebGlRenderer.d.ts.map +1 -1
- package/dist/hooks/useWebGlRenderer.js +23 -2
- package/dist/hooks/useWebGlRenderer.js.map +1 -1
- package/dist/rendering/CameraWrapperPerspective.d.ts.map +1 -1
- package/dist/rendering/CameraWrapperPerspective.js +10 -5
- package/dist/rendering/CameraWrapperPerspective.js.map +1 -1
- package/dist/rendering/LightWrapper.d.ts.map +1 -1
- package/dist/rendering/LightWrapper.js +14 -1
- package/dist/rendering/LightWrapper.js.map +1 -1
- package/dist/rendering/outline/EffectComposer.js +9 -5
- package/dist/rendering/outline/EffectComposer.js.map +1 -1
- package/package.json +1 -1
- package/src/library/components/DemoWrapper.tsx +1 -1
- package/src/library/components/Gallery/GalleryViewer.tsx +7 -2
- package/src/library/components/SparkLineChart.tsx +65 -104
- package/src/library/components/Viewer.tsx +11 -2
- package/src/library/game/Chit.ts +1 -1
- package/src/library/game/Game.ts +7 -0
- package/src/library/game/badAiTransport/BadAIClientPrompts.ts +17 -5
- package/src/library/hooks/useWebGlRenderer.tsx +25 -2
- package/src/library/rendering/CameraWrapperPerspective.ts +10 -5
- package/src/library/rendering/LightWrapper.ts +20 -1
- package/src/library/rendering/outline/EffectComposer.ts +4 -4
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useMemo } from "react";
|
|
2
2
|
import { Box, Typography } from "@mui/material";
|
|
3
|
+
import Color from "color";
|
|
3
4
|
import { SparkChit } from "../game/SparkChit";
|
|
4
5
|
import { PlayerChit } from "../game/PlayerChit";
|
|
5
6
|
|
|
@@ -29,65 +30,30 @@ interface SparkLineChartProps {
|
|
|
29
30
|
|
|
30
31
|
const HALO_OPACITY = 0.35;
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
r: toLin(parseInt(hex.slice(0, 2), 16)),
|
|
40
|
-
g: toLin(parseInt(hex.slice(2, 4), 16)),
|
|
41
|
-
b: toLin(parseInt(hex.slice(4, 6), 16)),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function getColorLuminance(color: string): number {
|
|
46
|
-
const { r, g, b } = hexToLinearRgb(color);
|
|
47
|
-
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Convert sRGB hex → CIE Lab (D65), so we can measure perceptual distance.
|
|
51
|
-
function hexToLab(color: string): { L: number; a: number; b: number } {
|
|
52
|
-
const { r, g, b } = hexToLinearRgb(color);
|
|
53
|
-
const X = (r * 0.4124564 + g * 0.3575761 + b * 0.1804375) / 0.95047;
|
|
54
|
-
const Y = r * 0.2126729 + g * 0.7151522 + b * 0.072175;
|
|
55
|
-
const Z = (r * 0.0193339 + g * 0.119192 + b * 0.9503041) / 1.08883;
|
|
56
|
-
const f = (t: number) => (t > 0.008856 ? Math.cbrt(t) : 7.787 * t + 16 / 116);
|
|
57
|
-
const fx = f(X);
|
|
58
|
-
const fy = f(Y);
|
|
59
|
-
const fz = f(Z);
|
|
60
|
-
return { L: 116 * fy - 16, a: 500 * (fx - fy), b: 200 * (fy - fz) };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Perceptual contrast: a stroke is only needed if both luminance AND hue/chroma
|
|
64
|
-
// are too close to distinguish. Pure red vs pure green have similar luminance
|
|
65
|
-
// but enormous Lab distance, so they should pass without an outline.
|
|
66
|
-
function hasGoodContrast(color1: string, color2: string): boolean {
|
|
67
|
-
const lum1 = getColorLuminance(color1);
|
|
68
|
-
const lum2 = getColorLuminance(color2);
|
|
69
|
-
const lumRatio = (Math.max(lum1, lum2) + 0.05) / (Math.min(lum1, lum2) + 0.05);
|
|
70
|
-
if (lumRatio >= 3) return true;
|
|
71
|
-
|
|
72
|
-
const lab1 = hexToLab(color1);
|
|
73
|
-
const lab2 = hexToLab(color2);
|
|
74
|
-
const dL = lab1.L - lab2.L;
|
|
75
|
-
const da = lab1.a - lab2.a;
|
|
76
|
-
const db = lab1.b - lab2.b;
|
|
77
|
-
const deltaE = Math.sqrt(dL * dL + da * da + db * db);
|
|
78
|
-
return deltaE >= 35;
|
|
33
|
+
// One halo color for every line in the chart, picked as the extreme furthest
|
|
34
|
+
// from the bg — so the halo is always visible against the bg and provides the
|
|
35
|
+
// edge that separates each line from the bg. Per-line halos flipping between
|
|
36
|
+
// black and white read as arbitrary noise.
|
|
37
|
+
function getUnifiedHaloColor(backgroundColor: string): string {
|
|
38
|
+
return Color(backgroundColor).isLight() ? "#000000" : "#ffffff";
|
|
79
39
|
}
|
|
80
40
|
|
|
81
|
-
// The halo
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
|
|
41
|
+
// The halo only does its job when every line clearly contrasts against it —
|
|
42
|
+
// otherwise a dark line drowns into the dark halo and you get fuzz instead of
|
|
43
|
+
// a crisp edge. Push any too-close line toward the halo's opposite (which is
|
|
44
|
+
// also the bg side) in 5% steps until WCAG luminance contrast clears the
|
|
45
|
+
// threshold. This is the "lighten the dark line until it's distinguishable"
|
|
46
|
+
// step — only the dark-red-burger gets touched in a sea of light pastels.
|
|
47
|
+
function adjustLineForHalo(lineColor: string, haloColor: string, minRatio = 7): string {
|
|
48
|
+
const halo = Color(haloColor);
|
|
49
|
+
const line = Color(lineColor);
|
|
50
|
+
if (line.contrast(halo) >= minRatio) return line.hex();
|
|
51
|
+
const target = halo.isDark() ? Color("#ffffff") : Color("#000000");
|
|
52
|
+
for (let t = 0.05; t <= 1; t += 0.05) {
|
|
53
|
+
const candidate = line.mix(target, t);
|
|
54
|
+
if (candidate.contrast(halo) >= minRatio) return candidate.hex();
|
|
55
|
+
}
|
|
56
|
+
return target.hex();
|
|
91
57
|
}
|
|
92
58
|
|
|
93
59
|
export function SparkLineChart({
|
|
@@ -202,9 +168,15 @@ export function SparkLineChart({
|
|
|
202
168
|
const getY = (value: number) => chartHeight - ((value - chartMinValue) / chartValueRange) * chartHeight;
|
|
203
169
|
const chartEndX = chartWidth;
|
|
204
170
|
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
|
|
171
|
+
// The chart always gets one unified halo (opposite of bg). Each line is then
|
|
172
|
+
// shifted only if it sits too close to the halo's luminance — so on a light
|
|
173
|
+
// bg the halo is dark, all the light pastels keep their hue, and the lone
|
|
174
|
+
// dark line gets lightened until the dark halo can actually frame it.
|
|
175
|
+
const haloColor = getUnifiedHaloColor(backgroundColor);
|
|
176
|
+
const displayLines = lines.map((line) => ({
|
|
177
|
+
...line,
|
|
178
|
+
color: adjustLineForHalo(line.color, haloColor),
|
|
179
|
+
}));
|
|
208
180
|
|
|
209
181
|
return (
|
|
210
182
|
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "center", my: 4 }}>
|
|
@@ -237,7 +209,7 @@ export function SparkLineChart({
|
|
|
237
209
|
</g>
|
|
238
210
|
|
|
239
211
|
{/* Draw each line */}
|
|
240
|
-
{
|
|
212
|
+
{displayLines.map((line) => {
|
|
241
213
|
// Step interpolation: values change instantaneously in the game (e.g. $0 → $50
|
|
242
214
|
// at t=100), so hold the previous value until the new clock, then jump vertically.
|
|
243
215
|
const pathData = line.points
|
|
@@ -255,28 +227,21 @@ export function SparkLineChart({
|
|
|
255
227
|
const lastY = getY(lastPoint.value);
|
|
256
228
|
const extendedPathData = `${pathData} L ${chartEndX} ${lastY}`;
|
|
257
229
|
|
|
258
|
-
// All lines get the same halo treatment if any line needs one — picked
|
|
259
|
-
// per line so each gets the right black/white for its own color.
|
|
260
|
-
const needsStroke = anyNeedsStroke;
|
|
261
|
-
const strokeColor = needsStroke ? getStrokeColor(line.color, backgroundColor) : undefined;
|
|
262
|
-
|
|
263
230
|
const adjustedLabelY = labelPositions[line.id];
|
|
264
231
|
|
|
265
232
|
return (
|
|
266
233
|
<g key={line.id}>
|
|
267
|
-
{/*
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
/>
|
|
279
|
-
)}
|
|
234
|
+
{/* Unified halo behind every line — soft glow opposite the bg. */}
|
|
235
|
+
<path
|
|
236
|
+
d={extendedPathData}
|
|
237
|
+
fill="none"
|
|
238
|
+
stroke={haloColor}
|
|
239
|
+
strokeWidth={6}
|
|
240
|
+
strokeLinecap="round"
|
|
241
|
+
strokeLinejoin="round"
|
|
242
|
+
filter="url(#sparkline-soften)"
|
|
243
|
+
opacity={HALO_OPACITY}
|
|
244
|
+
/>
|
|
280
245
|
<path
|
|
281
246
|
d={extendedPathData}
|
|
282
247
|
fill="none"
|
|
@@ -320,36 +285,32 @@ export function SparkLineChart({
|
|
|
320
285
|
|
|
321
286
|
{/* Final value label at the adjusted position */}
|
|
322
287
|
<g transform={`translate(${chartEndX + (line.icon ? 30 : 10)}, ${adjustedLabelY})`}>
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
</text>
|
|
336
|
-
)}
|
|
288
|
+
<text
|
|
289
|
+
fontSize={20}
|
|
290
|
+
fontWeight="bold"
|
|
291
|
+
dominantBaseline="middle"
|
|
292
|
+
fill={haloColor}
|
|
293
|
+
stroke={haloColor}
|
|
294
|
+
strokeWidth={5}
|
|
295
|
+
filter="url(#sparkline-soften)"
|
|
296
|
+
opacity={HALO_OPACITY}
|
|
297
|
+
>
|
|
298
|
+
{line.finalValue}
|
|
299
|
+
</text>
|
|
337
300
|
<text fill={line.color} fontSize={20} fontWeight="bold" dominantBaseline="middle">
|
|
338
301
|
{line.finalValue}
|
|
339
302
|
</text>
|
|
340
303
|
</g>
|
|
341
304
|
|
|
342
|
-
{/* End point marker */}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
/>
|
|
352
|
-
)}
|
|
305
|
+
{/* End point marker halo + dot */}
|
|
306
|
+
<circle
|
|
307
|
+
cx={chartEndX}
|
|
308
|
+
cy={lastY}
|
|
309
|
+
r={6}
|
|
310
|
+
fill={haloColor}
|
|
311
|
+
filter="url(#sparkline-soften)"
|
|
312
|
+
opacity={HALO_OPACITY}
|
|
313
|
+
/>
|
|
353
314
|
<circle cx={chartEndX} cy={lastY} r={3} fill={line.color} />
|
|
354
315
|
</g>
|
|
355
316
|
);
|
|
@@ -170,9 +170,10 @@ export default function Viewer({
|
|
|
170
170
|
rendererWrapper &&
|
|
171
171
|
(paused || prevRenderNextFrame === undefined || prevRenderNextFrame || chitRenderInstance.dirty)
|
|
172
172
|
) {
|
|
173
|
+
let drew: boolean | undefined;
|
|
173
174
|
if (!hardPaused) {
|
|
174
175
|
// Clear canvas and render
|
|
175
|
-
|
|
176
|
+
drew = rendererWrapper.render(chitRenderInstance.sceneWrapper, chitRenderInstance.camera, context, theme, id);
|
|
176
177
|
|
|
177
178
|
loadingState.setLoading(id, false);
|
|
178
179
|
|
|
@@ -189,7 +190,15 @@ export default function Viewer({
|
|
|
189
190
|
loadingState.setLoading(id, false);
|
|
190
191
|
}
|
|
191
192
|
|
|
192
|
-
|
|
193
|
+
// If render bailed, keep dirty=true so the next iteration retries.
|
|
194
|
+
// When paused, no rAF is queued, so schedule one explicitly.
|
|
195
|
+
if (drew === false) {
|
|
196
|
+
if (paused) {
|
|
197
|
+
requestSharedAnimationFrame(animate);
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
chitRenderInstance.resetDirty();
|
|
201
|
+
}
|
|
193
202
|
if (!hardPaused) {
|
|
194
203
|
timeState.setAnimationState(id, !paused);
|
|
195
204
|
}
|
package/src/library/game/Chit.ts
CHANGED
|
@@ -44,7 +44,7 @@ function wrapWithDirtyProxy(value: any, chit: Chit): any {
|
|
|
44
44
|
},
|
|
45
45
|
get(target, prop) {
|
|
46
46
|
const val = target[prop];
|
|
47
|
-
if (typeof val === "function") return val.bind(
|
|
47
|
+
if (typeof val === "function") return val.bind(proxy);
|
|
48
48
|
if (typeof val === "object" && val !== null && !(val instanceof Chit) && !(val instanceof OrderedOutlet)) {
|
|
49
49
|
return wrapWithDirtyProxy(val, chit);
|
|
50
50
|
}
|
package/src/library/game/Game.ts
CHANGED
|
@@ -54,4 +54,11 @@ export interface Game<P extends PlayerChit, R extends RootChit<P>> {
|
|
|
54
54
|
* @param spec
|
|
55
55
|
*/
|
|
56
56
|
renderDefaultRootChit?(spec: ChitRenderSpec): void;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Useful to help the bad AI demo pick more interesting picks. This function should return a multiplier for the weight of a given pick, where the weight is determined by the type of pick (e.g. ButtonPick is 1, ChitPick is the number of chits that can be picked, DragPick is the number of targets that can be dragged to). The picks parameter is the full list of picks available, and the pick parameter is the specific pick we are calculating the weight for.
|
|
60
|
+
* @param picks The list of available pickes
|
|
61
|
+
* @param pick the pick we are looking at
|
|
62
|
+
*/
|
|
63
|
+
demoPickWeight?(picks: any[], pick: any): number;
|
|
57
64
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Match } from "../..";
|
|
1
2
|
import { ClockDetails } from "../ClockDetails";
|
|
2
3
|
import { Connection } from "../Connection";
|
|
3
4
|
import { ConnectionObject } from "../ConnectionObject";
|
|
@@ -13,6 +14,7 @@ export class BadAIClientPrompts<P extends PlayerChit, R extends RootChit<P>> ext
|
|
|
13
14
|
constructor(
|
|
14
15
|
private playerId: string,
|
|
15
16
|
private connection: Connection,
|
|
17
|
+
private match: Match<P, R>,
|
|
16
18
|
) {
|
|
17
19
|
super();
|
|
18
20
|
|
|
@@ -25,11 +27,18 @@ export class BadAIClientPrompts<P extends PlayerChit, R extends RootChit<P>> ext
|
|
|
25
27
|
if (prompt.type === "PickPrompt") {
|
|
26
28
|
const picks = prompt.details.picks;
|
|
27
29
|
const weights = picks.map((p: any) => {
|
|
30
|
+
const multiplier = this.match.game.demoPickWeight ? this.match.game.demoPickWeight(picks, p) : 1;
|
|
28
31
|
switch (p.type as PickType) {
|
|
29
|
-
case "ButtonPick":
|
|
30
|
-
|
|
31
|
-
case "
|
|
32
|
-
|
|
32
|
+
case "ButtonPick":
|
|
33
|
+
return 1 * multiplier;
|
|
34
|
+
case "ChitPick":
|
|
35
|
+
return p.details.c.length * multiplier;
|
|
36
|
+
case "DragPick":
|
|
37
|
+
return (
|
|
38
|
+
(p.details.d as any[][]).reduce((sum: number, targets: any[]) => sum + targets.length, 0) * multiplier
|
|
39
|
+
);
|
|
40
|
+
default:
|
|
41
|
+
return 1 * multiplier;
|
|
33
42
|
}
|
|
34
43
|
});
|
|
35
44
|
const totalWeight = weights.reduce((sum: number, w: number) => sum + w, 0);
|
|
@@ -37,7 +46,10 @@ export class BadAIClientPrompts<P extends PlayerChit, R extends RootChit<P>> ext
|
|
|
37
46
|
let pickIndex = 0;
|
|
38
47
|
for (let i = 0; i < weights.length; i++) {
|
|
39
48
|
roll -= weights[i];
|
|
40
|
-
if (roll <= 0) {
|
|
49
|
+
if (roll <= 0) {
|
|
50
|
+
pickIndex = i;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
41
53
|
}
|
|
42
54
|
const pick = picks[pickIndex];
|
|
43
55
|
switch (pick.type as PickType) {
|
|
@@ -40,7 +40,7 @@ class WebGLRendererWrapper {
|
|
|
40
40
|
public readonly isWebGL2: boolean;
|
|
41
41
|
|
|
42
42
|
constructor() {
|
|
43
|
-
this.renderer = new WebGLRenderer({ alpha: true, antialias: true });
|
|
43
|
+
this.renderer = new WebGLRenderer({ alpha: true, antialias: true, preserveDrawingBuffer: true });
|
|
44
44
|
|
|
45
45
|
// Check if WebGL context is available
|
|
46
46
|
if (!this.renderer.getContext()) {
|
|
@@ -332,7 +332,7 @@ class WebGLRendererWrapper {
|
|
|
332
332
|
// happily call composer.render() on a dead context, produce no pixels, and
|
|
333
333
|
// strip the snapshot overlay → blank canvas until the user switches panels.
|
|
334
334
|
const gl = this.renderer.getContext();
|
|
335
|
-
if (gl
|
|
335
|
+
if (!gl || gl.isContextLost()) {
|
|
336
336
|
this.handleContextLost("silent");
|
|
337
337
|
return false;
|
|
338
338
|
}
|
|
@@ -357,9 +357,32 @@ class WebGLRendererWrapper {
|
|
|
357
357
|
this.renderer.setScissor(0, 0, targetWidth, targetHeight);
|
|
358
358
|
this.renderer.setViewport(0, 0, width, height);
|
|
359
359
|
|
|
360
|
+
// Clear *depth only* in this panel's scissor region before composer.render().
|
|
361
|
+
// All viewers share the same WebGL backbuffer (and thus its depth buffer).
|
|
362
|
+
// Each composer's OutputPass renders a fullscreen quad at the same NDC z,
|
|
363
|
+
// and the default depth func is LESS — so the second panel's quad fails
|
|
364
|
+
// depth-test against the first panel's quad and the fragment is discarded.
|
|
365
|
+
// The panel then "didn't render": the backbuffer keeps the previous panel's
|
|
366
|
+
// pixels in its region, and drawImage copies those into the wrong panel's
|
|
367
|
+
// 2D canvas. Clearing depth (but not color) lets the OutputPass actually
|
|
368
|
+
// write its real output without stomping on whatever fallback content might
|
|
369
|
+
// already be visible from a prior frame.
|
|
370
|
+
this.renderer.clear(false, true, false);
|
|
371
|
+
|
|
360
372
|
// Render using the composer
|
|
361
373
|
entry.composer.render(sceneWrapper, camera);
|
|
362
374
|
|
|
375
|
+
// Re-check for context loss after the render. The webglcontextlost event
|
|
376
|
+
// is dispatched asynchronously, so a loss that happened during composer.render
|
|
377
|
+
// wouldn't have been caught by the pre-render check above. If we proceeded to
|
|
378
|
+
// drawImage anyway, we'd copy stale pixels from the WebGL backbuffer (which
|
|
379
|
+
// is preserved across frames) and report success.
|
|
380
|
+
const glAfter = this.renderer.getContext();
|
|
381
|
+
if (!glAfter || glAfter.isContextLost()) {
|
|
382
|
+
this.handleContextLost("silent");
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
|
|
363
386
|
// Copy the rendered result to the 2D canvas
|
|
364
387
|
const webglCanvas = this.renderer.domElement;
|
|
365
388
|
context2d.drawImage(
|
|
@@ -566,7 +566,13 @@ export class CameraWrapperPerspective {
|
|
|
566
566
|
tween
|
|
567
567
|
.to(newPosition, duration)
|
|
568
568
|
.easing(Easing.Quadratic.InOut)
|
|
569
|
-
.onUpdate((obj) =>
|
|
569
|
+
.onUpdate((obj) => {
|
|
570
|
+
this.camera.position.set(obj.x, obj.y, obj.z);
|
|
571
|
+
const planes = this.calculateOptimalNearFar(this.bbox, this.camera.position);
|
|
572
|
+
this.camera.near = planes.near;
|
|
573
|
+
this.camera.far = planes.far;
|
|
574
|
+
this.camera.updateProjectionMatrix();
|
|
575
|
+
}),
|
|
570
576
|
);
|
|
571
577
|
}
|
|
572
578
|
|
|
@@ -581,8 +587,8 @@ export class CameraWrapperPerspective {
|
|
|
581
587
|
);
|
|
582
588
|
}
|
|
583
589
|
|
|
584
|
-
//
|
|
585
|
-
if (nearFarDistance > 0.001) {
|
|
590
|
+
// Only tween near/far independently when camera position isn't changing
|
|
591
|
+
if (positionDistance === 0 && nearFarDistance > 0.001) {
|
|
586
592
|
this.nearFarTween = this.chit.createTween({ near: currentNear, far: currentFar }, (tween) =>
|
|
587
593
|
tween
|
|
588
594
|
.to({ near: optimalPlanes.near, far: optimalPlanes.far }, duration)
|
|
@@ -593,8 +599,7 @@ export class CameraWrapperPerspective {
|
|
|
593
599
|
this.camera.updateProjectionMatrix();
|
|
594
600
|
}),
|
|
595
601
|
);
|
|
596
|
-
} else if (nearFarDistance > 0) {
|
|
597
|
-
// If difference is tiny, just set immediately
|
|
602
|
+
} else if (positionDistance === 0 && nearFarDistance > 0) {
|
|
598
603
|
this.camera.near = optimalPlanes.near;
|
|
599
604
|
this.camera.far = optimalPlanes.far;
|
|
600
605
|
this.camera.updateProjectionMatrix();
|
|
@@ -74,7 +74,6 @@ export class LightWrapper {
|
|
|
74
74
|
l.shadow.camera.right = 0.1;
|
|
75
75
|
l.shadow.camera.top = 0.1;
|
|
76
76
|
l.shadow.camera.bottom = -0.1;
|
|
77
|
-
l.shadow.camera.near = 0.000001;
|
|
78
77
|
this.group.add(l);
|
|
79
78
|
}
|
|
80
79
|
|
|
@@ -147,6 +146,26 @@ export class LightWrapper {
|
|
|
147
146
|
camera.right = Math.max(right, b.max.x);
|
|
148
147
|
camera.bottom = Math.min(bottom, b.min.y);
|
|
149
148
|
camera.top = Math.max(top, b.max.y);
|
|
149
|
+
|
|
150
|
+
const lDist = light.position.length();
|
|
151
|
+
if (lDist > 0) {
|
|
152
|
+
const lightDir = light.position.clone().normalize();
|
|
153
|
+
let minDepth = Infinity;
|
|
154
|
+
let maxDepth = -Infinity;
|
|
155
|
+
[this.bbox.min.x, this.bbox.max.x].forEach((x) =>
|
|
156
|
+
[this.bbox.min.y, this.bbox.max.y].forEach((y) =>
|
|
157
|
+
[this.bbox.min.z, this.bbox.max.z].forEach((z) => {
|
|
158
|
+
const depth = lDist - (x * lightDir.x + y * lightDir.y + z * lightDir.z);
|
|
159
|
+
minDepth = Math.min(minDepth, depth);
|
|
160
|
+
maxDepth = Math.max(maxDepth, depth);
|
|
161
|
+
}),
|
|
162
|
+
),
|
|
163
|
+
);
|
|
164
|
+
const margin = Math.max(1, (maxDepth - minDepth) * 0.1);
|
|
165
|
+
camera.near = Math.max(0.1, minDepth - margin);
|
|
166
|
+
camera.far = maxDepth + margin;
|
|
167
|
+
}
|
|
168
|
+
|
|
150
169
|
camera.updateProjectionMatrix();
|
|
151
170
|
}
|
|
152
171
|
}
|
|
@@ -69,7 +69,7 @@ export class EffectComposer {
|
|
|
69
69
|
Math.max(1, Math.floor(this._width * this._pixelRatio)),
|
|
70
70
|
Math.max(1, Math.floor(this._height * this._pixelRatio)),
|
|
71
71
|
);
|
|
72
|
-
|
|
72
|
+
if (renderer.capabilities.isWebGL2) renderTarget.depthTexture.type = FloatType;
|
|
73
73
|
|
|
74
74
|
this.renderTarget = renderTarget;
|
|
75
75
|
|
|
@@ -83,7 +83,7 @@ export class EffectComposer {
|
|
|
83
83
|
Math.max(1, Math.floor(this._width * this._pixelRatio)),
|
|
84
84
|
Math.max(1, Math.floor(this._height * this._pixelRatio)),
|
|
85
85
|
);
|
|
86
|
-
|
|
86
|
+
if (renderer.capabilities.isWebGL2) this.renderTarget2.depthTexture.type = FloatType;
|
|
87
87
|
|
|
88
88
|
this.copyPass = new ShaderPass(CopyShader, this.textureId);
|
|
89
89
|
}
|
|
@@ -166,13 +166,13 @@ export class EffectComposer {
|
|
|
166
166
|
if (this.renderTarget.depthTexture) {
|
|
167
167
|
this.renderTarget.depthTexture.dispose();
|
|
168
168
|
this.renderTarget.depthTexture = new DepthTexture(effectiveWidth, effectiveHeight);
|
|
169
|
-
|
|
169
|
+
if (this.renderer.capabilities.isWebGL2) this.renderTarget.depthTexture.type = FloatType;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
if (this.renderTarget2.depthTexture) {
|
|
173
173
|
this.renderTarget2.depthTexture.dispose();
|
|
174
174
|
this.renderTarget2.depthTexture = new DepthTexture(effectiveWidth, effectiveHeight);
|
|
175
|
-
|
|
175
|
+
if (this.renderer.capabilities.isWebGL2) this.renderTarget2.depthTexture.type = FloatType;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
for (let i = 0; i < this.passes.length; i++) {
|