Numa

OPTIMIZE_WITH_UV causes un-smoothed normals after recomputing

Recommended Posts

Hi there, 

If you load an obj with the flag OPTIMIZE_WITH_UV=true then recompute the normals, you lose the smoothing.

playground: (switch line 14 from true to false hehe)

http://www.babylonjs-playground.com/#1U5GPV#50

Right now I have to pick between broken texture (flag set to false) or broken normals (flag set to true) :) 

any ideas?

 

Thanks

Share this post


Link to post
Share on other sites

yes but I edited the other post and started this new one, as the problem is not at all what I thought it was :) it has nothing to do with me moving verts. It's just that the "optimization" flag in the obj loader causes the normals to not recalculate correctly.

 

 

Share this post


Link to post
Share on other sites

Yes it looks like the change only takes effect if you reapply the vertex data (I can see it on another model where it affects the lighting)

I'm wondering how this even runs in the playground, there is a typo line 31, "inices" instead of "indices". If you fix the typo, it doesn't smooth :( 

I got excited for a moment :D

 

Share this post


Link to post
Share on other sites

thanks, I had a look and from what I can tell it only affect this function, which to be honest looks like minified code :D

var isInArrayUV = (arr: Array<{ normals: Array<number>; idx: Array<number>; uv: Array<number> }>, obj: Array<number>) => {
                if (!arr[obj[0]]) arr[obj[0]] = { normals: [], idx: [], uv: [] };
                var idx = arr[obj[0]].normals.indexOf(obj[1]);

                if (idx != 1 && (obj[2] == arr[obj[0]].uv[idx])) {
                    return arr[obj[0]].idx[idx];
                }
                return -1;
            };

Do we know who wrote the obj loader? I'd love to understand what this does :)

Share this post


Link to post
Share on other sites

this is not a bug

recompute calculate new normal with face points when we import .obj (with last uv ) with SceneLoader 

algorithm make separated face so recomputed method create flat normal

the best way to have correct normal is import that normal from obj and recalculate always have some part of data 

i work on new importer but i just can correct  non edge(uv edge) part of mesh

left : last uv + recompute 

center : raw object + recompute

right : scene loader 

http://www.babylonjs-playground.com/#D6IPT#5

bird : http://www.babylonjs-playground.com/#D6IPT#7

textured : http://www.babylonjs-playground.com/#D6IPT#6

solution :

1.import raw obj 

2.recompute normals

3. correct last uv problem + append new normal to created face

i need time to fix some bug and import this stuff 

 

 

 

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.