-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,465 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//= require Three | ||
//= require Globe | ||
|
||
GLOBE.ConnectivityModifier = function(radius) { | ||
this.radius = radius; | ||
}; | ||
|
||
GLOBE.ConnectivityModifier.prototype.constructor = GLOBE.ConnectivityModifier; | ||
|
||
GLOBE.ConnectivityModifier.prototype.modify = function(geometry) { | ||
var vertices = geometry.vertices; | ||
var faces = geometry.faces; | ||
var network = new Array(vertices.length); | ||
|
||
for (i=0; i<network.length; i++) { | ||
network[i] = { neighbours: [], normal: new THREE.Vector3(), position: vertices[i].position }; | ||
} | ||
|
||
for (i=0; i<faces.length; i++) { | ||
var face=faces[i]; | ||
var vertexSet = null; | ||
if(face instanceof THREE.Face3) { | ||
vertexSet = [face.a, face.b, face.c]; | ||
} else if(face instanceof THREE.Face4) { | ||
vertexSet = [face.a, face.b, face.c, face.d]; | ||
} | ||
|
||
vertexSet.forEach(function(value, index) { | ||
var node=network[value]; | ||
var nextVertex=vertexSet[(index+1) % vertexSet.length]; | ||
|
||
if(node.neighbours.indexOf(nextVertex)==-1) | ||
node.neighbours.push(nextVertex); | ||
|
||
node.normal.addSelf(face.normal); | ||
}); | ||
} | ||
|
||
for (i=0; i<network.length; i++) { | ||
network[i].normal.divideScalar(network[i].neighbours.length); | ||
} | ||
|
||
return network; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//= require Globe | ||
|
||
GLOBE.Gameplay = function(network, scene) { | ||
this.scene=scene; | ||
this.network=network; | ||
|
||
this.reset(); | ||
|
||
//amount of manufactured goods required to build various things | ||
this.FactoryCost = 10; | ||
this.SpaceCost = 1000; | ||
}; | ||
|
||
GLOBE.Gameplay.prototype.reset = function() { | ||
this.pollution=0; //planetary pollution | ||
this.capacity=0; //rate of manufacture | ||
this.manufactured_goods=this.FactoryCost; //current stock of manufactured goods | ||
|
||
for(i=0; i<this.network.length; i++) { | ||
var node = this.network[i]; | ||
if("building" in node && node.building!=null) { | ||
this.scene.removeObject(node.building); | ||
delete node.building; | ||
} | ||
if("joins" in node) { | ||
for(i=0; i<joins.length; i++) { | ||
this.scene.removeObject(node.joins[i]); | ||
delete node.joins[i]; | ||
} | ||
} | ||
|
||
this.network[i].building=null; | ||
this.network[i].joins = []; | ||
} | ||
} | ||
|
||
GLOBE.Gameplay.prototype.handlePlacement = function(placement) { | ||
var node = this.network[placement]; | ||
|
||
if(node.building!=null) return; | ||
|
||
var geometry = new THREE.CubeGeometry(50, 50, 50, 1, 1, 1); | ||
material = new THREE.MeshLambertMaterial( { color: 0x999999 } ); | ||
building = new THREE.Mesh( geometry, material ); | ||
|
||
building.position = node.normal.clone().multiplyScalar(20); | ||
building.position.addSelf(node.position); | ||
|
||
building.lookAt(building.position.clone().addSelf(network[placement].normal)); | ||
|
||
this.scene.add(building); | ||
|
||
node.building = building; | ||
|
||
for(i=0; i<node.neighbours.length; i++) { | ||
var neighbour = this.network[node.neighbours[i]]; | ||
if(neighbour.building != null) { | ||
var midpoint = node.position.clone().addSelf(neighbour.position).multiplyScalar(0.5); | ||
var avgnormal = node.normal.clone().addSelf(neighbour.normal); | ||
var offset = avgnormal.multiplyScalar(40).addSelf(midpoint); | ||
var joinCurve = new THREE.QuadraticBezierCurve3(node.position, offset, neighbour.position) | ||
var joinGeom = new THREE.Geometry(); | ||
joinGeom.vertices = joinCurve.getSpacedPoints(8).map(function(value) { return new THREE.Vertex(value); }); | ||
var joinMaterial = new THREE.LineBasicMaterial( { color: 0x00ff00 }); | ||
var join = new THREE.Line( joinGeom, joinMaterial, THREE.LineStrip); | ||
|
||
node.joins.push(join); | ||
this.scene.add(join); | ||
} | ||
} | ||
}; | ||
|
||
GLOBE.Gameplay.prototype.update = function() { | ||
this.network | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var GLOBE={}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//= require Three | ||
//= require Globe | ||
|
||
GLOBE.SphericalModifier = function(radius) { | ||
this.radius = radius; | ||
}; | ||
|
||
GLOBE.SphericalModifier.prototype.constructor = GLOBE.SphericalModifier; | ||
|
||
GLOBE.SphericalModifier.prototype.modify = function(geometry) { | ||
var vertices = geometry.vertices; | ||
|
||
for (i=0; i<vertices.length; i++) { | ||
vertices[i].position.setLength(this.radius); | ||
} | ||
|
||
delete geometry.__tmpVertices; | ||
|
||
geometry.computeCentroids(); | ||
geometry.computeFaceNormals(); | ||
geometry.computeVertexNormals(); | ||
}; |
Oops, something went wrong.