source: other-projects/playing-in-the-street/summer-2013/trunk/Playing-in-the-Street-WPF/Content/Web/mrdoob-three.js-4862f5f/src/objects/LOD.js@ 28897

Last change on this file since 28897 was 28897, checked in by davidb, 10 years ago

GUI front-end to server base plus web page content

File size: 1.6 KB
Line 
1/**
2 * @author mikael emtinger / http://gomo.se/
3 * @author alteredq / http://alteredqualia.com/
4 * @author mrdoob / http://mrdoob.com/
5 */
6
7THREE.LOD = function () {
8
9 THREE.Object3D.call( this );
10
11 this.objects = [];
12
13};
14
15
16THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
17
18THREE.LOD.prototype.addLevel = function ( object, distance ) {
19
20 if ( distance === undefined ) distance = 0;
21
22 distance = Math.abs( distance );
23
24 for ( var l = 0; l < this.objects.length; l ++ ) {
25
26 if ( distance < this.objects[ l ].distance ) {
27
28 break;
29
30 }
31
32 }
33
34 this.objects.splice( l, 0, { distance: distance, object: object } );
35 this.add( object );
36
37};
38
39THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
40
41 for ( var i = 1, l = this.objects.length; i < l; i ++ ) {
42
43 if ( distance < this.objects[ i ].distance ) {
44
45 break;
46
47 }
48
49 }
50
51 return this.objects[ i - 1 ].object;
52
53};
54
55THREE.LOD.prototype.update = function () {
56
57 var v1 = new THREE.Vector3();
58 var v2 = new THREE.Vector3();
59
60 return function ( camera ) {
61
62 if ( this.objects.length > 1 ) {
63
64 v1.setFromMatrixPosition( camera.matrixWorld );
65 v2.setFromMatrixPosition( this.matrixWorld );
66
67 var distance = v1.distanceTo( v2 );
68
69 this.objects[ 0 ].object.visible = true;
70
71 for ( var i = 1, l = this.objects.length; i < l; i ++ ) {
72
73 if ( distance >= this.objects[ i ].distance ) {
74
75 this.objects[ i - 1 ].object.visible = false;
76 this.objects[ i ].object.visible = true;
77
78 } else {
79
80 break;
81
82 }
83
84 }
85
86 for( ; i < l; i ++ ) {
87
88 this.objects[ i ].object.visible = false;
89
90 }
91
92 }
93
94 };
95
96}();
97
98THREE.LOD.prototype.clone = function () {
99
100 // TODO
101
102};
Note: See TracBrowser for help on using the repository browser.