Skip to content

Commit

Permalink
Fix ground types 'hills' & 'canyon' not using seed
Browse files Browse the repository at this point in the history
  • Loading branch information
MakingSpiderSense committed Mar 27, 2021
1 parent 611b367 commit 869870c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ AFRAME.registerComponent('environment', {
if (!this.groundGeometry) {
this.groundGeometry = new THREE.PlaneGeometry(this.STAGE_SIZE + 2, this.STAGE_SIZE + 2, resolution - 1, resolution - 1);
}
var perlin = new PerlinNoise();
var perlin = new PerlinNoise(this.environmentData.seed);
var verts = this.groundGeometry.attributes.position.array;
var numVerts = verts.length;
var frequency = 10;
Expand Down Expand Up @@ -1206,13 +1206,14 @@ AFRAME.registerShader('gradientshader', {
// perlin noise generator
// from https://gist.github.com/banksean/304522

var PerlinNoise = function(r) {
if (r == undefined) r = Math;
var PerlinNoise = function(seed) {
var randomWithSeed;
this.grad3 = [[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]];
this.p = [];
var i;
for (i=0; i<256; i++) {
this.p[i] = Math.floor(r.random(666)*256);
randomWithSeed = parseFloat('0.' + Math.sin(seed * 9999 * i).toString().substr(7));
this.p[i] = Math.floor(randomWithSeed * 256);
}
// To remove the need for index wrapping, double the permutation table length
this.perm = [];
Expand Down

0 comments on commit 869870c

Please sign in to comment.