SceneKit - Remove stitching line in edges borders

帅比萌擦擦* 提交于 2021-01-28 18:22:11

问题


I'm displaying a texture on a cube (see SceneKit - Map cube texture to box) Things work well now, but the result show a light stitching line between some of the cube faces that I outlined here (you are inside the cube):

Any idea how I can get rid of that? The input texture looks like

So there is some discontinuity in the input. I'm using a custom SceneKit geometry that doesn't do much more than mapping this texture to a cube. You can find the relevant code in question mentioned above: https://stackoverflow.com/a/38961244/2054629


回答1:


As a hacky solution, I've changed the geometry of the cube to be slightly not cubic and more like

So that the edges disappear (assuming the camera is inside). The texture is cropped a bit as a result, but this is much less noticeable.

I used to define the position of the 3 x 8 vertices as:

let _positions = [
  SCNVector3(x:-halfSide, y:-halfSide, z:  halfSide),
  SCNVector3(x: halfSide, y:-halfSide, z:  halfSide),
  SCNVector3(x:-halfSide, y:-halfSide, z: -halfSide),
  SCNVector3(x: halfSide, y:-halfSide, z: -halfSide),
  SCNVector3(x:-halfSide, y: halfSide, z:  halfSide),
  SCNVector3(x: halfSide, y: halfSide, z:  halfSide),
  SCNVector3(x:-halfSide, y: halfSide, z: -halfSide),
  SCNVector3(x: halfSide, y: halfSide, z: -halfSide),
]
let positions = _positions + _positions + _positions

and now I'm replacing the last line by:

let X = 0
let Y = 8
let Z = 16
func killEdgeStitching(positions: [SCNVector3], axis: Int) -> [SCNVector3] {
  var res = [SCNVector3]()
  let delta = Float(0.99)
  for pos in positions {
      var newPosition = SCNVector3(x: pos.x, y: pos.y, z: pos.z)
      switch axis {
      case X:
          newPosition.x *= delta
      case Y:
          newPosition.y *= delta
      default:
          newPosition.z *= delta
      }
      res.append(newPosition)
  }
  return res
}
let positions = killEdgeStitching(positions: _positions, axis: X) +
  killEdgeStitching(positions: _positions, axis: Y) +
  killEdgeStitching(positions: _positions, axis: Z)

I'll leave that out there, but hopefully someone will have a real answer!



来源:https://stackoverflow.com/questions/38961919/scenekit-remove-stitching-line-in-edges-borders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!