Hovu commited on
Commit
3ee742c
1 Parent(s): 12a0665

Add 2 files

Browse files
Files changed (2) hide show
  1. app.js +127 -0
  2. index.html +13 -19
app.js ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ addEventListener('load', async function() {
2
+ // Initialize AlpineJS
3
+ Alpine.start()
4
+ // When the app loads, inject the required
5
+ // libraries for Three.js and DaisyUI
6
+ var three = await import('three.js')
7
+ var daisyui = await import('daisyui.js')
8
+ // Create the canvas element and get its context
9
+ var canvas = document.getElementById('canvas')
10
+ var ctx = canvas.getContext('2d')
11
+ // Set the canvas dimensions
12
+ canvas.width = window.innerWidth
13
+ canvas.height = window.innerHeight
14
+ // Create the Three.js scene
15
+ var scene = new three.Scene()
16
+ var camera = new three.PerspectiveCamera(75, canvas.width / canvas.height, 0.1, 1000)
17
+ camera.position.z = 5
18
+ var renderer = new three.WebGLRenderer({canvas: canvas, antialias: true})
19
+ var geometry = new three.BoxGeometry(2, 2, 2)
20
+ var material = new three.MeshPhongMaterial({color: 0x00ff00})
21
+ var cube = new three.Mesh(geometry, material)
22
+ scene.add(cube)
23
+ // Create the DaisyUI components
24
+ var button = daisyui.header('Design your home')
25
+ var printButton = daisyui.button('Print')
26
+ var controls = daisyui.controls([
27
+ {
28
+ type: 'slider',
29
+ label: 'Scale',
30
+ value: 1,
31
+ min: 1,
32
+ max: 5,
33
+ step: 0.1,
34
+ },
35
+ {
36
+ type: 'slider',
37
+ label: 'Rotate',
38
+ value: 0,
39
+ min: 0,
40
+ max: 360,
41
+ step: 1,
42
+ },
43
+ {
44
+ type: 'button',
45
+ label: 'Toggle lighting',
46
+ }
47
+ ], {
48
+ 'margin-top': '16px'
49
+ })
50
+ // Add the components to the scene
51
+ scene.add(cube, button, printButton, controls)
52
+ // Create a render loop
53
+ function render() {
54
+ requestAnimationFrame(render)
55
+ renderer.clear()
56
+ renderer.render(scene, camera)
57
+ }
58
+ render()
59
+ // Add event listeners for user input
60
+ canvas.addEventListener('mousedown', function(event) {
61
+ var mouse = new three.Vector2()
62
+ mouse.x = (event.clientX / canvas.width) * 2 - 1
63
+ mouse.y = -(event.y / canvas.height) * 2 + 1
64
+ var raycaster = new three.Raycaster()
65
+ raycaster.setFromCamera(mouse, camera)
66
+ var intersects = raycaster.intersectObjects(scene.children)
67
+ if (intersects.length > 0) {
68
+ var obj = intersects[0].object
69
+ if (obj.isMesh) {
70
+ if (obj.name === 'Cube') {
71
+ // Select the cube for dragging
72
+ cube.userData = 'dragging'
73
+ cube.position.lerp(new three.Vector3(mouse.x, mouse.y, 0), 0.5)
74
+ }
75
+ }
76
+ }
77
+ })
78
+ canvas.addEventListener('mouseup', function(event) {
79
+ var mouse = new three.Vector2()
80
+ mouse.x = (event.clientX / canvas.width) * 2 - 1
81
+ mouse.y = -(event.y / canvas.height) * 2 + 1
82
+ var raycaster = new three.Raycaster()
83
+ raycaster.setFromCamera(mouse, camera)
84
+ var intersects = raycaster.intersectObjects(scene.children)
85
+ if (intersects.length > 0) {
86
+ var obj = intersects[0].object
87
+ if (obj.isMesh) {
88
+ if (obj.name === 'Cube') {
89
+ cube.userData = ''
90
+ }
91
+ }
92
+ }
93
+ })
94
+ canvas.addEventListener('mousemove', function(event) {
95
+ var mouse = new three.Vector2()
96
+ mouse.x = (event.clientX / canvas.width) * 2 - 1
97
+ mouse.y = -(event.y / canvas.height) * 2 + 1
98
+ var raycaster = new three.Raycaster()
99
+ raycaster.setFromCamera(mouse, camera)
100
+ var intersects = raycaster.intersectObjects(scene.children)
101
+ if (intersects.length > 0) {
102
+ var obj = intersects[0].object
103
+ if (obj.isMesh) {
104
+ if (obj.name === 'Cube') {
105
+ // Update the cube position while dragging
106
+ cube.position.lerp(new three.Vector3(mouse.x, mouse.y, 0), 0.5)
107
+ }
108
+ }
109
+ }
110
+ })
111
+ var scale = 1
112
+ var rotate = 0
113
+ var lightOn = false
114
+ controls.addEventListener('input', function(event) {
115
+ var value = Number(event.target.value)
116
+ if (event.target.type === 'slider') {
117
+ scale = value
118
+ } else if (event.target.type === 'button') {
119
+ lightOn = !lightOn
120
+ if (lightOn) {
121
+ scene.add(new three.AmbientLight(0xffffff))
122
+ } else {
123
+ scene.remove(scene.getObjectByType('AmbientLight'))
124
+ }
125
+ }
126
+ })
127
+ })
index.html CHANGED
@@ -1,19 +1,13 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
1
+ <html><head><link href="https://cdn.jsdelivr.net/npm/daisyui@3.1.6/dist/full.css" rel="stylesheet" type="text/css" /><script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script><script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio"></script><script defer src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.156.1/three.min.js"></script><script type="module" src="main.js"></script><title>Architecture Designer</title></head><body><h1>Architecture Designer</h1>
2
+ <div class="flex justify-between items-center p-4 border-b-[1.5px] border-gray-300"></div>
3
+ <nav class="flex items-baseline text-xl">
4
+ <h1 class="font-bold text-4xl">Design your home</h1>
5
+ <span class="ml-[16px]">|</span>
6
+ <a class="text-link" href="#">Print</a>
7
+ </nav>
8
+ <h1>Design your home</h1>
9
+ <p class="mt-[8px]">Welcome to the Architecture Designer! Use the tools below to create a custom architectural design for your home. Start by dragging and dropping the provided components onto the canvas. You can then scale, rotate, and arrange the components as needed. Once you have created your design, print it out to take with you to your builder or contractor. If you need help or have any questions, please don't hesitate to ask. Have fun!</p>
10
+ </div>
11
+ <canvas class="mt-[16px] h-[600px] w-full" id="canvas"></canvas>
12
+ <script></script>
13
+ </body></html>