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

viewer fails to generate normals for some shapes #258

Closed
alexneufeld opened this issue Feb 22, 2025 · 1 comment
Closed

viewer fails to generate normals for some shapes #258

alexneufeld opened this issue Feb 22, 2025 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@alexneufeld
Copy link

alexneufeld commented Feb 22, 2025

fidget-viewer test.rhai

// test.rhai

fn sdBox(x, y, z, xlen, ylen, zlen) {
    let qx = abs(x) - xlen;
    let qy = abs(y) - ylen;
    let qz = abs(z) - zlen;
    let qxm = max(qx, 0.0);
    let qym = max(qy, 0.0);
    let qzm = max(qz, 0.0);
    let qlen = sqrt(square(qxm) + square(qym) + square(qzm));
    qlen + min(max(qy, max(qx, qz)), 0.0)
}

let mybox = sdBox(x, y, z, 0.5, 0.5, 0.5);

draw(mybox);

Image

rendering this script with the viewer demo in 3D heightmap and 2D SDF mode works as expected, but the 3D color mode produces no output. Running fidget-cli mesh -i test.rhai -o test.stl -d 6 also produces no useable output. This is probably a stupid error on my part; if not, let me know what other info to provide for debugging.

Thanks!

@mkeeter
Copy link
Owner

mkeeter commented Feb 22, 2025

Hello!

This shape does not have well-defined partial derivatives near the surface, which is necessary to render normals. Specifically, it takes sqrt(0.0), whose partial derivatives are undefined and return NaN.

See #15, #127, #194

@mkeeter mkeeter closed this as completed Feb 22, 2025
@mkeeter mkeeter added the duplicate This issue or pull request already exists label Feb 22, 2025
@mkeeter mkeeter closed this as completed Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants