sure
This commit is contained in:
parent
ced0ac56f3
commit
d6a8f898d1
27 changed files with 751 additions and 354 deletions
|
|
@ -2,7 +2,10 @@ import { vec2 } from 'gl-matrix';
|
|||
|
||||
import { GardenAudio } from '../audio/garden-audio';
|
||||
import { appConfig } from '../config';
|
||||
import { BrushPipeline } from '../pipelines/brush/brush-pipeline';
|
||||
import {
|
||||
BrushPipeline,
|
||||
getSafeDevicePixelRatio,
|
||||
} from '../pipelines/brush/brush-pipeline';
|
||||
import { EraserAgentPipeline } from '../pipelines/eraser/eraser-agent-pipeline';
|
||||
import { EraserTexturePipeline } from '../pipelines/eraser/eraser-texture-pipeline';
|
||||
import { activeVibe, settings } from '../settings';
|
||||
|
|
@ -201,7 +204,9 @@ export class GardenPointerInput {
|
|||
|
||||
private getCanvasPointerPosition(event: PointerEvent): vec2 {
|
||||
const rect = this.canvas.getBoundingClientRect();
|
||||
const devicePixelRatio = this.options.getDevicePixelRatio();
|
||||
const devicePixelRatio = getSafeDevicePixelRatio(
|
||||
this.options.getDevicePixelRatio()
|
||||
);
|
||||
return vec2.fromValues(
|
||||
(event.clientX - rect.left) * devicePixelRatio,
|
||||
(event.clientY - rect.top) * devicePixelRatio
|
||||
|
|
@ -213,7 +218,8 @@ export class GardenPointerInput {
|
|||
this.smoothedStrokePoints[this.smoothedStrokePoints.length - 1];
|
||||
if (
|
||||
previousSample !== undefined &&
|
||||
vec2.squaredDistance(previousSample, position) <= getBrushSmoothingDistanceSquared()
|
||||
vec2.squaredDistance(previousSample, position) <=
|
||||
getBrushSmoothingDistanceSquared(this.options.getDevicePixelRatio())
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -247,12 +253,13 @@ export class GardenPointerInput {
|
|||
|
||||
private addQuadraticBrushSegments(start: vec2, control: vec2, end: vec2): void {
|
||||
const curveLength = vec2.distance(start, control) + vec2.distance(control, end);
|
||||
const devicePixelRatio = getSafeDevicePixelRatio(this.options.getDevicePixelRatio());
|
||||
const brushRadius = Math.max(
|
||||
settings.brushCurveMinBrushRadius,
|
||||
settings.brushSize / 2
|
||||
settings.brushCurveMinBrushRadius * devicePixelRatio,
|
||||
(settings.brushSize * devicePixelRatio) / 2
|
||||
);
|
||||
const segmentSpacing = Math.max(
|
||||
settings.brushCurveMinSegmentSpacing,
|
||||
settings.brushCurveMinSegmentSpacing * devicePixelRatio,
|
||||
brushRadius * settings.brushCurveSegmentBrushRadiusRatio
|
||||
);
|
||||
const mirrorSegmentCount = Math.max(1, this.options.getMirrorSegmentCount());
|
||||
|
|
@ -292,7 +299,7 @@ export class GardenPointerInput {
|
|||
if (
|
||||
this.lastSmoothedBrushPosition !== null &&
|
||||
vec2.squaredDistance(this.lastSmoothedBrushPosition, finalSample) >
|
||||
getBrushSmoothingDistanceSquared()
|
||||
getBrushSmoothingDistanceSquared(this.options.getDevicePixelRatio())
|
||||
) {
|
||||
this.addMirroredBrushSegment(this.lastSmoothedBrushPosition, finalSample);
|
||||
}
|
||||
|
|
@ -374,11 +381,11 @@ const getBrushCurveResolution = (): number => {
|
|||
return Math.max(1, Math.floor(resolution));
|
||||
};
|
||||
|
||||
const getBrushSmoothingDistanceSquared = (): number => {
|
||||
const getBrushSmoothingDistanceSquared = (devicePixelRatio?: number): number => {
|
||||
const distance = Number.isFinite(settings.brushSmoothingMinSampleDistance)
|
||||
? settings.brushSmoothingMinSampleDistance
|
||||
: appConfig.defaultSettings.brushSmoothingMinSampleDistance;
|
||||
return Math.max(0, distance) ** 2;
|
||||
return Math.max(0, distance * getSafeDevicePixelRatio(devicePixelRatio)) ** 2;
|
||||
};
|
||||
|
||||
const isSamePointerSample = (left: PointerEvent, right: PointerEvent): boolean =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue