-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkami3d.html
239 lines (213 loc) · 6.95 KB
/
kami3d.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<html>
<head>
<title>紙肖像</title>
<script src="lightgl.js"></script>
<script src="csg.js"></script>
<script src="openjscad.js"></script>
<script src="three.js"></script>
<style media="screen" type="text/css">
body {
font: 14px/20px 'Helvetica Neue Light', HelveticaNeue-Light, 'Helvetica Neue', Helvetica, Arial, sans-serif;
xxxmax-width: 820px;
margin: 0 auto;
padding: 10px;
color: #6e6;
}
pre, code, textarea {
font: 12px/20px Monaco, monospace;
border: 1px solid #CCC;
border-radius: 3px;
background: #F9F9F9;
padding: 0 3px;
color: #555;
}
pre, textarea {
padding: 10px;
width: 100%;
}
textarea {
height: 200px;
}
textarea:focus {
outline: none;
}
</style>
</head>
<body bgcolor="#334" onload="onload()">
<h1>紙肖像</h1>
<div id="vertexShader">
</div>
</body>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, 1.0, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( 500, 500 );
document.body.appendChild( renderer.domElement );
var light = new THREE.PointLight( 0xffffff, 1, 500 );
light.position.set( 50, 50, 50 );
scene.add( light );
var geometry = new THREE.BoxGeometry(1,1,1);
var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
material = new THREE.MeshPhongMaterial( { ambient: 0x030303, color: 0x00ff00, specular: 0x009900, shininess: 30 } );
gradientVertexShader = [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join("\n");
gradientFragmentShader = [
"uniform vec3 uColorZero;",
"uniform vec3 uColorOne;",
"uniform vec3 vColorZero;",
"uniform vec3 vColorOne;",
"varying vec2 vUv;",
"void main() {",
"gl_FragColor.rgb = mix(uColorZero, uColorOne, vUv.x) + mix(vColorZero, vColorOne, vUv.y);",
"gl_FragColor.a = 0.5;",
"}"
].join("\n");
materialA = new THREE.ShaderMaterial( {
uniforms: {
"uColorZero" : { type: "c", value: new THREE.Color( 0x000000 ) },
"uColorOne" : { type: "c", value: new THREE.Color( 0xff0000 ) },
"vColorZero" : { type: "c", value: new THREE.Color( 0x000000 ) },
"vColorOne" : { type: "c", value: new THREE.Color( 0x00ff00 ) }
},
vertexShader: gradientVertexShader,
fragmentShader: gradientFragmentShader,
transparent: true
});
material1 = new THREE.ShaderMaterial( {
uniforms: {
"uColorZero" : { type: "c", value: new THREE.Color( 0xff0000 ) },
"uColorOne" : { type: "c", value: new THREE.Color( 0xff00ff ) },
"vColorZero" : { type: "c", value: new THREE.Color( 0x000000 ) },
"vColorOne" : { type: "c", value: new THREE.Color( 0x00ff00 ) }
},
vertexShader: gradientVertexShader,
fragmentShader: gradientFragmentShader,
transparent: true
});
material2 = new THREE.ShaderMaterial( {
uniforms: {
"uColorZero" : { type: "c", value: new THREE.Color( 0x0000ff ) },
"uColorOne" : { type: "c", value: new THREE.Color( 0x000000 ) },
"vColorZero" : { type: "c", value: new THREE.Color( 0x000000 ) },
"vColorOne" : { type: "c", value: new THREE.Color( 0x00ff00 ) }
},
vertexShader: gradientVertexShader,
fragmentShader: gradientFragmentShader,
transparent: true
});
material3 = new THREE.ShaderMaterial( {
uniforms: {
"uColorZero" : { type: "c", value: new THREE.Color( 0x00ff00 ) },
"uColorOne" : { type: "c", value: new THREE.Color( 0xffff00 ) },
"vColorZero" : { type: "c", value: new THREE.Color( 0x00ff00 ) },
"vColorOne" : { type: "c", value: new THREE.Color( 0x00ffff ) }
},
vertexShader: gradientVertexShader,
fragmentShader: gradientFragmentShader,
transparent: true
});
material4 = new THREE.ShaderMaterial( {
uniforms: {
"uColorZero" : { type: "c", value: new THREE.Color( 0x000000 ) },
"uColorOne" : { type: "c", value: new THREE.Color( 0xff0000 ) },
"vColorZero" : { type: "c", value: new THREE.Color( 0x0000ff ) },
"vColorOne" : { type: "c", value: new THREE.Color( 0x000000 ) }
},
vertexShader: gradientVertexShader,
fragmentShader: gradientFragmentShader,
transparent: true
});
material5 = new THREE.ShaderMaterial( {
uniforms: {
"uColorZero" : { type: "c", value: new THREE.Color( 0x000000 ) },
"uColorOne" : { type: "c", value: new THREE.Color( 0xff0000 ) },
"vColorZero" : { type: "c", value: new THREE.Color( 0x000000 ) },
"vColorOne" : { type: "c", value: new THREE.Color( 0x00ff00 ) }
},
vertexShader: gradientVertexShader,
fragmentShader: gradientFragmentShader,
transparent: true
});
material6 = new THREE.ShaderMaterial( {
uniforms: {
"uColorZero" : { type: "c", value: new THREE.Color( 0xff00ff ) },
"uColorOne" : { type: "c", value: new THREE.Color( 0x0000ff ) },
"vColorZero" : { type: "c", value: new THREE.Color( 0x000000 ) },
"vColorOne" : { type: "c", value: new THREE.Color( 0x00ff00 ) }
},
vertexShader: gradientVertexShader,
fragmentShader: gradientFragmentShader,
transparent: true
});
materialZ = new THREE.MeshBasicMaterial( {
color: 0xffffff, wireframe: true, wireframeLinewidth: 30.0
});
var materialUV = new THREE.MeshBasicMaterial({
map: THREE.ImageUtils.loadTexture( "uv-texture.jpg" ),
side: THREE.DoubleSide,
wireframe: false
});
var faceMaterials = [material1, material2, material3, material4, material5, material6];
//faceMaterials[1] = materialUV;
material = new THREE.MeshFaceMaterial(faceMaterials);
material.opacity = 0.4;
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );
sg = new THREE.SphereGeometry( 0.45, 32, 32 );
sm = new THREE.MeshPhongMaterial({ emissive: 0x220033, color: 0x66a00ff, specular: 0x99aaff, shininess: 10 });
var sphere = new THREE.Mesh( sg, sm );
scene.add( sphere );
camera.position.z = 1.8;
function render() {
requestAnimationFrame(render);
// cube.rotation.y = 0.6;
//cube.rotation.x = 10;
// cube.rotation.x += 0.01;
//cube.rotation.y += 0.01;
cube.rotation.x = 0.7;
cube.rotation.y += 0.02
renderer.render(scene, camera);
}
render();
function onload()
{}
document.onkeydown = function checkKey(e) {
e = e || window.event;
if (e.keyCode == '45') {
cube.rotation.x = 0;
cube.rotation.y = 0;
cube.rotation.z = 0;
}
else if (e.keyCode == '35') {
cube.rotation.x -= 0.2
// down arrow
}
else if (e.keyCode == '34') {
cube.rotation.x += 0.2
// down arrow
}
else if (e.keyCode == '37') {
cube.rotation.y -= 0.2
// down arrow
}
else if (e.keyCode == '39') {
cube.rotation.y += 0.2
// down arrow
}
else if (e.keyCode == '36') {
cube.rotation.z -= 0.2
// down arrow
}
else if (e.keyCode == '33') {
cube.rotation.z += 0.2
// down arrow
}
}
</script>
</html>