-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
224 lines (169 loc) · 5.26 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!DOCTYPE html>
<html lang="en">
<body>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<div class="row w-100 m-0">
<div class="col-4">
<h1 class="my-4 text-center">
Borghi Fine Art
</h1>
<hr>
<br>
<button class="btn btn-outline-dark w-100 mb-4">
Bradley Narduzzi Rex
</button>
<button class="btn btn-outline-dark w-100 mb-4">
Bradley Narduzzi Rex
</button>
<button class="btn btn-outline-dark w-100 mb-4">
Bradley Narduzzi Rex
</button>
<button class="btn btn-outline-dark w-100 mb-4">
Bradley Narduzzi Rex
</button>
<button class="btn btn-outline-dark w-100 mb-4">
Bradley Narduzzi Rex
</button>
</div>
<div class="col-8 m-0 p-0">
<div class="box">
<div id="3d">
</div>
</div>
</div>
</div>
</body>
<script type="importmap">
{
"imports": {
"three": "https://www.unpkg.com/three/build/three.module.js"
}
}
</script>
<script type="module">
// [IMPORT] //
import * as THREE from 'three'
// [INIT] const //
const windowWidth = document.querySelector('.box').offsetWidth
const windowHeight = window.innerHeight
const imageURL = "https://raw.githubusercontent.com/mrdoob/three.js/master/examples/textures/758px-Canestra_di_frutta_(Caravaggio).jpg"
// [INIT] //
let container, camera, scene, renderer
let mouseX = 0, mouseY = 0
// [DOM] create element div //
container = document.createElement('div')
document.getElementById('3d').appendChild(container)
// [three.js] create camera //
camera = new THREE.PerspectiveCamera(
35,
windowWidth / windowHeight,
1,
5000
)
camera.position.z = 1500
// [three.js] Create scenes //
scene = new THREE.Scene()
scene.background = new THREE.Color('#F8F8F8')
// GROUND //
const imageCanvas = document.createElement('canvas')
imageCanvas.width = 128
imageCanvas.height = 128
const context = imageCanvas.getContext('2d')
context.fillStyle = 'white'
context.fillRect(0, 0, 128, 128)
const textureCanvas = new THREE.CanvasTexture(imageCanvas)
textureCanvas.repeat.set(1000, 1000)
textureCanvas.wrapS = THREE.RepeatWrapping
textureCanvas.wrapT = THREE.RepeatWrapping
const materialCanvas = new THREE.MeshBasicMaterial({
map: textureCanvas
})
const geometry = new THREE.PlaneGeometry(100, 100)
const meshCanvas = new THREE.Mesh(geometry, materialCanvas)
meshCanvas.rotation.x = - Math.PI / 2
meshCanvas.scale.set(1000, 1000, 1000)
// [three.js][LOAD] Add painting to the scene //
const texturePainting = new THREE.TextureLoader().load(
imageURL,
function () {
// [INIT] //
const image = texturePainting.image
// [three.js][ADD] //
scene.add(meshCanvas)
// [three.js][Mesh] Image //
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
materialPainting
)
// [three.js][SCALE] //
mesh.scale.x = image.width / 100
mesh.scale.y = image.height / 100
// [three.js][ADD] //
scene.add(mesh)
// [three.js][Mesh] Image-Frame //
const meshFrame = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshBasicMaterial({ color: 0x000000 })
)
// [three.js][SCALE] //
meshFrame.position.z = - 10.0
meshFrame.scale.x = 1.1 * image.width / 100
meshFrame.scale.y = 1.1 * image.height / 100
// [three.js][ADD] Image-Frame //
scene.add(meshFrame)
// [three.js][Mesh] Shadow //
const meshShadow = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshBasicMaterial({
color: 0x000000,
opacity: 0.75,
transparent: true
})
)
// [three.js][SCALE] //
meshShadow.rotation.x = - Math.PI / 2
meshShadow.position.y = - 1.1 * image.height / 2
meshShadow.position.z = - 1.1 * image.height / 2
meshShadow.scale.x = 1.1 * image.width / 100
meshShadow.scale.y = 1.1 * image.height / 100
// [three.js][ADD] Shadow //
scene.add(meshShadow)
// Set floor height
meshCanvas.position.y = - 1.117 * image.height / 2
}
)
const materialPainting = new THREE.MeshBasicMaterial({
map: texturePainting
})
texturePainting.minFilter = texturePainting.magFilter = THREE.LinearFilter
texturePainting.mapping = THREE.UVMapping
// [three.js][WebGLRenderer] //
renderer = new THREE.WebGLRenderer({ antialias: true })
renderer.setPixelRatio(window.devicePixelRatio)
renderer.setSize(windowWidth, windowHeight)
renderer.autoClear = false
renderer.domElement.style.position = 'relative'
// [DOM] //
container.appendChild(renderer.domElement)
// [DOM][mousemove] //
document.addEventListener('mousemove', function (e) {
mouseX = (e.clientX - (windowWidth / 2))
mouseY = (e.clientY - (windowHeight / 2))
})
// [FUNCTION] //
animate()
function animate() {
requestAnimationFrame(animate)
camera.position.x += (mouseX - camera.position.x) * .05
camera.position.y += (- (mouseY - 200) - camera.position.y) * .05
camera.lookAt(scene.position)
renderer.clear()
renderer.render(scene, camera)
}
</script>
</html>
<style>
body {
margin: 0;
}
</style>