Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ground types 'hills' & 'canyon' not using seed #70

Merged
merged 1 commit into from
Oct 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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