Jump to content

Spheres get "corrupted" normals if radiusXYZ or diameterXYZ is used


G'kar
 Share

Recommended Posts

I was checking around the latest code of icosphere and find out that the normal are corrupted when radiusX/radiusY/radiusZ are used.
More over the BABYLON.MeshBuilder.CreateSphere seems to have the same issue if diameterX/Y/Z are used.
Both spheres use the normal define as line between vertex position to sphere center line.
Fine, but if the sphere is scaled to a flat ellipsoid with radiusY or diameterY for instance, then the (center --> ellipse point) is not the normal anymore.

I setup a basic playground to illustrate the issue (added blue line matching normal for several vertices):
flat sphere: http://www.babylonjs-playground.com/#24XHJP#2
flat icosphere: http://www.babylonjs-playground.com/#24XHJP#3

This can be fix "easily" in BJS code:

I have a tentative fix commit in my fork:

https://github.com/regis-c/Babylon.js/commit/f7d6b0159e8498943a689744cd5d019692e70191

(normals and shading seems much better when I run the playground code with the fix in my local setup)

 

Let me know if you think it is done in the right way (I didn't check much so side effect still possible).

Then I can send a PR if OK.
 

Link to comment
Share on other sites

Thanks for the showNormals() code : gives nice visual check for normal.

 

I play around with sphere, icosphere (flat=true), icosphere (flat=false), changing the radius scaling to see what happen.

(using my local BJS recompiled with the fix : https://github.com/r...d5d019692e70191)

The fix seems ok for me. The normals looks as I expect now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...