aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/apis/gpt/GPT.ts2
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx37
-rw-r--r--src/client/views/collections/collectionFreeForm/SmartDrawHandler.tsx27
3 files changed, 42 insertions, 24 deletions
diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts
index 5afb345a0..454ea8116 100644
--- a/src/client/apis/gpt/GPT.ts
+++ b/src/client/apis/gpt/GPT.ts
@@ -58,7 +58,7 @@ const callTypeMap: { [type: string]: GPTCallOpts } = {
model: 'gpt-4o',
maxTokens: 256,
temp: 0.5,
- prompt: 'Given an item to draw, generate a list of Bezier control points that will represent the item. Answer only with the list of coordinates and no additional text',
+ prompt: 'Given an item to draw, generate Bezier control points that will represent the item. Answer only with a list of lists of coordinates, where each list of coordinates is one Bezier ink stroke. Do not include any text, description, or comments.',
}
};
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 194c99c3d..d22b3569e 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -1233,23 +1233,26 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
@action
createDrawing = (e: PointerEvent, doubleTap?: boolean) => {
SmartDrawHandler.Instance.displaySmartDrawHandler(e.pageX, e.pageY);
- if (SmartDrawHandler.Instance.coords) {
- // const coords: InkData = SmartDrawHandler.Instance.coords;
- // const inkField = new InkField(coords);
- // const points = coords.map(p => intersect.inkView.ComponentView?.ptToScreen?.({ X: p.x, Y: p.y }) ?? { X: 0, Y: 0 })], [] as PointData[]);
- // const bounds = InkField.getBounds(points);
- // const B = this.screenToFreeformContentsXf.transformBounds(bounds.left, bounds.top, bounds.width, bounds.height);
- // const inkWidth = ActiveInkWidth() * this.ScreenToLocalBoxXf().Scale;
- // return Docs.Create.InkDocument(
- // points,
- // { title: 'stroke',
- // x: B.x - inkWidth / 2,
- // y: B.y - inkWidth / 2,
- // _width: B.width + inkWidth,
- // _height: B.height + inkWidth,
- // stroke_showLabel: BoolCast(Doc.UserDoc().activeInkHideTextLabels)}, // prettier-ignore
- // inkWidth
- // );
+ if (SmartDrawHandler.Instance.strokes.length > 0) {
+ const strokeList: InkData[] = SmartDrawHandler.Instance.strokes;
+ strokeList.forEach(coords => {
+ // const stroke = new InkField(coords);
+ // const points = coords.map(p => intersect.inkView.ComponentView?.ptToScreen?.({ X: p.X, Y: p.Y }) ?? { X: 0, Y: 0 }), [] as PointData[]);
+ const bounds = InkField.getBounds(coords);
+ const B = this.screenToFreeformContentsXf.transformBounds(bounds.left, bounds.top, bounds.width, bounds.height);
+ const inkWidth = ActiveInkWidth() * this.ScreenToLocalBoxXf().Scale;
+ const inkDoc = Docs.Create.InkDocument(
+ coords,
+ { title: 'stroke',
+ x: B.x - inkWidth / 2,
+ y: B.y - inkWidth / 2,
+ _width: B.width + inkWidth,
+ _height: B.height + inkWidth,
+ stroke_showLabel: BoolCast(Doc.UserDoc().activeInkHideTextLabels)}, // prettier-ignore
+ inkWidth
+ );
+ this.addDocument(inkDoc);
+ });
}
};
diff --git a/src/client/views/collections/collectionFreeForm/SmartDrawHandler.tsx b/src/client/views/collections/collectionFreeForm/SmartDrawHandler.tsx
index fc88b5cc6..7e66a62d4 100644
--- a/src/client/views/collections/collectionFreeForm/SmartDrawHandler.tsx
+++ b/src/client/views/collections/collectionFreeForm/SmartDrawHandler.tsx
@@ -23,7 +23,7 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
@observable private _yRelativeToTop: boolean = true;
@observable private _isLoading: boolean = false;
@observable private _userInput: string = '';
- @observable public coords: InkData | undefined = undefined;
+ @observable public strokes: InkData[] = [];
constructor(props: any) {
super(props);
@@ -55,6 +55,7 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
@action
drawWithGPT = async (startPoint: {X: number, Y: number}, input: string) => {
+ console.log("start point is", startPoint);
this.setIsLoading(true);
try {
const res = await gptAPICall(input, GPTCallType.DRAW);
@@ -63,13 +64,27 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
return;
}
console.log("GPT response:", res);
- // controlPts: {X: number, Y: number}[] = []
- // code to extract list of coords from the string
- // this.coords = controlPts.map(pt: {X: number, Y: number } => {pt.X + startPoint.X, pt.Y + startPoint.Y});
-
+ try {
+ // const controlPts: [number, number][][] = JSON.parse(res) as [number, number][][];
+ // console.log("Control Points", controlPts);
+ // const transformedPts: { X: number; Y: number }[][] = [];
+ // controlPts.forEach(stroke => {
+ // stroke.map(pt => {
+ // pt.X += startPoint.X, pt.Y += startPoint.Y;
+ // });
+ // transformedPts.push(stroke);
+ // });
+
+ const controlPts: { X: number; Y: number }[][] = JSON.parse(res).map((stroke: [number, number][]) =>
+ stroke.map(([X, Y]) => ({ X: X + startPoint.X, Y: Y + startPoint.Y })));
+ console.log("transformed points", controlPts);
+ this.strokes = controlPts;
+ } catch (err) {
+ console.error('Incompatible GPT output type');
+ }
} catch (err) {
- console.error('GPT call failed');
+ console.error('GPT call failed', err);
}
this.setIsLoading(false);