简体   繁体   中英

Unwanted artefacts in SceneKit nodes with subdivisionLevel > 0

Ok, the code for this was quite long and complex so I'm going to have to describe this problem carefully.

Imagine you are creating a 3D object by lathing a set of points around an axis. You now want to generate a spherical texture map for these points. There is now a difficult dichotomy:

If you create a fully cyclical mesh, where the last points are joined to the first points and there are no edges that are not shared by two polygonal facets, then you cannot create a true spherical map. This is because vertices are mapped 1:1 with texture points. The leftmost vertex of the first facet would need to map to a U value of 0; the rightmost vertex of the last facet would map to 1 - but these are the same vertex! The result is that one segment of the mesh is textured with a large portion of the texture map from right to left, whereas all others map from left to right correctly.

纹理映射不正确

You could theoretically solve this by duplicating the first set of vertices so that they can have different texture coordinates depending on which polygon they relate to, but this surfaces another problem. If I do this and apply a subdivision level to the resulting geometry, an ugly crease appears and the texture seems badly distorted. It's not so obvious on a still image, but look in the bottom right of the image.

讨厌的“捏”

Ideally I would like to be able to apply a texture map AND subdivision to the same mesh without experiencing these ugly effects. Anybody got any ideas?

The crease in the subdivided model is standard subdivision behavior after duplicating those vertices. In fact, it's what I and many other 3D modellers do to create creases (opposed to the edge and vertex crease options even scenekit supports). So even though they are “unwanted” by you, it's expected behavior.

Imagine you are creating a 3D object by lathing a set of points around an axis. You now want to generate a spherical texture map for these points.

I'm having a hard time imagining why I would want to generate a spherical map for a torus. Spherical mapping is specifically for reflections.

Anyway, the problem is not the subdivision or the map, but the fact you use shared vertices.

but these are the same vertex!

Right. Instead of adding extra vertices at just the point where the texture basically repeats, you need to feed unique vertices to the SCNGeometry. That way subdivision will work and you can map it as expected.

Turns out my problem was actually that there were some redundant vertices in the profile I was attempting to rotate and this was just too much for subdivision to cope with. After removing these, the subdivision looks just fine - so there's probably just a limit to how complex a raw edge you can have on a model before subdivision packs in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM