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

TypeError: grad3(...) is undefined while using Perlin3. #21

Open
nrayamajhee opened this issue Apr 6, 2019 · 2 comments
Open

TypeError: grad3(...) is undefined while using Perlin3. #21

nrayamajhee opened this issue Apr 6, 2019 · 2 comments

Comments

@nrayamajhee
Copy link

I am using this library from npm and when I run the perlin3 function with -1 as the z parameter, I keep getting this error.

const perlin = new tumult.Perlin3(Math.random());
console.log(perlin.get(0,0,-1));
TypeError: grad3(...) is undefined
@philipjscott
Copy link
Owner

I'm kinda low on bandwidth at the moment; it's currently exam season for me.

I might be able to fix the bug after this weekend.

This particular issue is caused by Math.trunc(x) % 256 returning a negative number if x is negative. I use the result to deference a lookup array, which then returns undefined. I'll use x & 255 instead.

I've experimented and noticed other odd bugs, such as perlin.gen(0, 0, 512) returning numbers outside the [-1, 1] bound. This is why I'm holding back on a "hot fix"; I want to fix it properly when I get around to it.

Dunno what you're using the library for, but I know the library works well for positive fractional input

Eg.

const tumult = require('tumult')
const perlin = new tumult.Perlin3(Math.random())

for (let i = 0; i < 255; i++) {
  for (let j = 0; j < 255; j++) {
    for (let k = 0; k < 255; k++) {
      console.log(perlin.gen(i / 255, j / 255, k / 255))
    }
  }
}

I've created NodeJS bindings for a C++ noise library which you may want to use as an alternative: https://www.npmjs.com/package/fastnoisejs

@scott-cornwell
Copy link

Perlin 3 is still broken, it actually doesn't work at all for me. Throws an error Cannot read properties of undefined (reading 'dot'). grad3 is supposed to return an object that has a dot function and it returns undefined. All the noise is actually broken in this library sadly, it just returns 1 past a certain fairly low input (not sure the exact value). I'm not passing any negative numbers in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants