wip: adaptive roughness

This commit is contained in:
dwelle 2023-04-09 19:52:18 +02:00
parent b885d87bc5
commit 0f32b7c1ef

View File

@ -389,6 +389,16 @@ export const setShapeForElement = <T extends ExcalidrawElement>(
export const invalidateShapeForElement = (element: ExcalidrawElement) =>
shapeCache.delete(element);
function adjustRoughness(size: number, roughness: number): number {
if (size >= 50) {
return roughness;
}
const factor = 2 + (50 - size) / 10;
// console.log({ ret: roughness / factor, roughness, factor, size });
return roughness / factor;
}
export const generateRoughOptions = (
element: ExcalidrawElement,
continuousPath = false,
@ -415,7 +425,10 @@ export const generateRoughOptions = (
// calculate them (and we don't want the fills to be modified)
fillWeight: element.strokeWidth / 2,
hachureGap: element.strokeWidth * 4,
roughness: element.roughness,
roughness: adjustRoughness(
Math.min(element.width, element.height),
element.roughness,
),
stroke: element.strokeColor,
preserveVertices: continuousPath,
};