我正在拍摄图像,AVCapturePhotoOutput
然后使用他们的JPEG表示作为SceneKit上的纹理SCNPlane
,与图像的纵横比相同:
let image = UIImage(data: dataImage!)
let rectangle = SCNPlane(width:9, height:12)
let rectmaterial = SCNMaterial()
rectmaterial.diffuse.contents = image
rectmaterial.isDoubleSided = true
rectangle.materials = [rectmaterial]
let rectnode = SCNNode(geometry: rectangle)
let pos = sceneSpacePosition(inFrontOf: self.pictCamera, atDistance: 16.5) // 16.5 is arbitrary, but makes the rectangle the same size as the camera
rectnode.position = pos
rectnode.orientation = self.pictCamera.orientation
pictView.scene?.rootNode.addChildNode(rectnode)
Run Code Online (Sandbox Code Playgroud)
sceneSpacePosition
是一些可以在SO上找到的代码,它将CoreMotion映射到SceneKit方向.它用于放置矩形,确实出现在正确的位置,大小合适.一切都很酷.
问题是图像旋转90度到矩形.所以我明白了:
rectmaterial.diffuse.contentsTransform = SCNMatrix4MakeRotation(Float.pi / 2, 0, 0, 1)
Run Code Online (Sandbox Code Playgroud)
这不起作用; 生成的图像无法识别.看起来图像的一小部分已被拉伸到一个巨大的尺寸.我认为它可能是轴,但我尝试了所有三个相同的结果.
有任何想法吗?
小智 8
您正在按照Alain T的建议在左上角旋转.如果您向下移动图像,您可能会得到您期望的旋转.
试试这个:
let translation = SCNMatrix4MakeTranslation(0, -1, 0)
let rotation = SCNMatrix4MakeRotation(Float.pi / 2, 0, 0, 1)
let transform = SCNMatrix4Mult(translation, rotation)
rectmaterial.diffuse.contentsTransform = transform
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1655 次 |
最近记录: |