SceneKit,SCNMaterial的翻转方向 [英] SceneKit, flip direction of SCNMaterial

查看:52
本文介绍了SceneKit,SCNMaterial的翻转方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SceneKit非常新,因此只需在这里寻求帮助即可.

extremely new to SceneKit, so just looking for help here:

我有一个SCNSphere,在它的中央有一个摄像头

I have an SCNSphere with a camera at the center of it

我创建了一个SCNMaterial,doubleSided,并将其分配给球体

I create an SCNMaterial, doubleSided, and assign it to the sphere

由于相机位于中央,因此图像看起来是垂直翻转的,当里面的文字完全弄乱时.

Since the camera is at the center, the image looks flipped vertically, which when having text inside totally messes things up.

所以我该如何翻转材料或图像(尽管稍后将是视频中的帧),欢迎任何其他建议.

So how can i flip the material, or the image (although later it will be frames from a video), any other suggestion is welcome.

顺便说一句,这种解决方案对我来说是失败的,将normalImage用作材质(但是从球体内部看时图像会被翻转),但是分配flippedImage则不会有任何材质(白屏)

This solution, btw, is failing on me, normalImage is applied as a material (but the image is flipped when looking from inside the sphere), but assigning flippedImage results in no material whatsoever (white screen)

    let normalImage = UIImage(named: "text2.png")
    let ciimage = CIImage(CGImage: normalImage!.CGImage!)
    let flippeCIImage = ciimage.imageByApplyingTransform(CGAffineTransformMakeScale(-1, 1))
    let flippedImage = UIImage(CIImage: flippeCIImage, scale: 1.0, orientation: .Left)

    sceneMaterial.diffuse.contents = flippedImage
    sceneMaterial.specular.contents = UIColor.whiteColor()
    sceneMaterial.doubleSided = true
    sceneMaterial.shininess = 0.5

推荐答案

您可以使用SCNMaterialProperty的contentsTransform属性来翻转映射,而不是缩放节点(这可能会破坏照明):

Instead of scaling the node (which may break your lighting) you can flip the mapping using SCNMaterialProperty's contentsTransform property:

material.diffuse.contentsTransform = SCNMatrix4MakeScale(1,-1,1)
material.diffuse.wrapT = SCNWrapModeRepeat // or translate contentsTransform by (0,1,0)

这篇关于SceneKit,SCNMaterial的翻转方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆