Skip to content

Commit cc9ca37

Browse files
committed
3d
1 parent b5109a9 commit cc9ca37

File tree

6 files changed

+44
-13
lines changed

6 files changed

+44
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ yarn-error.log*
3434
# typescript
3535
*.tsbuildinfo
3636
next-env.d.ts
37+
.idea

app/components/ExportButton.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ import { PreviewShape } from '../PreviewShape/PreviewShape'
44
import { getHtmlFromOpenAI } from '../lib/getHtmlFromOpenAI'
55
import { useMakeReal } from '../hooks/useMakeReal'
66

7-
export function ExportButton() {
8-
const makeReal = useMakeReal()
7+
export function ExportButton({
8+
mode,
9+
}: {
10+
mode: 'tailwind' | 'threejs',
11+
}) {
12+
const makeReal = useMakeReal(mode)
913

1014
// A tailwind styled button that is pinned to the bottom right of the screen
1115
return (
1216
<button
1317
onClick={makeReal}
14-
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded m-2"
18+
className='bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded m-2'
1519
style={{ cursor: 'pointer', zIndex: 100000, pointerEvents: 'all' }}
1620
>
17-
Make Real
21+
{`Make Real${mode === 'threejs' ? ' (3D!)' : ''}`}
1822
</button>
1923
)
2024
}

app/hooks/useMakeReal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { useEditor, useToasts } from '@tldraw/tldraw'
22
import { useCallback } from 'react'
33
import { makeReal } from '../lib/makeReal'
44

5-
export function useMakeReal() {
5+
export function useMakeReal(mode: 'tailwind' | 'threejs') {
66
const editor = useEditor()
77
const toast = useToasts()
88

99
return useCallback(async () => {
1010
const input = document.getElementById('openai_key_risky_but_cool') as HTMLInputElement
1111
const apiKey = input?.value ?? null
1212
try {
13-
await makeReal(editor, apiKey)
13+
await makeReal(editor, apiKey, mode)
1414
} catch (e: any) {
1515
console.error(e)
1616
toast.addToast({

app/lib/getHtmlFromOpenAI.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,43 @@ Use JavaScript modules and unkpkg to import any necessary dependencies.
1313
1414
Respond ONLY with the contents of the html file.`
1515

16+
const threeJsSystemPrompt = `You are an expert web developer who specializes in three.js.
17+
A user will provide you with a low-fidelity wireframe of an application.
18+
You will return a single html file that uses HTML, three.js, and JavaScript to create a high fidelity website.
19+
Include any extra CSS and JavaScript in the html file.
20+
The user will provide you with notes in blue or red text, arrows, or drawings.
21+
The user may also include images of other websites as style references. Transfer the styles as best as you can, matching colors.
22+
Prefer to use standard materials instead of basic and avoid custom shaders.
23+
Unless otherwise specified, set up orbit controls and a directional light attached to the camera.
24+
Use an import map e.g. <script type="importmap">{"imports": {"three": "https://unpkg.com/[email protected]/build/three.module.js","OrbitControls": "https://unpkg.com/[email protected]/examples/jsm/controls/OrbitControls.js"}}</script>
25+
They may also provide you with the html of a previous design that they want you to iterate from.
26+
Carry out any changes they request from you.
27+
In the wireframe, the previous design's html will appear as a white rectangle.
28+
Use creative license to make the application more fleshed out.
29+
Use JavaScript modules and unkpkg to import any necessary dependencies.
30+
Respond ONLY with the contents of the html file.`
31+
1632
export async function getHtmlFromOpenAI({
1733
image,
1834
html,
1935
apiKey,
36+
mode,
2037
}: {
21-
image: string
22-
html: string
23-
apiKey: string
38+
image: string;
39+
html: string;
40+
apiKey: string;
41+
mode: 'tailwind' | 'threejs',
2442
}) {
43+
let threeJsText = 'Turn this into a single html file using three.js.'
44+
let tailwindText = 'Turn this into a single html file using tailwind.'
2545
const body: GPT4VCompletionRequest = {
2646
model: 'gpt-4-vision-preview',
2747
max_tokens: 4096,
2848
temperature: 0,
2949
messages: [
3050
{
3151
role: 'system',
32-
content: systemPrompt,
52+
content: mode === 'tailwind' ? systemPrompt : threeJsSystemPrompt,
3353
},
3454
{
3555
role: 'user',
@@ -43,7 +63,7 @@ export async function getHtmlFromOpenAI({
4363
},
4464
{
4565
type: 'text',
46-
text: 'Turn this into a single html file using tailwind.',
66+
text: mode === 'tailwind' ? tailwindText : threeJsText,
4767
},
4868
{
4969
type: 'text',

app/lib/makeReal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Editor, createShapeId, getSvgAsImage } from '@tldraw/tldraw'
22
import { PreviewShape } from '../PreviewShape/PreviewShape'
33
import { getHtmlFromOpenAI } from './getHtmlFromOpenAI'
44

5-
export async function makeReal(editor: Editor, apiKey: string) {
5+
export async function makeReal(editor: Editor, apiKey: string, mode: 'tailwind' | 'threejs') {
66
const newShapeId = createShapeId()
77
const selectedShapes = editor.getSelectedShapes()
88

@@ -62,6 +62,7 @@ export async function makeReal(editor: Editor, apiKey: string) {
6262
image: dataUrl,
6363
html: previousHtml,
6464
apiKey,
65+
mode,
6566
})
6667

6768
if (json.error) {

app/page.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export default function Home() {
2020
return (
2121
<>
2222
<div className={'tldraw__editor'}>
23-
<Tldraw persistenceKey="tldraw" shapeUtils={shapeUtils} shareZone={<ExportButton />}>
23+
<Tldraw persistenceKey="tldraw" shapeUtils={shapeUtils} shareZone={
24+
<div className={"flex"}>
25+
<ExportButton mode={'tailwind'}/>
26+
<ExportButton mode={'threejs'}/>
27+
</div>
28+
}>
2429
<APIKeyInput />
2530
<LockupLink />
2631
</Tldraw>

0 commit comments

Comments
 (0)