关于contentsTransform。3D变换矩阵是如何工作的?

5

我听说可以使用contentsTranform修改纹理。但是怎么做呢?contentsTranform是一个SCNMatrix,从文档中我可以使用SCNMatrix4MakeTranslation、SCNMatrix4MakeRotation和SCNMatrix4MakeScale函数来创建矩阵。但我不知道如何像第二张图片那样显示纹理。photoFrame是1:2,纹理是1:1。

enter image description here

enter image description here

enter image description here


Twice Edit:

我在材质编辑器中更改了比例尺、偏移和WrapT属性。效果很好。但是当我运行它时,无法获得相同的效果。所以我试着通过更改contentsTransform属性来编程。但是,比例尺和偏移都会影响contentsTransform。因此,如果offSet为(0,-4.03),比例尺为(1,1.714),则contentsTransform是多少

enter image description here


难道不是更容易将飞机的长宽比与图像相同,然后将其添加到框架节点中吗? - James P
我已经尝试过这个解决方案,但是我有许多具有不同纵横比的照片框架,我想创建一种简单的方法来选择图像并修改它,然后显示在照片框架中。 - HaoDong
有不同的图像,不仅仅是你在图片中看到的。 - HaoDong
1个回答

0

解决方案已移动@HaoDong的问题帖子中。

Now I know what's solution.

First

Don't load .dae file as the SCNScene. You are supported to use .scn file. The error happened because I use .dae file to modify texture in Scene Editor. Then I couldn't get the same result when I run it. After I changed it to .scn file and modify the texture. I get the right effect on real Device. You can simply convert .dae to .scn file by ->Editor->Convert to SceneKit scene file format.

Second

Both offset and Scale value affect the value of contentsTransform property. I have modify the texture in the material Editor View. if the offSet is (0, -4.03) and the Scale is (1, 1.714) the contentsTransform property is SCNMatrix4(m11: 1.0, m12: 0.0, m13: 0.0, m14: 0.0, m21: 0.0, m22: 1.714, m23: 0.0, m24: 0.0, m31: 0.0, m32: 0.0, m33: 1.0, m34: 0.0, m41: 0.0, m42: -4.03, m43: 0.0, m44: 1.0). By searching the doc, I found that how to get this property.

var matrixA =  SCNMatrix4MakeTranslation(0, -4.0, 0)
var matrixB = SCNMatrix4MakeScale(1, 1.345, 1)

var b = SCNMatrix4Mult(matrixB, matrixA)

Make sure it is MakeScale * MakeTranslation


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接