Kaynağa Gözat

wip: adaptive roughness

dwelle 2 yıl önce
ebeveyn
işleme
0f32b7c1ef
1 değiştirilmiş dosya ile 14 ekleme ve 1 silme
  1. 14 1
      src/renderer/renderElement.ts

+ 14 - 1
src/renderer/renderElement.ts

@@ -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,
   };