-
Notifications
You must be signed in to change notification settings - Fork 0
/
yunnanchong.html
1089 lines (823 loc) · 28.8 KB
/
yunnanchong.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
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<title>webgl_ar</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<script src ="JSARToolKit.js"></script>
<script src="three.js "></script>
<script src="shaderwater.js"></script>
<script src = "ShaderGodRays.js"> </script>
<script src="FresnelShader.js"></script>
<script src="tween.min.js"></script>
<!--<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
<script type="text/javascript" src="js/Tween.js"></script>-->
<script src="Sparks.js"></script>
<script type = "x-shader/x-vertex" id = "vertexshader">
attribute float size;
attribute vec3 pcolor;
varying vec3 vColor;
void main() {
vColor = pcolor;
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_PointSize = 0.5*size * ( 200.0 / length( mvPosition.xyz ) );
gl_Position = projectionMatrix * mvPosition;
}
</script>
<script type = "x-shader/x-fragment" id = "fragmentshader">
uniform sampler2D texture;
varying vec3 vColor;
void main() {
vec4 outColor = texture2D( texture, gl_PointCoord );
gl_FragColor = outColor;
}
</script>
<script>
threshHold = 128;
var video = document.createElement('video');
video.width = 640;
video.height = 480;
video.loop = true;
video.volume = 0;
video.autoplay = true;
video.controls = true;
var clock = new THREE.Clock();
var scenepar;
var scene1, scene2, scene3, scene4, scene5, scene6;
var scenecube;
var renderer;
var ids = [];
var cubemesh;
var horsemesh,horsemesh2;
var treemesh;
var spheres = [];
var stonemesh;
var pyramidmesh;
var duration = 1000;
var keyframes = 15;
var interpolation = duration / keyframes;
var lastKeyframe = 0,currentKeyframe = 0;
var models=new Array(6);
var light1;
var light2;
var buffalo, animation;
var verticalMirrorMesh;
var text2;
var group;
var camerapar;
var speed = 50;
var targetRotation = 0;
var targetRotationOnMouseDown = 0;
var mouseX = 0;
var mouseXOnMouseDown = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
var deltapar = 1,clock = new THREE.Clock();
var heartShape, particleCloud, sparksEmitter, emitterpos;
var _rotation = 0;
var timeOnShapePath = 0;
var pointLight;
var timerrunning=false;
var timerid;
var timerid2;
var timerid3;
// Push indics
attributes = {
size: { type: 'f', value: [] },
pcolor: { type: 'c', value: [] }
};
function newpos(x, y, z) {
return new THREE.Vector3(x, y, z);
}
var Pool = {
__pools: [],
// Get a new Vector
get: function() {
if (this.__pools.length>0) {
return this.__pools.pop();
}
console.log("pool ran out!")
return null;
},
// Release a vector back into the pool
add: function(v) {
this.__pools.push(v);
},
};
THREE.ShaderLibzxm = {
'cube': {
uniforms: {
"tCube": {
type: "t",
value: null
},
"tFlip": {
type: "f",
value: -1
}
},
vertexShader: [
"varying vec3 vWorldPosition;",
"void main() {",
"vec4 worldPosition = vec4( position, 1.0 );",
"vWorldPosition = worldPosition.xyz;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join("\n"),
fragmentShader: [
"uniform samplerCube tCube;",
"uniform float tFlip;",
"varying vec3 vWorldPosition;",
"void main() {",
"gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
"}"
].join("\n")
}
};
var getUserMedia = function(t, onsuccess, onerror) {
if (navigator.getUserMedia) {
return navigator.getUserMedia(t, onsuccess, onerror);
} else if (navigator.webkitGetUserMedia) {
return navigator.webkitGetUserMedia(t, onsuccess, onerror);
} else if (navigator.mozGetUserMedia) {
return navigator.mozGetUserMedia(t, onsuccess, onerror);
} else if (navigator.msGetUserMedia) {
return navigator.msGetUserMedia(t, onsuccess, onerror);
} else {
onerror(new Error("No getUserMedia implementation found."));
}
};
var URL = window.URL || window.webkitURL;
var createObjectURL = URL.createObjectURL || webkitURL.createObjectURL;
if (!createObjectURL) {
throw new Error("URL.createObjectURL not found.");
}
getUserMedia({
'video': true
},
function(stream) {
var url = createObjectURL(stream);
video.src = url;
},
function(error) {
alert("Couldn't access webcam.");
}
);
window.onload = function() {
var canvas = document.createElement('canvas');
canvas.width = 320;
canvas.height = 240;
var videoCanvas = document.createElement('canvas');
videoCanvas.width = video.width;
videoCanvas.height = video.height;
var ctx = canvas.getContext('2d');
var raster = new NyARRgbRaster_Canvas2D(canvas);
var param = new FLARParam(320, 240);
var resultMat = new NyARTransMatResult();
var detector = new FLARMultiIdMarkerDetector(param, 120);
detector.setContinueMode(true);
var tmp = new Float32Array(16);
renderer = new THREE.WebGLRenderer();
renderer.sortObjects = false;
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.autoClear = false;
var glCanvas = renderer.domElement;
var s = glCanvas.style;
document.body.appendChild(glCanvas);
text2 = document.createElement('div');
text2.setAttribute("id", "Div1");
text2.style.position = 'absolute';
//text2.style.zIndex = 1; // if you still don't see the label, try uncommenting this
text2.style.width = 100;
text2.style.height = 100;
text2.style.backgroundColor = "blue";
//text2.innerHTML = "<font size='10'>hi there!</font>";
text2.style.top = 200 + 'px';
text2.style.left = 1000 + 'px';
document.body.appendChild(text2);
//THREEJS场景管理部分
var scene = new THREE.Scene();
//scene.fog = new THREE.FogExp2( 0xffffff, 0.00025 );
var picture = new THREE.ImageUtils.loadTexture('textures/cloud.png');
var pictureplane = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100, 0),
new THREE.MeshBasicMaterial({
map: picture
})
);
var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 100000);
camera.position.z = 0;
camera.position.y = 0;
camera.position.x = 0;
scene.add(camera);
param.copyCameraMatrix(tmp, 10, 10000);
camera.projectionMatrix.setFromArray(tmp);
light1 = new THREE.PointLight(0xffffff);
light1.position.set(0, 500, 500);
//scene.add(light);
light2 = new THREE.PointLight(0xffffff);
light2.position.set(0, -500, 500);
//scene.add(light);
var videoTex = new THREE.Texture(videoCanvas);
var plane = new THREE.Mesh(
new THREE.PlaneGeometry(2, 2, 0),
new THREE.MeshBasicMaterial({
map: videoTex
})
);
plane.material.depthTest = false;
plane.material.depthWrite = false;
var path = "textures/";
var format = '.png';
var urls = [
path + 'px' + format, path + 'nx' + format,
path + 'py' + format, path + 'ny' + format,
path + 'pz' + format, path + 'nz' + format
];
var textureCube = THREE.ImageUtils.loadTextureCube(urls);
var textureCube_refraction = THREE.ImageUtils.loadTextureCube(urls, new THREE.CubeRefractionMapping());
var cubeMaterial_refract = new THREE.MeshBasicMaterial({
color: 0xccddff,
envMap: textureCube_refraction,
refractionRatio: 0.8,
reflectivity: 0.98
});
var material_reflect = new THREE.MeshBasicMaterial({
color: 0xffffff,
envMap: textureCube
});
//气泡
var geometry = new THREE.SphereGeometry(20, 16, 16);
for (var i = 0; i < 100; i++) {
var mesh = new THREE.Mesh(geometry, cubeMaterial_refract);
mesh.position.x = Math.random() * 200 - 100;
mesh.position.y = Math.random() * 170 - 100;
mesh.position.z = Math.random() * 200 - 100;
mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 0.1 + 0.05;
spheres.push(mesh);
}
for (var i = 0; i < 100; i++) {
var mesh = new THREE.Mesh(geometry, material_reflect);
mesh.position.x = Math.random() * 200 - 100;
mesh.position.y = Math.random() * 170 - 100;
mesh.position.z = Math.random() * 200 - 100;
mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 0.1 + 0.05;
spheres.push(mesh);
}
//包围盒
var shader = THREE.ShaderLibzxm["cube"];
shader.uniforms["tCube"].value = textureCube;
var material = new THREE.ShaderMaterial({
fragmentShader: shader.fragmentShader,
vertexShader: shader.vertexShader,
uniforms: shader.uniforms,
depthWrite: false,
side: THREE.FrontSide
});
cubemesh = new THREE.Mesh(new THREE.CubeGeometry(200, 200, 200), material);
//马
var loader = new THREE.JSONLoader();
loader.load("models/yunnanchong.js", function(geometry, materials) {
var material_horse = new THREE.MeshFaceMaterial(materials);
var originalMaterial = materials[0];
originalMaterial.skinning = true;
originalMaterial.transparent = true;
//originalMaterial.alphaTest = 0.75;
THREE.AnimationHandler.add(geometry.animation);
horsemesh = new THREE.SkinnedMesh(geometry, material_horse, false);
//scene.add( buffalo );
var sc = 2;
horsemesh.rotation.y=Math.PI/6;
horsemesh.rotation.x=Math.PI;
horsemesh.scale.set(sc, sc, sc);
horsemesh.matrixAutoUpdate = false;
horsemesh.updateMatrix();
animation = new THREE.Animation(horsemesh, "Action");
animation.play();
//meshhorse.position.y = meshhorse.geometry.boundingSphere.radius * 0.5;
});
var loader = new THREE.JSONLoader();
loader.load("models/yunnanchong1.js", function(geometry, materials) {
var material_horse2 = new THREE.MeshFaceMaterial(materials);
var originalMaterial = materials[0];
originalMaterial.skinning = true;
originalMaterial.transparent = true;
//originalMaterial.alphaTest = 0.75;
//THREE.AnimationHandler.add(geometry.animation);
horsemesh2 = new THREE.SkinnedMesh(geometry, material_horse2, false);
//scene.add( buffalo );
var sc =3;
horsemesh2.scale.set(sc, sc, sc);
horsemesh2.matrixAutoUpdate = false;
horsemesh2.updateMatrix();
//animation = new THREE.Animation(horsemesh, "Action");
//animation.play();
//meshhorse.position.y = meshhorse.geometry.boundingSphere.radius * 0.5;
});
//水面
var noiseTexture = new THREE.ImageUtils.loadTexture('textures/cloud.png');
noiseTexture.wrapS = noiseTexture.wrapT = THREE.RepeatWrapping;
// MIRORR plane
verticalMirror = new THREE.FlatMirror(renderer, camera, {
clipBias: 0.003,
textureWidth: 800,
textureHeight: 600,
color: 0x1919B3, //333366,
baseTexture: THREE.ImageUtils.loadTexture("textures/water.jpg"),
baseSpeed: 1.15,
noiseTexture: noiseTexture,
noiseScale: 0.2,
alpha: 0.8,
time: 0.0,
});
verticalMirrorMesh = new THREE.Mesh(
new THREE.PlaneGeometry(200, 200, 5, 5),
verticalMirror.material
);
verticalMirrorMesh.add(verticalMirror);
verticalMirror.material.side = THREE.DoubleSide;
verticalMirrorMesh.position.set(0, 90, 0);
verticalMirrorMesh.rotation.x = Math.PI / 2;
var materialScene = new THREE.MeshBasicMaterial({
color: 0x000000,
shading: THREE.FlatShading
});
var tex = THREE.ImageUtils.loadTexture('models/skins/2008142271953.jpg', null, function() {
var mat = new THREE.MeshPhongMaterial({
map: tex
});
loader.load('models/diqiuyi.js', function(geo) {
treemesh = new THREE.Mesh(geo, mat);
treemesh.position.set(30, 0, 0);
treemesh.rotation.y=-Math.PI/1.7;
treemesh.rotation.x=Math.PI/3;
var sc = 2;
treemesh.scale.set(sc, sc, sc);
treemesh.matrixAutoUpdate = false;
treemesh.updateMatrix();
// etc, etc
});
});
loader.load('models/stone.js', function(geo, materials) {
var material_stone = new THREE.MeshFaceMaterial(materials);
stonemesh = new THREE.Mesh(geo, material_stone);
stonemesh.position.set(0, 0, 0);
stonemesh.rotation.y = -Math.PI / 1.7;
stonemesh.rotation.x = Math.PI / 3;
var sc = 2;
stonemesh.scale.set(sc, sc, sc);
stonemesh.matrixAutoUpdate = false;
stonemesh.updateMatrix();
// etc, etc
});
loader.load('models/jinzi.js', function(geo, materials) {
var material_jinzi = new THREE.MeshFaceMaterial(materials);
pyramidmesh = new THREE.Mesh(geo, material_jinzi);
pyramidmesh.position.set(0, 0, 0);
//pyramidmesh.rotation.y = -Math.PI / 1.7;
pyramidmesh.rotation.x = -Math.PI / 3;
var sc = 5;
pyramidmesh.scale.set(sc, sc, sc);
pyramidmesh.matrixAutoUpdate = false;
pyramidmesh.updateMatrix();
// etc, etc
});
//树
/*var loader = new THREE.JSONLoader();
loader.load("tree.js", function(geometry) {
treemesh = new THREE.Mesh(geometry, materialScene);
//treeMesh.position.set(2000, -3000, -1500);
var sc = 100;
treemesh.scale.set(sc, sc, sc);
treemesh.matrixAutoUpdate = false;
treemesh.updateMatrix();
});*/
//粒子系统部分
//scenepar=new THREE.Scene();
//camerapar = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 2000 );
//camerapar.position.set( 0, 150, 400 );
var directionalLight = new THREE.DirectionalLight( 0xffffff, 0.5 );
directionalLight.position.set( 0, -1, 1 );
directionalLight.position.normalize();
//scenepar.add( directionalLight );
pointLight = new THREE.PointLight( 0xffffff, 2, 300 );
pointLight.position.set( 0, 0, 0 );
//scenepar.add( pointLight );
group = new THREE.Object3D();
group.add(directionalLight);
group.add(pointLight);
//scenepar.add( group );
// Create particle objects for Three.js
var particlesLength = 70000;
var particles = new THREE.Geometry();
function newpos( x, y, z ) {
return new THREE.Vector3( x, y, z );
}
var Pool = {
__pools: [],
// Get a new Vector
get: function() {
if ( this.__pools.length > 0 ) {
return this.__pools.pop();
}
console.log( "pool ran out!" )
return null;
},
// Release a vector back into the pool
add: function( v ) {
this.__pools.push( v );
}
};
for ( i = 0; i < particlesLength; i ++ ) {
particles.vertices.push( newpos( Math.random() * 200 - 100, Math.random() * 100 + 150, Math.random() * 50 ) );
Pool.add( i );
}
// Create pools of vectors
attributes = {
size: { type: 'f', value: [] },
pcolor: { type: 'c', value: [] }
};
//var sprite = generateSprite() ;
//texture = new THREE.Texture( sprite );
texture = new THREE.ImageUtils.loadTexture('textures/haizao2.png');
texture.needsUpdate = true;
uniforms = {
texture: { type: "t", value: texture }
};
// PARAMETERS
// Steadycounter
// Life
// Opacity
// Hue Speed
// Movement Speed
function generateSprite() {
var canvas = document.createElement( 'canvas' );
canvas.width = 128;
canvas.height = 128;
var context = canvas.getContext( '2d' );
context.beginPath();
context.arc( 64, 64, 60, 0, Math.PI * 2, false) ;
context.lineWidth = 0.5; //0.05
context.stroke();
context.restore();
var gradient = context.createRadialGradient( canvas.width / 2, canvas.height / 2, 0, canvas.width / 2, canvas.height / 2, canvas.width / 2 );
gradient.addColorStop( 0, 'rgba(255,255,255,1)' );
gradient.addColorStop( 0.2, 'rgba(255,255,255,1)' );
gradient.addColorStop( 0.4, 'rgba(200,200,200,1)' );
gradient.addColorStop( 1, 'rgba(0,0,0,1)' );
context.fillStyle = gradient;
context.fill();
return canvas;
}
var shaderMaterial = new THREE.ShaderMaterial( {
uniforms: uniforms,
attributes: attributes,
vertexShader: document.getElementById( 'vertexshader' ).textContent,
fragmentShader: document.getElementById( 'fragmentshader' ).textContent,
//blending: THREE.AdditiveBlending,
depthWrite: false,
transparent: true
});
particleCloud = new THREE.ParticleSystem( particles, shaderMaterial );
particleCloud.dynamic = true;
// particleCloud.sortParticles = true;
var vertices = particleCloud.geometry.vertices;
var values_size = attributes.size.value;
var values_color = attributes.pcolor.value;
for( var v = 0; v < vertices.length; v ++ ) {
values_size[ v ] = 50;
values_color[ v ] = new THREE.Color( 0x000000 );
particles.vertices[ v ].set( Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY );
}
group.add( particleCloud );
group.scale.x=0.3;
group.scale.y=0.3;
group.scale.z=0.3;
particleCloud.y = 800;
// Create Particle Systems
// EMITTER STUFF
// Heart
var x = 0, y = 30;
heartShape = new THREE.Shape();
heartShape.moveTo( x + 25, y + 25 );
heartShape.bezierCurveTo( x + 25, y + 25, x + 20, y, x, y );
heartShape.bezierCurveTo( x - 30, y, x - 30, y + 35,x - 30,y + 35 );
heartShape.bezierCurveTo( x - 30, y + 55, x - 10, y + 77, x + 25, y + 95 );
heartShape.bezierCurveTo( x + 60, y + 77, x + 80, y + 55, x + 80, y + 35 );
heartShape.bezierCurveTo( x + 80, y + 35, x + 80, y, x + 50, y );
heartShape.bezierCurveTo( x + 35, y, x + 25, y + 25, x + 25, y + 25 );
var hue = 0;
var setTargetParticle = function() {
var target = Pool.get();
values_size[ target ] = Math.random() * 200 + 100;
return target;
};
var onParticleCreated = function( p ) {
var position = p.position;
p.target.position = position;
var target = p.target;
if ( target ) {
// console.log(target,particles.vertices[target]);
// values_size[target]
// values_color[target]
hue += 0.0003 * deltapar;
if ( hue > 1 ) hue -= 1;
// TODO Create a PointOnShape Action/Zone in the particle engine
timeOnShapePath += 0.0035 * deltapar;
if ( timeOnShapePath > 1 ) timeOnShapePath -= 1;
var pointOnShape = heartShape.getPointAt( timeOnShapePath );
emitterpos.x = pointOnShape.x * 3 - 100;
emitterpos.z = -pointOnShape.y * 3;
emitterpos.y=40*Math.cos(timeOnShapePath)-350;
// pointLight.position.copy( emitterpos );
pointLight.position.x = emitterpos.x;
pointLight.position.y = emitterpos.y;
pointLight.position.z = 100;
particles.vertices[ target ] = p.position;
values_color[ target ].setHSL( hue, 0.6, 0.1 );
pointLight.color.setHSL( hue, 0.8, 0.5 );
};
};
var onParticleDead = function( particle ) {
var target = particle.target;
if ( target ) {
// Hide the particle
values_color[ target ].setRGB( 0, 0, 0 );
particles.vertices[ target ].set( Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY );
// Mark particle system as available by returning to pool
Pool.add( particle.target );
}
};
var engineLoopUpdate = function() {
};
sparksEmitter = new SPARKS.Emitter( new SPARKS.SteadyCounter( 100 ) );
emitterpos = new THREE.Vector3( 0, 0, 0 );
sparksEmitter.addInitializer( new SPARKS.Position( new SPARKS.PointZone( emitterpos ) ) );
sparksEmitter.addInitializer( new SPARKS.Lifetime( 1, 10 ));
sparksEmitter.addInitializer( new SPARKS.Target( null, setTargetParticle ) );
sparksEmitter.addInitializer( new SPARKS.Velocity( new SPARKS.PointZone( new THREE.Vector3( 0, -5, 1 ) ) ) );
sparksEmitter.addAction( new SPARKS.Age() );
sparksEmitter.addAction( new SPARKS.Accelerate( 0, 100, 0 ) );
sparksEmitter.addAction( new SPARKS.Move() );
sparksEmitter.addAction( new SPARKS.RandomDrift( 90, 100, 100 ) );
sparksEmitter.addCallback( "created", onParticleCreated );
sparksEmitter.addCallback( "dead", onParticleDead );
//sparksEmitter.start();
//场景一对象
models[0]=new THREE.Object3D();
//场景二对象
models[1]=new THREE.Object3D();
//场景三对象
models[2]=new THREE.Object3D();
//场景四对象
models[3]=new THREE.Object3D();
//场景五对象
models[4]=new THREE.Object3D();
//场景六对象
models[5]=new THREE.Object3D();
var videoCam = new THREE.Camera();
var videoScene = new THREE.Scene();
videoScene.add(plane);
videoScene.add(videoCam);
var times = [];
var markers = {};
var lastTime = 0;
setInterval(render,33);
function render() {
//视频背景部分
if (video.ended) video.play();
if (video.paused) return;
if (window.paused) return;
if (video.currentTime == video.duration) {
video.currentTime = 0;
}
if (video.currentTime == lastTime) return;
lastTime = video.currentTime;
videoCanvas.getContext('2d').drawImage(video, 0, 0);
ctx.drawImage(videoCanvas, 0, 0, 320, 240);
var dt = new Date().getTime();
canvas.changed = true;
videoTex.needsUpdate = true;
//判别部分
var t = new Date();
var detected = detector.detectMarkerLite(raster, threshHold);
for (var idx = 0; idx < detected; idx++) {
var id = detector.getIdMarkerData(idx);
var currId;
if (id.packetLength > 4) {
currId = -1;
} else {
currId = 0;
for (var i = 0; i < id.packetLength; i++) {
currId = (currId << 8) | id.getPacketData(i);
}
}
if (!markers[currId]) {
markers[currId] = {};
}
detector.getTransformMatrix(idx, resultMat);
markers[currId].age = 0;
markers[currId].transform = Object.asCopy(resultMat);
}
//删除过期的
for (var i in markers) {
var r = markers[i];
if (r.age > 1) {
delete markers[i];
scene.remove(r.model);
}
r.age++;
}
selectModel();
//animationUpdate();
var timer = 0.0001 * Date.now();
for (var i = 0, il = spheres.length; i < il; i++) {
var sphere = spheres[i];
sphere.position.x = 100 * Math.cos(timer + i);
sphere.position.y = Math.sin(timer + i * 1.1) * 85- 15;
}
var delta = clock.getDelta();
verticalMirror.material.uniforms.time.value += delta;
THREE.AnimationHandler.update(delta);
deltapar = speed * delta;
particleCloud.geometry.verticesNeedUpdate = true;
attributes.size.needsUpdate = true;
attributes.pcolor.needsUpdate = true;
// Pretty cool effect if you enable this
// particleCloud.rotation.y += 0.05;
group.rotation.y += ( targetRotation - group.rotation.y ) * 0.05;
renderer.clear();
renderer.autoClear = false;
renderer.render(videoScene, videoCam);
renderer.render(scene, camera);
//renderer.render(scenepar, camerapar);
}
function animationUpdate() {
/*if (horsemesh)
{
var time = Date.now() % duration;
var keyframe = Math.floor(time / interpolation);
if (keyframe != currentKeyframe)
{
horsemesh.morphTargetInfluences[lastKeyframe] = 0;
horsemesh.morphTargetInfluences[currentKeyframe] = 1;
horsemesh.morphTargetInfluences[keyframe] = 0;
lastKeyframe = currentKeyframe;
currentKeyframe = keyframe;
}
horsemesh.morphTargetInfluences[keyframe] = (time % interpolation) / interpolation;
horsemesh.morphTargetInfluences[lastKeyframe] = 1 - horsemesh.morphTargetInfluences[keyframe];
}*/
}
function parstop()
{
console.log("par stop");
sparksEmitter.stop();
timerid2=setTimeout(function()
{
for ( i = 0; i < particles.vertices.length; i ++ )
{
particles.vertices[i].x=Number.POSITIVE_INFINITY;
particles.vertices[i].y=Number.POSITIVE_INFINITY;
particles.vertices[i].z=Number.POSITIVE_INFINITY;
}
//clearInterval(timerid2);
},1000);
//clearInterval(timerid);
}
function selectModel() {
var count=0;
for (var i in markers) {
count++;
var m = markers[i];
if (!m.model) {
switch (i) {
case "0":
m.model = models[0];
models[0].add(horsemesh);
//models[0].add(cubemesh);
for(var i=0,il=spheres.length;i<il;i++)
{
var sphere=spheres[i];
models[0].add(sphere);
}
//models[0].add(verticalMirrorMesh);
models[0].add(group);
sparksEmitter.start();
document.getElementById('Div1').innerHTML = "";
//console.log(timerrunning);
if(timerrunning==false)
{
console.log("start timer");
console.log(timerrunning);
timerid=setTimeout(parstop,15000);
timerrunning=true;
}
break;
case "1":
m.model = models[1];
models[1].add(treemesh);
document.getElementById('Div1').innerHTML = "<font size='5' color='red'>云南虫虫发现于云南澄江</font>"
break;
case "2":
m.model = models[2];
models[2].add(horsemesh2);
document.getElementById('Div1').innerHTML =
" <font size='3' color='red'>云南虫头顶长有一个大吸盘,可以用于吸附在别的动物身<br />"+
"上;云南虫的鳃腔较大,发育有7对鳃弓和一中柱,鳃<br />"+
"腔末端具一围鳃孔。云南虫正是通过这一系列特殊身体结<br />"+
"构营滤食生活,在口部经过初步筛选的小颗粒进入鳃腔<br />"+
",食物颗粒剂氧气在鳃腔中流动并被鳃丝附着,并通过咽<br />"+
"进入肠道,最后排出体外。<br />"+
" 云南虫最特别在于其拥有了脊椎的前身——脊索,比较<br />"+
"柔软,容易受到外力伤害,类似于今天脊髓中的软性物质<br />"+
"身体神经单元几种的脊索上,肢体的感觉可以通过脊<br />"+
"索传到全身。</font>";
break;
case "3":
m.model = models[3];
models[3].add(stonemesh);
document.getElementById('Div1').innerHTML = "";
break;
case "4":
m.model = models[4];
models[4].add(pyramidmesh);
document.getElementById('Div1').innerHTML = "";
break;
case "5":
m.model = models[5];
document.getElementById('Div1').innerHTML = "";