-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.old.html
215 lines (147 loc) · 6.25 KB
/
index.old.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - materials - texture filtering</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
</head>
<body>
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://www.unpkg.com/three/build/three.module.js"
}
}
</script>
<script type="module">
// [IMPORT] //
import * as THREE from 'three'
const SCREEN_WIDTH = window.innerWidth
const SCREEN_HEIGHT = window.innerHeight
const windowHalfX = window.innerWidth / 2
const windowHalfY = window.innerHeight / 2
let container
let camera, scene, scene2, renderer
let mouseX = 0, mouseY = 0
init();
animate();
function init() {
container = document.createElement( 'div' )
document.body.appendChild( container )
camera = new THREE.PerspectiveCamera( 35, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 5000 )
camera.position.z = 1500
scene = new THREE.Scene()
scene2 = new THREE.Scene()
scene.background = new THREE.Color( 0x000000 )
scene2.background = new THREE.Color('white')
// GROUND
const imageCanvas = document.createElement( "canvas" );
const context = imageCanvas.getContext( "2d" );
imageCanvas.width = imageCanvas.height = 128;
context.fillStyle = "white";
context.fillRect( 0, 0, 128, 128 );
context.fillStyle = "white";
context.fillRect( 0, 0, 64, 64 );
context.fillRect( 64, 64, 64, 64 );
const textureCanvas = new THREE.CanvasTexture( imageCanvas );
textureCanvas.repeat.set( 1000, 1000 );
textureCanvas.wrapS = THREE.RepeatWrapping;
textureCanvas.wrapT = THREE.RepeatWrapping;
const textureCanvas2 = textureCanvas.clone();
textureCanvas2.magFilter = THREE.NearestFilter;
textureCanvas2.minFilter = THREE.NearestFilter;
const materialCanvas = new THREE.MeshBasicMaterial( { map: textureCanvas } );
const materialCanvas2 = new THREE.MeshBasicMaterial( { color: 0xffccaa, map: textureCanvas2 } );
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 );
const meshCanvas2 = new THREE.Mesh( geometry, materialCanvas2 );
meshCanvas2.rotation.x = - Math.PI / 2;
meshCanvas2.scale.set( 1000, 1000, 1000 );
// PAINTING
const callbackPainting = function () {
const image = texturePainting.image;
texturePainting2.image = image;
texturePainting2.needsUpdate = true;
scene.add( meshCanvas );
scene2.add( meshCanvas2 );
const geometry = new THREE.PlaneGeometry( 100, 100 );
const mesh = new THREE.Mesh( geometry, materialPainting );
const mesh2 = new THREE.Mesh( geometry, materialPainting2 );
addPainting( scene, mesh );
addPainting( scene2, mesh2 );
function addPainting( zscene, zmesh ) {
zmesh.scale.x = image.width / 100;
zmesh.scale.y = image.height / 100;
zscene.add( zmesh );
const meshFrame = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 0x000000 } ) );
meshFrame.position.z = - 10.0;
meshFrame.scale.x = 1.1 * image.width / 100;
meshFrame.scale.y = 1.1 * image.height / 100;
zscene.add( meshFrame );
const meshShadow = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 0x000000, opacity: 0.75, transparent: true } ) );
meshShadow.position.y = - 1.1 * image.height / 2;
meshShadow.position.z = - 1.1 * image.height / 2;
meshShadow.rotation.x = - Math.PI / 2;
meshShadow.scale.x = 1.1 * image.width / 100;
meshShadow.scale.y = 1.1 * image.height / 100;
zscene.add( meshShadow );
const floorHeight = - 1.117 * image.height / 2;
meshCanvas.position.y = meshCanvas2.position.y = floorHeight;
}
};
const texturePainting = new THREE.TextureLoader()
.load(
"https://raw.githubusercontent.com/mrdoob/three.js/master/examples/textures/758px-Canestra_di_frutta_(Caravaggio).jpg",
callbackPainting
);
const texturePainting2 = new THREE.Texture();
const materialPainting = new THREE.MeshBasicMaterial( { color: 0xffffff, map: texturePainting } );
const materialPainting2 = new THREE.MeshBasicMaterial( { color: 0xffccaa, map: texturePainting2 } );
texturePainting2.minFilter = texturePainting2.magFilter = THREE.NearestFilter;
texturePainting.minFilter = texturePainting.magFilter = THREE.LinearFilter;
texturePainting.mapping = THREE.UVMapping;
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
renderer.autoClear = false;
renderer.domElement.style.position = "relative";
container.appendChild( renderer.domElement );
document.addEventListener( 'mousemove', onDocumentMouseMove );
}
function onDocumentMouseMove( event ) {
mouseX = ( event.clientX - windowHalfX );
mouseY = ( event.clientY - windowHalfY );
}
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
camera.position.x += ( mouseX - camera.position.x ) * .05;
camera.position.y += ( - ( mouseY - 200 ) - camera.position.y ) * .05;
camera.lookAt( scene.position );
renderer.clear();
renderer.setScissorTest( true );
renderer.setScissor( 0, 0, SCREEN_WIDTH / 2 - 2, SCREEN_HEIGHT );
renderer.render( scene, camera );
renderer.setScissor( SCREEN_WIDTH / 2, 0, SCREEN_WIDTH / 2 - 2, SCREEN_HEIGHT );
renderer.render( scene2, camera );
renderer.setScissorTest( false );
}
</script>
</body>
</html>
<style>
body {
margin: 0;
}
.lbl { color:#fff; font-size:16px; font-weight:bold; position: absolute; bottom:0px; z-index:100; text-shadow:#000 1px 1px 1px; background-color:rgba(0,0,0,0.85); padding:1em }
#lbl_left { text-align:left; left:0px }
#lbl_right { text-align:left; right:0px }
</style>