1
votes

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):

enter image description here

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

enter image description here

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

1 Answers

0
votes

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

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!