Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added static vs animated modes

  • Loading branch information...
commit a7e8756b0d0877a99c66320713ee9d5ee0784831 1 parent f4c23a7
@doug doug authored
Showing with 51 additions and 50 deletions.
  1. +1 −12 globe-search/index.html
  2. +49 −37 globe/globe.js
  3. +1 −1  globe/index.html
View
13 globe-search/index.html
@@ -116,7 +116,6 @@
<script type="text/javascript" src="/globe/Three/ThreeExtras.js"></script>
<script type="text/javascript" src="/globe/Three/RequestAnimationFrame.js"></script>
<script type="text/javascript" src="/globe/Three/Detector.js"></script>
-<script type="text/javascript" src="/globe/Tween.js"></script>
<script type="text/javascript" src="/globe/globe.js"></script>
<script type="text/javascript">
@@ -136,19 +135,9 @@
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
window.data = data;
- var emptydata = [];
- for(var i=0;i<data.length;i+=4) {
- emptydata.push(data[i]);
- emptydata.push(data[i+1]);
- emptydata.push(0);
- emptydata.push(data[i+3]);
- }
- globe.addData(emptydata, "legend");
- globe.addData(data, "legend");
+ globe.addData(data, {format: 'legend'});
globe.createPoints();
globe.animate();
- TWEEN.start();
- new TWEEN.Tween(globe).to({time: 1},1500).easing(TWEEN.Easing.Bounce.EaseOut).start();
}
}
};
View
86 globe/globe.js
@@ -179,37 +179,42 @@ DAT.Globe = function(container, colorFn) {
}, false);
}
- addData = function(data, opt_format, opt_name) {
+ addData = function(data, opts) {
var lat, lng, size, color, i, step, colorFnWrapper;
- opt_format = opt_format || 'magnitude'; // other option is 'legend'
- if (opt_format === 'magnitude') {
+ opts.animated = opts.animated || false;
+ this.is_animated = opts.animated;
+ opts.format = opts.format || 'magnitude'; // other option is 'legend'
+ console.log(opts.format);
+ if (opts.format === 'magnitude') {
step = 3;
colorFnWrapper = function(data, i) { return colorFn(data[i+2]); }
- } else if (opt_format === 'legend') {
+ } else if (opts.format === 'legend') {
step = 4;
colorFnWrapper = function(data, i) { return colorFn(data[i+3]); }
} else {
- throw('error: format not supported: '+opt_format);
+ throw('error: format not supported: '+opts.format);
}
- if (this._baseGeometry === undefined) {
- this._baseGeometry = new THREE.Geometry();
- for (i = 0; i < data.length; i += step) {
- lat = data[i];
- lng = data[i + 1];
+ if (opts.animated) {
+ if (this._baseGeometry === undefined) {
+ this._baseGeometry = new THREE.Geometry();
+ for (i = 0; i < data.length; i += step) {
+ lat = data[i];
+ lng = data[i + 1];
// size = data[i + 2];
- color = colorFnWrapper(data,i);
- size = 0;
- addPoint(lat, lng, size, color, this._baseGeometry);
+ color = colorFnWrapper(data,i);
+ size = 0;
+ addPoint(lat, lng, size, color, this._baseGeometry);
+ }
}
+ if(this._morphTargetId === undefined) {
+ this._morphTargetId = 0;
+ } else {
+ this._morphTargetId += 1;
+ }
+ opts.name = opts.name || 'morphTarget'+this._morphTargetId;
}
- if(this._morphTargetId === undefined) {
- this._morphTargetId = 0;
- } else {
- this._morphTargetId += 1;
- }
- opt_name = opt_name || 'morphTarget'+this._morphTargetId;
var subgeo = new THREE.Geometry();
for (i = 0; i < data.length; i += step) {
lat = data[i];
@@ -219,31 +224,38 @@ DAT.Globe = function(container, colorFn) {
size = size*200;
addPoint(lat, lng, size, color, subgeo);
}
- this._baseGeometry.morphTargets.push({'name': opt_name, vertices: subgeo.vertices});
+ if (opts.animated) {
+ this._baseGeometry.morphTargets.push({'name': opts.name, vertices: subgeo.vertices});
+ } else {
+ this._baseGeometry = subgeo;
+ }
};
function createPoints() {
if (this._baseGeometry !== undefined) {
- if (this._baseGeometry.morphTargets.length < 8) {
- console.log('t l',this._baseGeometry.morphTargets.length);
- var padding = 8-this._baseGeometry.morphTargets.length;
- console.log('padding', padding);
- for(var i=0; i<=padding; i++) {
- console.log('padding',i);
- this._baseGeometry.morphTargets.push({'name': 'morphPadding'+i, vertices: this._baseGeometry.vertices});
+ if (this.is_animated === false) {
+ this.points = new THREE.Mesh(this._baseGeometry, new THREE.MeshBasicMaterial({
+ color: 0xffffff,
+ vertexColors: THREE.FaceColors,
+ morphTargets: false
+ }));
+ } else {
+ if (this._baseGeometry.morphTargets.length < 8) {
+ console.log('t l',this._baseGeometry.morphTargets.length);
+ var padding = 8-this._baseGeometry.morphTargets.length;
+ console.log('padding', padding);
+ for(var i=0; i<=padding; i++) {
+ console.log('padding',i);
+ this._baseGeometry.morphTargets.push({'name': 'morphPadding'+i, vertices: this._baseGeometry.vertices});
+ }
}
+ this.points = new THREE.Mesh(this._baseGeometry, new THREE.MeshBasicMaterial({
+ color: 0xffffff,
+ vertexColors: THREE.FaceColors,
+ morphTargets: true
+ }));
}
- this.points = new THREE.Mesh(this._baseGeometry, new THREE.MeshBasicMaterial({
- color: 0xffffff,
- vertexColors: THREE.FaceColors,
- morphTargets: true
- }));
-
- var update = function(i) {
- console.log('update');
- console.log(i);
- };
scene.addObject(this.points);
}
}
View
2  globe/index.html
@@ -174,7 +174,7 @@
var data = JSON.parse(xhr.responseText);
window.data = data;
for (i=0;i<data.length;i++) {
- globe.addData(data[i][1], "magnitude", data[i][0]);
+ globe.addData(data[i][1], {format: 'magnitude', name: data[i][0], animated: true});
}
globe.createPoints();
settime(globe,0)();

0 comments on commit a7e8756

Please sign in to comment.
Something went wrong with that request. Please try again.