-
Notifications
You must be signed in to change notification settings - Fork 1
/
index_svg.html
245 lines (222 loc) · 6.22 KB
/
index_svg.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
240
241
242
243
244
245
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - svg loader</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
color: #ffffff;
font-family: Monospace;
font-size: 13px;
text-align: center;
font-weight: bold;
background-color: #000000;
margin: 0px;
overflow: hidden;
}
#info {
position: absolute;
top: 0px;
width: 100%;
padding: 5px;
}
a {
color: #ffffff;
}
img {
width: 100%;
height: auto;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="three.min.js"></script>
<script src="OrbitControls.js"></script>
<script src="SVGLoader.js"></script>
<script src="SVGRenderer.js"></script>
<script>
var renderer, scene, camera, board_group;
//
//img.src = "textures/tiger.svg";
//img.src = "textures/badge2018-brd.svg";
layers = [
"textures/badge2018-F.Cu.svg",
"textures/badge2018-In1.Cu.svg",
"textures/badge2018-Edge.Cuts.svg",
"textures/badge2018-In2.Cu.svg",
"textures/badge2018-B.Cu.svg",
"textures/badge2018-B.SilkS2.svg"
//"textures/badge2018-F.Mask.svg",
];
/*
layers = ["textures/tiger.svg",
"textures/tiger.svg",
"textures/tiger.svg",
"textures/badge2018-F.Cu.svg",
"textures/tiger.svg",
"textures/tiger.svg"]
*/
function set_color(canv, color){
var ctx = canv.getContext('2d');
var imageData = ctx.getImageData(0,0,canv.width, canv.height);
var data = imageData.data;
var rr = (color & 0xff0000) >> 16;
var gg = (color & 0x00ff00) >> 8;
var bb = (color & 0x0000ff);
for(var i = 0; i < data.length; i+= 4){
r = data[i];
g = data[i+1];
b = data[i+2];
if (r == 0 && g == 0 & b == 0){
data[i] = rr;
data[i+1] = gg;
data[i+2] = bb;
}
}
ctx.putImageData(imageData,0,0);
}
var textures = [null, null, null, null, null,null];
var meshes = [null,null,null,null,null,null];
var purple = 0x880088;
var pink = 0xff22ff;
var gold = 0xb38f00;
var yellow = 0xffff00;
var green = 0x00ff00;
var red = 0xff0000;
var blue = 0x0000ff;
var colors = [blue,red,green,gold,pink,yellow];
var colors = [yellow, pink, gold, green, red, blue];
var cnt = layers.length
function load_svg(s,i){
var l = new THREE.SVGLoader();
l.load(s,
function(paths){
var g = new THREE.Group();
for(var ii = 0; ii < paths.length; ii++){
var path = paths[ii];
//console.log(path.currentPath.currentPoint)
if (path.color.r == 0 && path.color.g == 0 && path.color.b == 0){
path.color = new THREE.Color(colors[i]);
}
var mat = new THREE.MeshPhysicalMaterial({
color: path.color,
side:THREE.DoubleSide,
transparent:true,
reflectivity:0.5,
metalness:0,
clearCoat:0.5,
clearCoatRoughness:0.5,
depthWrite:false});
var shapes = path.toShapes();
for (var j = 0; j < shapes.length; j++){
var geom = new THREE.ShapeBufferGeometry(shapes[j]);
var mesh = new THREE.Mesh(geom,mat);
g.add(mesh);
}
}
g.position.x = 1000;
g.position.y = 1000;
g.position.z = 100000;
meshes[i] = g;
cnt -= 1;
if (cnt == 0){
init();
animate();
}
});
}
for(var i = 0; i < layers.length; i++){
//load_layer(layers[i],i);
load_svg(layers[i],i);
}
function init() {
var container = document.getElementById( 'container' );
//
//meshes[0].rotation.y=3.14159
renderer = new THREE.WebGLRenderer({antialiasing:true} );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
camera = new THREE.PerspectiveCamera(50000, window.innerWidth / window.innerHeight, 1, 200000 );
camera.position.set( 0, 0, -70000 );
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x000000 );
//
//
//var helper = new THREE.GridHelper( 100000, 10 );
//helper.rotation.x = Math.PI / 2;
//scene.add( helper );
//
//texture.offset.set(0.5,0);
//var geom = new THREE.PlaneGeometry(128,128,64);
board_group = new THREE.Group();
for(var i = 0; i < meshes.length; i++){
meshes[i].position.set(0,0,-20 + 10 * i);
meshes[i].castShadow=true;
board_group.add(meshes[i]);
}
/*
for (var i = 0; i < textures.length; i++){
//var geom = new THREE.BoxGeometry(100,100,100);
var mat = new THREE.MeshPhysicalMaterial(
{map:textures[i],
side:THREE.DoubleSide,
transparent:true,
reflectivity:0.5,
metalness:0,
clearCoat:0.5,
clearCoatRoughness:0.5,
alpha:0.5,
});
mat.map.minFilter = THREE.LinearFilter;
mesh = new THREE.Mesh(geom,mat);
mesh.position.set(0,0,-20 + 10 * i);
mesh.castShadow=true;
meshes[i] = mesh;
board_group.add(mesh)
}
*/
scene.add(board_group);
var light = new THREE.PointLight(0xffffff,1,200000);
light.position.set(30000,0,-100000);
scene.add(light);
light = new THREE.PointLight(0xffffff,1,2000);
light.position.set(-30000,0,-100000);
scene.add(light);
light = new THREE.PointLight(0xffffff,1,2000);
light.position.set(0,0,10000);
scene.add(light);
//
//
var controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.screenSpacePanning = true;
//
window.addEventListener( 'resize', onWindowResize, false );
scene.add(new THREE.AmbientLight(0x555555));
}
function set_spacing(n){
offset = - meshes.length/2 * n;
for(var i = 0; i < meshes.length; i++){
meshes[i].position.set(-29000,-25000,200+offset + n * i);
}
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
frame_n = 0;
function animate() {
requestAnimationFrame( animate );
board_group.rotation.y += 0.003;
frame_n += 1;
set_spacing(Math.abs(Math.sin(frame_n/180))*10000);
render();
}
function render() {
renderer.render( scene, camera );
}
</script>
</body>
</html>