-
Notifications
You must be signed in to change notification settings - Fork 0
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
Etienne Dldc
committed
Nov 25, 2015
1 parent
dcbb502
commit e8a65aa
Showing
18 changed files
with
494 additions
and
170 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
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
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
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,98 @@ | ||
'use strict'; | ||
|
||
import THREE from 'three'; | ||
import OrbitControlsInit from 'three-orbit-controls'; | ||
import Forest from './objects/Forest'; | ||
|
||
window.THREE = THREE; | ||
const OrbitControls = OrbitControlsInit(THREE); | ||
|
||
export default class Webgl { | ||
constructor(width, height) { | ||
this.params = { | ||
usePostprocessing: false, | ||
}; | ||
|
||
this.scene = new THREE.Scene(); | ||
|
||
this.scene.fog = new THREE.Fog( 0x000000, 300, 1000 ); | ||
this.scene.fog.color.setHSL( 0, 0, 0 ); | ||
|
||
/** | ||
* LIGHTS | ||
*/ | ||
var ambientLight = new THREE.AmbientLight( 0xffffff ); | ||
this.scene.add( ambientLight ); | ||
|
||
var directionalLight = new THREE.DirectionalLight( Math.random() * 0xffffff ); | ||
directionalLight.position.x = Math.random() - 0.5; | ||
directionalLight.position.y = Math.random() - 0.5; | ||
directionalLight.position.z = Math.random() - 0.5; | ||
directionalLight.position.normalize(); | ||
//this.scene.add( directionalLight ); | ||
|
||
var directionalLight = new THREE.DirectionalLight( Math.random() * 0xffffff ); | ||
directionalLight.position.x = Math.random() - 0.5; | ||
directionalLight.position.y = Math.random() - 0.5; | ||
directionalLight.position.z = Math.random() - 0.5; | ||
directionalLight.position.normalize(); | ||
//this.scene.add( directionalLight ); | ||
|
||
/** | ||
* CAMERA | ||
*/ | ||
this.camera = new THREE.PerspectiveCamera(50, width / height, 1, 1000); | ||
this.camera.position.z = 600; | ||
this.camera.position.y = 30; | ||
this.camera.rotation.x = -0.3; | ||
this.camera.lookAt(new THREE.Vector3()) | ||
|
||
this.controls = new OrbitControls(this.camera); | ||
//this.controls.minDistance = 100; | ||
this.controls.maxDistance = 700; | ||
this.controls.minAzimuthAngle = -Math.PI/2; | ||
this.controls.maxAzimuthAngle = Math.PI/2; | ||
this.controls.minPolarAngle = 0; // radians | ||
this.controls.maxPolarAngle = Math.PI * 0.4; // radians | ||
|
||
this.renderer = new THREE.WebGLRenderer(); | ||
this.renderer.setSize(width, height); | ||
this.renderer.setClearColor(0x000000); | ||
|
||
this.composer = null; | ||
this.initPostprocessing(); | ||
} | ||
|
||
initPostprocessing() { | ||
if (!this.params.usePostprocessing) { return; } | ||
|
||
/* Add the effect composer of your choice */ | ||
} | ||
|
||
start() { | ||
this.forest = new Forest(); | ||
this.forest.position.set(0, 0, 0); | ||
this.scene.add(this.forest); | ||
} | ||
|
||
resize(width, height) { | ||
if (this.composer) { | ||
this.composer.setSize(width, height); | ||
} | ||
|
||
this.camera.aspect = width / height; | ||
this.camera.updateProjectionMatrix(); | ||
|
||
this.renderer.setSize(width, height); | ||
} | ||
|
||
render() { | ||
if (this.params.usePostprocessing) { | ||
console.warn('WebGL - No effect composer set.'); | ||
} else { | ||
this.renderer.render(this.scene, this.camera); | ||
} | ||
|
||
this.forest.update(); | ||
} | ||
} |
File renamed without changes.
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,89 @@ | ||
import THREE from 'three'; | ||
import Tree from './Tree'; | ||
|
||
export default class Forest extends THREE.Object3D { | ||
constructor() { | ||
super(); | ||
|
||
/** | ||
* GRID | ||
*/ | ||
var groundGeo = new THREE.Geometry(); | ||
// var size = 300, step = 50; | ||
// for ( var i = - size; i <= size; i += step ) { | ||
// groundGeo.vertices.push( new THREE.Vector3( - size, 0, i ) ); | ||
// groundGeo.vertices.push( new THREE.Vector3( size, 0, i ) ); | ||
// | ||
// groundGeo.vertices.push( new THREE.Vector3( i, 0, - size ) ); | ||
// groundGeo.vertices.push( new THREE.Vector3( i, 0, size ) ); | ||
// } | ||
var length = 15, step = 50, cutAngleRatio = 0.7; | ||
var size = length * step * 0.5, cutAngle = Math.floor(length * cutAngleRatio * 0.5); | ||
for ( var i = 0; i < length/2; i++ ) { | ||
let z = (-size) + (i * step); | ||
let xSub = (cutAngle-i) * step; | ||
xSub = xSub < 0 ? 0 : xSub; | ||
// top | ||
groundGeo.vertices.push( new THREE.Vector3( - size + xSub, 0, z ) ); | ||
groundGeo.vertices.push( new THREE.Vector3( size - xSub, 0, z ) ); | ||
// left | ||
groundGeo.vertices.push( new THREE.Vector3( z, 0, - size + xSub ) ); | ||
groundGeo.vertices.push( new THREE.Vector3( z, 0, size - xSub ) ); | ||
// bottom | ||
z = size - (i * step); | ||
groundGeo.vertices.push( new THREE.Vector3( - size + xSub, 0, z ) ); | ||
groundGeo.vertices.push( new THREE.Vector3( size - xSub, 0, z ) ); | ||
// right | ||
groundGeo.vertices.push( new THREE.Vector3( z, 0, - size + xSub ) ); | ||
groundGeo.vertices.push( new THREE.Vector3( z, 0, size - xSub ) ); | ||
} | ||
var groundMat = new THREE.LineBasicMaterial( { color: 0xFFFFFF, linewidth: 0.1, opacity: 0.4 } ); | ||
groundMat.transparent = true; | ||
this.groundLines = new THREE.LineSegments( groundGeo, groundMat ); | ||
this.add( this.groundLines ); | ||
|
||
/** | ||
* GENERATE THREE | ||
*/ | ||
this.trees = []; | ||
var treesPos = []; | ||
|
||
for (var i = 0; i < 97; i++) { | ||
var maxLoop = 50; | ||
var x, z; | ||
do { | ||
let posAngle = Math.random() * Math.PI * 2; | ||
let posDist = Math.random() * (size * 0.9 ); | ||
x = Math.cos(posAngle) * posDist; | ||
z = Math.sin(posAngle) * posDist; | ||
maxLoop--; | ||
if (maxLoop == 0) { console.log('max'); } | ||
} while (maxLoop > 0 && closestTree(x, z) < 30); | ||
treesPos.push([x, z]); | ||
|
||
var newTree = new Tree(); | ||
newTree.position.set(x, 0, z ); | ||
this.add(newTree); | ||
this.trees.push(newTree); | ||
} | ||
|
||
function closestTree(x, y) { | ||
var minDist = 1000; | ||
for (var i = 0; i < treesPos.length; i++) { | ||
var tx = treesPos[i][0]; | ||
var ty = treesPos[i][1]; | ||
var dx = tx - x; | ||
var dy = ty - y; | ||
var dist = Math.sqrt( (dy * dy) + (dx * dx)); | ||
if (dist < minDist) { minDist = dist } | ||
} | ||
return minDist; | ||
} | ||
|
||
|
||
} | ||
|
||
update() { | ||
|
||
} | ||
} |
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,21 @@ | ||
import THREE from 'three'; | ||
|
||
export default class Leaf extends THREE.Object3D { | ||
constructor(color) { | ||
super(); | ||
|
||
this.geom = new THREE.BoxGeometry( 0.3, 0.3, 0.3 ); | ||
this.mat = new THREE.MeshBasicMaterial({ | ||
color: color | ||
}); | ||
this.mesh = new THREE.Mesh(this.geom, this.mat); | ||
|
||
this.add(this.mesh); | ||
} | ||
|
||
|
||
|
||
update() { | ||
this.rotation.y += 0.01; | ||
} | ||
} |
Oops, something went wrong.