-
Notifications
You must be signed in to change notification settings - Fork 0
/
ferguson.html
789 lines (680 loc) · 39.1 KB
/
ferguson.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
<!doctype html>
<html lang="en">
<head>
<title>Repeating Textures (Three.js)</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<body>
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<!--[if IE]><script type="text/javascript" src="excanvas.js"></script><![endif]-->
<script type="text/javascript" src="js/canvg/rgbcolor.js"></script>
<script type="text/javascript" src="js/canvg/StackBlur.js"></script>
<script type="text/javascript" src="js/canvg/canvg.js"></script>
<script src="js/Three.js"></script>
<script src="js/Detector.js"></script>
<!--<script src="js/Stats.js"></script>-->
<script src="js/OrbitControls.js"></script>
<script src="js/THREEx.KeyboardState.js"></script>
<script src="js/THREEx.FullScreen.js"></script>
<script src="js/THREEx.WindowResize.js"></script>
<div id="ThreeJS" style="position: absolute; left:0px; top:0px; width: 755px; height: 600px; background-color: #c4c4c4;"></div>
<div id="canvas_container" style="position: absolute; left: 755px; top: 0px;"></div>
<script>
$jq = jQuery.noConflict();
var pipingImg = 'piping.png';
var zoomRatio = 50;
var tierHeight = 7.5 * zoomRatio;
var cakeSizes = {
square: {
one: {
small: [16],
standard: [22],
medium: [25]
},
two: {
small: [22, 16],
medium: [25, 22]
},
three: {
small: [25, 22, 16]
}
},
round: {
one: {
mini: [15],
small: [18],
standard: [20],
medium: [25]
},
two: {
small: [18, 15],
medium: [20, 18]
},
three: {
small: [20, 18, 15],
medium: [25, 20, 18]
}
},
rectangle: {
one: {
medium: [20, 33],
large: [22, 43],
giant: [43, 67]
}
}
};
// MAIN
// standard global variables
var container, scene, camera, renderer, controls, stats;
var keyboard = new THREEx.KeyboardState();
var clock = new THREE.Clock();
// custom global variables
var cube;
init();
animate();
// FUNCTIONS
function init()
{
// SCENE
scene = new THREE.Scene();
// CAMERA
// var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
var SCREEN_WIDTH = 755, SCREEN_HEIGHT = 600;
var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000;
camera = new THREE.PerspectiveCamera(VIEW_ANGLE, ASPECT, NEAR, FAR);
scene.add(camera);
camera.position.set(30 * zoomRatio, 30 * zoomRatio, 40 * zoomRatio);
camera.lookAt(scene.position);
// RENDERER
if (Detector.webgl) {
renderer = new THREE.WebGLRenderer({antialias: true});
} else {
renderer = new THREE.CanvasRenderer();
}
renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
container = document.getElementById('ThreeJS');
container.appendChild(renderer.domElement);
// EVENTS
THREEx.WindowResize(renderer, camera);
THREEx.FullScreen.bindKey({charCode: 'm'.charCodeAt(0)});
// CONTROLS
controls = new THREE.OrbitControls(camera, renderer.domElement);
// STATS
// stats = new Stats();
// stats.domElement.style.position = 'absolute';
// stats.domElement.style.bottom = '0px';
// stats.domElement.style.zIndex = 100;
// container.appendChild( stats.domElement );
// LIGHT
var light = new THREE.PointLight(0xffffff);
light.position.set(0, 150, 100);
// scene.add(light);
// FLOOR
// var floorTexture = new THREE.ImageUtils.loadTexture( 'images/checkerboard.jpg' );
// floorTexture.wrapS = floorTexture.wrapT = THREE.RepeatWrapping;
// floorTexture.repeat.set( 10, 10 );
// var floorMaterial = new THREE.MeshBasicMaterial( { map: floorTexture, side: THREE.DoubleSide } );
// var floorGeometry = new THREE.PlaneGeometry(1000, 1000, 10, 10);
// var floor = new THREE.Mesh(floorGeometry, floorMaterial);
// floor.position.y = -0.5;
// floor.rotation.x = Math.PI / 2;
// scene.add(floor);
// SKYBOX/FOG
// var skyBoxGeometry = new THREE.CubeGeometry( 10000, 10000, 10000 );
// var skyBoxMaterial = new THREE.MeshBasicMaterial( { color: 0x9999ff, side: THREE.BackSide } );
// var skyBox = new THREE.Mesh( skyBoxGeometry, skyBoxMaterial );
// // scene.add(skyBox);
// scene.fog = new THREE.FogExp2( 0x9999ff, 0.00025 );
////////////
// CUSTOM //
////////////
// Spheres
// Note: a standard flat rectangular image will look distorted,
// a "spherical projection" image will look "normal".
// radius, segmentsWidth, segmentsHeight
// var sphereGeom = new THREE.SphereGeometry(40, 32, 16);
var light2 = new THREE.AmbientLight(0xfffffff);
// light2.position.set(0, 150, 100);
scene.add(light2);
//RECTANGLE CAKES
var rectangleCakeData = new Array();
rectangleCakeData['1'] = {
size: [67, 43],
side: 'side_3.jpg',
pipingColor: '#ffffff',
pipingSize: '1.5'
};
// createRectangleCake(rectangleCakeData);
//SQUARE CAKES
var squareCakeData = new Array();
squareCakeData['1'] = {
size: [25],
side: 'side_1.png',
pipingColor: '#ffffff',
pipingSize: '1.2'
};
squareCakeData['2'] = {
size: [22],
side: 'side_2.png',
pipingColor: '#0000ff',
pipingSize: '1'
};
squareCakeData['3'] = {
size: [16],
side: 'side_3.jpg',
pipingColor: '#ff0000',
pipingSize: '0.8'
};
// createSquareCake(squareCakeData);
//ROUND CAKES
var roundCakeData = new Array();
roundCakeData['1'] = {
size: [22],
side: 'side_1.png',
pipingColor: '#ffffff',
pipingSize: '1.2'
};
roundCakeData['2'] = {
size: [20],
side: 'side_2.png',
pipingColor: '#0000ff',
pipingSize: '1'
};
roundCakeData['3'] = {
size: [18],
side: 'side_3.jpg',
pipingColor: '#ff0000',
pipingSize: '0.8'
};
createRoundCake(roundCakeData);
}
/*
* Create Rectangle Cube
*/
function createRectangleCake(cakeData) {
var tierWidth, tierDepth;
var boardWidth, boardDepth, boardPadding, boardHeight;
boardPadding = 5 * zoomRatio;
boardHeight = 0.5 * zoomRatio;
//Load piping image
var pipingImage = new Image();
pipingImage.onload = function() {
if (cakeData[1]) {
tierWidth = cakeData[1].size[0] * zoomRatio;
tierDepth = cakeData[1].size[1] * zoomRatio;
boardWidth = tierWidth + boardPadding;
boardDepth = tierDepth + boardPadding;
var boardCube = createRectangleCube(boardWidth, boardDepth, boardHeight, 'board.svg');
boardCube.position.set(0, (tierHeight + boardHeight) / -2, 0);
var boardTopMaterial = boardCube.material.materials[2];
var boardTopCtx = boardTopMaterial.map.image.getContext('2d');
scene.add(boardCube);
var tier1Cube = createRectangleCube(tierWidth, tierDepth, tierHeight, 'ferg_sidestrip_icing/sidestrip_icing_blue.svg');
tier1Cube.position.set(0, 0, 0);
var tier1LeftMaterial = tier1Cube.material.materials[0];
var tier1TopMaterial = tier1Cube.material.materials[2];
var tier1FrontMaterial = tier1Cube.material.materials[4];
var tier1SideCtx = tier1LeftMaterial.map.image.getContext('2d');
var tier1TopCtx = tier1TopMaterial.map.image.getContext('2d');
var tier1FrontCtx = tier1FrontMaterial.map.image.getContext('2d');
scene.add(tier1Cube);
//Draw side image
var tier1Side = new Image();
tier1Side.onload = function() {
tierWidth = cakeData[1].size[0] * zoomRatio;
tierDepth = cakeData[1].size[1] * zoomRatio;
var sideImageCanvas = document.createElement("canvas");
var sideImageCtx = sideImageCanvas.getContext('2d');
sideImageCanvas.width = tierHeight * tier1Side.width / tier1Side.height;
sideImageCanvas.height = tierHeight;
sideImageCtx.drawImage(tier1Side, 0, 0, tier1Side.width, tier1Side.height, 0, 0, sideImageCanvas.width, sideImageCanvas.height);
addSidePiping(sideImageCtx, pipingImage, cakeData[1].pipingSize, cakeData[1].pipingColor);
var sideImagePattern = sideImageCtx.createPattern(sideImageCanvas, 'repeat');
tier1SideCtx.fillStyle = sideImagePattern;
tier1SideCtx.fill();
tier1LeftMaterial.map.needsUpdate = true;
tier1FrontCtx.fillStyle = sideImagePattern;
tier1FrontCtx.fill();
tier1FrontMaterial.map.needsUpdate = true;
addTopPiping(tier1TopCtx, tierWidth, tierDepth, pipingImage, cakeData[1].pipingSize, cakeData[1].pipingColor);
tier1TopMaterial.map.needsUpdate = true;
addBottomPiping(boardTopCtx, boardWidth, boardWidth, tierWidth, tierDepth, pipingImage, cakeData[1].pipingSize, cakeData[1].pipingColor);
boardTopMaterial.map.needsUpdate = true;
};
tier1Side.src = cakeData[1].side;
}
};
pipingImage.src = pipingImg;
}
/*
* Create Square Cube
*/
function createSquareCake(cakeData) {
//SQUARE CAKES
var tierWidth;
var boardWidth, boardPadding, boardHeight;
boardPadding = 5 * zoomRatio;
boardHeight = 0.5 * zoomRatio;
//Load piping image
var pipingImage = new Image();
pipingImage.onload = function() {
if (cakeData[1]) {
tierWidth = cakeData[1].size[0] * zoomRatio;
boardWidth = tierWidth + boardPadding;
var boardCube = createSquareCube(boardWidth, boardHeight, 'board.svg');
boardCube.position.set(0, (tierHeight + boardHeight) / -2, 0);
var boardTopMaterial = boardCube.material.materials[2];
var boardTopCtx = boardTopMaterial.map.image.getContext('2d');
scene.add(boardCube);
var tier1Cube = createSquareCube(tierWidth, tierHeight, 'ferg_sidestrip_icing/sidestrip_icing_blue.svg');
tier1Cube.position.set(0, 0, 0);
var tier1SideMaterial = tier1Cube.material.materials[0];
var tier1TopMaterial = tier1Cube.material.materials[2];
var tier1SideCtx = tier1SideMaterial.map.image.getContext('2d');
var tier1TopCtx = tier1TopMaterial.map.image.getContext('2d');
scene.add(tier1Cube);
//Draw side image
var tier1Side = new Image();
tier1Side.onload = function() {
tierWidth = cakeData[1].size[0] * zoomRatio;
var sideImageCanvas = document.createElement("canvas");
var sideImageCtx = sideImageCanvas.getContext('2d');
sideImageCanvas.width = tierHeight * tier1Side.width / tier1Side.height;
sideImageCanvas.height = tierHeight;
sideImageCtx.drawImage(tier1Side, 0, 0, tier1Side.width, tier1Side.height, 0, 0, sideImageCanvas.width, sideImageCanvas.height);
addSidePiping(sideImageCtx, pipingImage, cakeData[1].pipingSize, cakeData[1].pipingColor);
var sideImagePattern = sideImageCtx.createPattern(sideImageCanvas, 'repeat');
tier1SideCtx.fillStyle = sideImagePattern;
tier1SideCtx.fill();
tier1SideMaterial.map.needsUpdate = true;
addTopPiping(tier1TopCtx, tierWidth, tierWidth, pipingImage, cakeData[1].pipingSize, cakeData[1].pipingColor);
tier1TopMaterial.map.needsUpdate = true;
// addBottomPiping(boardTopCtx, boardWidth, boardWidth, tierWidth, tierWidth, pipingImage, cakeData[1].pipingSize, cakeData[1].pipingColor);
// boardTopMaterial.map.needsUpdate = true;
};
tier1Side.src = cakeData[1].side;
if (cakeData[2]) {
tierWidth = cakeData[2].size[0] * zoomRatio;
var tier2Cube = createSquareCube(tierWidth, tierHeight, 'ferg_sidestrip_icing/sidestrip_icing_green.svg');
tier2Cube.position.set(0, tierHeight, 0);
var tier2SideMaterial = tier2Cube.material.materials[0];
var tier2TopMaterial = tier2Cube.material.materials[2];
var tier2SideCtx = tier2SideMaterial.map.image.getContext('2d');
var tier2TopCtx = tier2TopMaterial.map.image.getContext('2d');
scene.add(tier2Cube);
//Draw Side Image
var tier2Side = new Image();
tier2Side.onload = function() {
tierWidth = cakeData[2].size[0] * zoomRatio;
var sideImageCanvas = document.createElement("canvas");
var sideImageCtx = sideImageCanvas.getContext('2d');
sideImageCanvas.width = tierHeight * tier2Side.width / tier2Side.height;
sideImageCanvas.height = tierHeight;
sideImageCtx.drawImage(tier2Side, 0, 0, tier2Side.width, tier2Side.height, 0, 0, sideImageCanvas.width, sideImageCanvas.height);
addSidePiping(sideImageCtx, pipingImage, cakeData[2].pipingSize, cakeData[2].pipingColor);
var sideImagePattern = sideImageCtx.createPattern(sideImageCanvas, 'repeat');
tier2SideCtx.fillStyle = sideImagePattern;
tier2SideCtx.fill();
tier2SideMaterial.map.needsUpdate = true;
addTopPiping(tier2TopCtx, tierWidth, tierWidth, pipingImage, cakeData[2].pipingSize, cakeData[2].pipingColor);
tier2TopMaterial.map.needsUpdate = true;
// addBottomPiping(tier1TopCtx, cakeData[1].size[0] * zoomRatio, cakeData[1].size[0] * zoomRatio, tierWidth, tierWidth, pipingImage, cakeData[2].pipingWidth, cakeData[2].pipingColor);
// tier1TopMaterial.map.needsUpdate = true;
};
tier2Side.src = cakeData[2].side;
if (cakeData[3]) {
tierWidth = cakeData[3].size[0] * zoomRatio;
var tier3Cube = createSquareCube(tierWidth, tierHeight, 'ferg_sidestrip_icing/sidestrip_icing_ivory.svg');
tier3Cube.position.set(0, tierHeight * 2, 0);
var tier3SideMaterial = tier3Cube.material.materials[0];
var tier3TopMaterial = tier3Cube.material.materials[2];
var tier3SideCtx = tier3SideMaterial.map.image.getContext('2d');
var tier3TopCtx = tier3TopMaterial.map.image.getContext('2d');
scene.add(tier3Cube);
var tier3Side = new Image();
tier3Side.onload = function() {
tierWidth = cakeData[3].size[0] * zoomRatio;
var sideImageCanvas = document.createElement("canvas");
var sideImageCtx = sideImageCanvas.getContext('2d');
sideImageCanvas.width = tierHeight * tier3Side.width / tier3Side.height;
sideImageCanvas.height = tierHeight;
sideImageCtx.drawImage(tier3Side, 0, 0, tier3Side.width, tier3Side.height, 0, 0, sideImageCanvas.width, sideImageCanvas.height);
addSidePiping(sideImageCtx, pipingImage, cakeData[3].pipingSize, cakeData[3].pipingColor);
var sideImagePattern = sideImageCtx.createPattern(sideImageCanvas, 'repeat');
tier3SideCtx.fillStyle = sideImagePattern;
tier3SideCtx.fill();
tier3SideMaterial.map.needsUpdate = true;
addTopPiping(tier3TopCtx, tierWidth, tierWidth, pipingImage, cakeData[3].pipingSize, cakeData[3].pipingColor);
tier3TopMaterial.map.needsUpdate = true;
// addBottomPiping(tier2TopCtx, cakeData[2].size[0] * zoomRatio, cakeData[2].size[0] * zoomRatio, tierWidth, tierWidth, pipingImage, cakeData[3].pipingSize, cakeData[3].pipingColor);
// tier2TopMaterial.map.needsUpdate = true;
};
tier3Side.src = cakeData[3].side;
}
}
}
};
pipingImage.src = pipingImg;
}
/*
* Create Square Cube
*/
function createRoundCake(cakeData) {
//ROUND CAKES
var boardPadding, boardHeight;
boardPadding = 5 * zoomRatio;
boardHeight = 0.5 * zoomRatio;
//Load piping image
var pipingImage = new Image();
pipingImage.onload = function() {
if (cakeData[1]) {
var boardCylinder = createRoundTier(cakeData[1].size[0] * zoomRatio + boardPadding, boardHeight, 'board.svg', 'board.svg');
boardCylinder.position.set(0, (tierHeight + boardHeight) / -2, 0);
scene.add(boardCylinder);
var tier1Cylinder = createRoundTier(cakeData[1].size[0] * zoomRatio, tierHeight, 'top.jpg', cakeData[1].side, pipingImage);
tier1Cylinder.position.set(0, 0, 0);
scene.add(tier1Cylinder);
if (cakeData[2]) {
var tier2Cylinder = createRoundTier(cakeData[2].size[0] * zoomRatio, tierHeight, 'top.jpg', cakeData[2].side, pipingImage);
tier2Cylinder.position.set(0, tierHeight, 0);
scene.add(tier2Cylinder);
if (cakeData[3]) {
var tier3Cylinder = createRoundTier(cakeData[3].size[0] * zoomRatio, tierHeight, 'top.jpg', cakeData[3].side, pipingImage);
tier3Cylinder.position.set(0, tierHeight * 2, 0);
scene.add(tier3Cylinder);
}
}
}
};
pipingImage.src = 'piping_one.png';
}
function addSidePiping(context, piping, pipingWidth, pipingColor) {
pipingWidth = pipingWidth * zoomRatio;
var ratio = piping.width / piping.height;
context.drawImage(piping, 0, 0, piping.width, piping.height, 0, (pipingWidth / -2), ratio * pipingWidth, pipingWidth);
context.drawImage(piping, 0, 0, piping.width, piping.height, 0, tierHeight + (pipingWidth / -2), ratio * pipingWidth, pipingWidth);
if (pipingColor) {
var buffer = document.createElement('canvas');
buffer.width = piping.width;
buffer.height = piping.height;
var bx = buffer.getContext('2d');
bx.fillStyle = pipingColor;
bx.fillRect(0, 0, buffer.width, buffer.height);
bx.globalCompositeOperation = "destination-atop";
bx.drawImage(piping, 0, 0);
context.globalAlpha = 0.5;
context.drawImage(buffer, 0, 0, piping.width, piping.height, 0, (pipingWidth / -2), ratio * pipingWidth, pipingWidth);
context.drawImage(buffer, 0, 0, piping.width, piping.height, 0, tierHeight + (pipingWidth / -2), ratio * pipingWidth, pipingWidth);
}
}
function addTopPiping(context, tierWidth, tierDepth, piping, pipingWidth, pipingColor) {
pipingWidth = pipingWidth * zoomRatio;
var ratio = piping.width / piping.height;
context.drawImage(piping, 0, 0, piping.width, piping.height, 0
, -(pipingWidth / 2), ratio * pipingWidth, pipingWidth);
context.drawImage(piping, 0, 0, piping.width, piping.height, 0
, tierDepth - (pipingWidth / 2), ratio * pipingWidth, pipingWidth);
context.rotate(Math.PI / 2);
context.drawImage(piping, 0, 0, piping.width, piping.height, 0
, -(pipingWidth / 2), ratio * pipingWidth, pipingWidth);
context.drawImage(piping, 0, 0, piping.width, piping.height, 0
, -tierWidth - (pipingWidth / 2), ratio * pipingWidth, pipingWidth);
context.rotate(Math.PI / -2);
if (pipingColor) {
var buffer = document.createElement('canvas');
buffer.width = piping.width;
buffer.height = piping.height;
var bx = buffer.getContext('2d');
bx.fillStyle = pipingColor;
bx.fillRect(0, 0, buffer.width, buffer.height);
bx.globalCompositeOperation = "destination-atop";
bx.drawImage(piping, 0, 0);
context.globalAlpha = 0.5;
context.drawImage(buffer, 0, 0, piping.width, piping.height
, 0, -(pipingWidth / 2), ratio * pipingWidth, pipingWidth);
context.drawImage(buffer, 0, 0, piping.width, piping.height
, 0, tierDepth - (pipingWidth / 2), ratio * pipingWidth, pipingWidth);
context.rotate(Math.PI / 2);
context.drawImage(buffer, 0, 0, piping.width, piping.height
, 0, -(pipingWidth / 2), ratio * pipingWidth, pipingWidth);
context.drawImage(buffer, 0, 0, piping.width, piping.height
, 0, -tierWidth - (pipingWidth / 2), ratio * pipingWidth, pipingWidth);
context.rotate(Math.PI / -2);
}
}
function addBottomPiping(context, tierWidth, tierDepth, aboveWidth, aboveDepth, piping, pipingSize, pipingColor) {
var ratio = (aboveWidth + pipingSize) / pipingSize;
var paddingTop = (tierWidth - aboveWidth - pipingSize) / 2;
var paddingBottom = (tierWidth - aboveWidth + pipingSize) / 2;
var paddingLeft = (tierDepth - aboveDepth - pipingSize) / 2;
var paddingRight = (tierDepth - aboveDepth + pipingSize) / 2;
context.drawImage(piping, 0, 0, piping.height * ratio, piping.height
, paddingTop, paddingTop, pipingSize * ratio, pipingSize);
context.drawImage(piping, 0, 0, piping.height * ratio, piping.height
, paddingTop, tierWidth - paddingBottom, pipingSize * ratio, pipingSize);
context.rotate(Math.PI / 2);
context.drawImage(piping, 0, 0, piping.height * ratio, piping.height
, paddingLeft, -paddingRight, pipingSize * ratio, pipingSize);
context.drawImage(piping, 0, 0, piping.height * ratio, piping.height
, paddingLeft, -tierWidth + paddingLeft, pipingSize * ratio, pipingSize);
context.rotate(Math.PI / -2);
if (pipingColor) {
var buffer = document.createElement('canvas');
buffer.width = piping.width;
buffer.height = piping.height;
var bx = buffer.getContext('2d');
bx.fillStyle = pipingColor;
bx.fillRect(0, 0, buffer.width, buffer.height);
bx.globalCompositeOperation = "destination-atop";
bx.drawImage(piping, 0, 0);
context.globalAlpha = 0.5;
context.drawImage(buffer, 0, 0, piping.height * ratio, piping.height
, paddingTop, paddingTop, pipingSize * ratio, pipingSize);
context.drawImage(buffer, 0, 0, piping.height * ratio, piping.height
, paddingTop, tierWidth - paddingBottom, pipingSize * ratio, pipingSize);
context.rotate(Math.PI / 2);
context.drawImage(buffer, 0, 0, piping.height * ratio, piping.height
, paddingTop, -paddingBottom, pipingSize * ratio, pipingSize);
context.drawImage(buffer, 0, 0, piping.height * ratio, piping.height
, paddingTop, -tierWidth + paddingTop, pipingSize * ratio, pipingSize);
context.rotate(Math.PI / -2);
}
}
function createCubeSide(width, height, materialImage) {
//Create front side
var cubeSideCanvas = document.createElement("canvas");
// var cubeSideCanvas = document.getElementById("canvas_container").appendChild(cubeSideCanvas);
cubeSideCanvas.width = width;
cubeSideCanvas.height = height;
var cubeSideTexture = new THREE.Texture(cubeSideCanvas, new THREE.UVMapping());
cubeSideTexture.needsUpdate = true;
var cubeSideMaterial = new THREE.MeshBasicMaterial({map: cubeSideTexture});
var ctx = cubeSideCanvas.getContext('2d');
ctx.drawSvg(materialImage, 0, 0, width, height);
return cubeSideMaterial;
}
function createCubeTop(width, height, sideimg) {
//Create front side
var cubeTopCanvas = document.createElement("canvas");
// var cubeTopCanvas = document.getElementById("canvas_container").appendChild(cubeTopCanvas);
cubeTopCanvas.width = width;
cubeTopCanvas.height = height;
var cubeTopTexture = new THREE.Texture(cubeTopCanvas, new THREE.UVMapping());
cubeTopTexture.needsUpdate = true;
var cubeTopMaterial = new THREE.MeshBasicMaterial({map: cubeTopTexture});
var ctx = cubeTopCanvas.getContext('2d');
ctx.drawSvg(sideimg, 0, 0, width, height);
return cubeTopMaterial;
}
function createSquareCube(width, height, sideDesign) {
var cubeGeometry = new THREE.CubeGeometry(width, height, width);
var leftMaterial = createCubeSide(width, height, sideDesign);
var rightMaterial = leftMaterial.clone();
var frontMaterial = leftMaterial.clone();
var backMaterial = leftMaterial.clone();
var topMaterial = createCubeTop(width, width, sideDesign);
var bottomMaterial = createCubeTop(width, width, sideDesign);
var faceMatterial = new THREE.MeshFaceMaterial([
leftMaterial,
rightMaterial,
topMaterial,
bottomMaterial,
frontMaterial,
backMaterial
]);
var cube = new THREE.Mesh(cubeGeometry.clone(), faceMatterial);
return cube;
}
function createRectangleCube(width, depth, height, sideDesign) {
var cubeGeometry = new THREE.CubeGeometry(width, height, depth);
var leftMaterial = createCubeSide(depth, height, sideDesign);
var rightMaterial = leftMaterial.clone();
var topMaterial = createCubeTop(width, depth, sideDesign);
var bottomMaterial = topMaterial.clone();
var frontMaterial = createCubeSide(width, height, sideDesign);
var backMaterial = frontMaterial.clone();
var faceMatterial = new THREE.MeshFaceMaterial([
leftMaterial,
rightMaterial,
topMaterial,
bottomMaterial,
frontMaterial,
backMaterial
]);
var cube = new THREE.Mesh(cubeGeometry.clone(), faceMatterial);
return cube;
}
// function createRoundCylinder(radius, height, sideDesign) {
// var cylinderGeometry = new THREE.CylinderGeometry(radius, radius, height, 100, 1, false);
//// var cubeGeometry = new THREE.CubeGeometry(radius, height, radius);
//
// var leftMaterial = createCubeSide(radius, height, sideDesign);
// var rightMaterial = leftMaterial.clone();
// var frontMaterial = leftMaterial.clone();
// var backMaterial = leftMaterial.clone();
// var topMaterial = createCubeTop(radius, radius, sideDesign);
// var bottomMaterial = createCubeTop(radius, radius, sideDesign);
//
// var faceMatterial = new THREE.MeshFaceMaterial([
// leftMaterial,
// rightMaterial,
// topMaterial,
// bottomMaterial,
// frontMaterial,
// backMaterial
// ]);
//
// var cube = new THREE.Mesh(cylinderGeometry.clone(), faceMatterial);
// return cube;
// }
function createRoundTier(tierSize, tierHeight, topImage, sideImage, pipingImage) {
// var pipingSize = 1.2 * zoomRatio;
var cylinderSideGeometry = new THREE.CylinderGeometry(tierSize, tierSize, tierHeight, 100.0, 10.0, true);
var cylinderTopGeometry = new THREE.Geometry();
for (var i = 0; i < 100; i++) {
var a = i * 1 / 100 * Math.PI * 2;
var z = Math.sin(a);
var x = Math.cos(a);
var a1 = (i + 1) * 1 / 100 * Math.PI * 2;
var z1 = Math.sin(a1);
var x1 = Math.cos(a1);
cylinderTopGeometry.vertices.push(
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(x * tierSize, 0, z * tierSize),
new THREE.Vector3(x1 * tierSize, 0, z1 * tierSize)
);
cylinderTopGeometry.faceVertexUvs[0].push([
new THREE.Vector2(0.5, 0.5),
new THREE.Vector2(x / 2 + 0.5, z / 2 + 0.5),
new THREE.Vector2(x1 / 2 + 0.5, z1 / 2 + 0.5)
]);
cylinderTopGeometry.faces.push(new THREE.Face3(i * 3, i * 3 + 1, i * 3 + 2));
}
cylinderTopGeometry.computeCentroids();
cylinderTopGeometry.computeFaceNormals();
var cylinderSideCanvas = document.createElement("canvas");
// cylinderSideCanvas = document.getElementById("canvas_container").appendChild(cylinderSideCanvas);
var cylinderSideTexture = new THREE.Texture(cylinderSideCanvas, new THREE.UVMapping());
var tierSideImage = new Image();
var cylinderTopCanvas = document.createElement("canvas");
// cylinderTopCanvas = document.getElementById("canvas_container").appendChild(cylinderTopCanvas);
var cylinderTopTexture = new THREE.Texture(cylinderTopCanvas, new THREE.UVMapping());
var tierTopImage = new Image();
var cylinderSideMaterial = new THREE.MeshLambertMaterial({map: cylinderSideTexture});
var cylinderSide = new THREE.Mesh(cylinderSideGeometry, cylinderSideMaterial);
var cylinderTopMaterial = new THREE.MeshLambertMaterial({map: cylinderTopTexture});
var cylinderTop = new THREE.Mesh(cylinderTopGeometry, cylinderTopMaterial);
var cylinderBottom = new THREE.Mesh(cylinderTopGeometry, cylinderTopMaterial);
cylinderTop.rotation.x = Math.PI;
cylinderTop.position.y = tierHeight / 2;
cylinderBottom.position.y = -tierHeight / 2;
var tier1Cylinder = new THREE.Object3D();
tier1Cylinder.add(cylinderSide);
tier1Cylinder.add(cylinderTop);
tier1Cylinder.add(cylinderBottom);
tier1Cylinder.position.set(0, 0, 0);
tierSideImage.onload = function() {
cylinderSideCanvas.width = tierSideImage.width;
cylinderSideCanvas.height = tierSideImage.height;
var cylinderSideCtx = cylinderSideCanvas.getContext('2d');
if (sideImage.indexOf('svg', sideImage.length - 3) !== -1) {
cylinderSideCtx.drawSvg(sideImage, 0, 0);
} else {
cylinderSideCtx.drawImage(tierSideImage, 0, 0);
}
tierTopImage.onload = function() {
cylinderTopCanvas.width = tierTopImage.width;
cylinderTopCanvas.height = tierTopImage.height;
var cylinderTopCtx = cylinderTopCanvas.getContext('2d');
if (topImage.indexOf('svg', topImage.length - 3) !== -1) {
cylinderTopCtx.drawSvg(topImage, 0, 0);
} else {
cylinderTopCtx.drawImage(tierTopImage, 0, 0);
}
if (pipingImage) {
var topImageRadius = cylinderTopCanvas.width;
var tierSize = 2 * Math.PI * topImageRadius;
var pipingWidth = pipingImage.width;
var pipingNumber = Math.round(tierSize / pipingWidth);
var rorateAngle = 2 * Math.PI / pipingNumber;
var sideImageWidthStep = cylinderSideCanvas.width / pipingNumber;
cylinderTopCtx.translate(topImageRadius / 2, topImageRadius / 2);
for (var i = 0; i < pipingNumber; i++) {
cylinderTopCtx.drawImage(pipingImage, topImageRadius / 2 - pipingWidth / 2, 0);
cylinderTopCtx.rotate(rorateAngle);
cylinderSideCtx.drawImage(pipingImage, (i - 1) * sideImageWidthStep, -pipingWidth / 2);
cylinderSideCtx.drawImage(pipingImage, (i - 1) * sideImageWidthStep, cylinderSideCanvas.height - pipingWidth / 2);
}
}
cylinderSideTexture.needsUpdate = true;
cylinderTopTexture.needsUpdate = true;
};
tierTopImage.src = topImage;
cylinderSideTexture.needsUpdate = true;
};
tierSideImage.src = sideImage;
return tier1Cylinder;
}
function animate()
{
requestAnimationFrame(animate);
render();
update();
}
function update()
{
if (keyboard.pressed("z"))
{
// do something
}
controls.update();
// stats.update();
}
function render()
{
renderer.render(scene, camera);
}
</script>
</body>
</html>