刚刚学习Optix,下载了一些有关的示例程序,想请问一下大家,我是像下面图片里那样导入自己在unity里建立的一些模型,但是这样导入会使纹理图片被拉伸成和模型面一样大小然后粘贴在模型上,想请问一下,如果想让纹理图片在模型上重复平铺,应该更改哪些参数,或者应该怎样改代码。谢谢!
I just learned Optix and downloaded some related sample programs. I would like to ask everyone, I imported some of the models I created in Unity as shown in the picture below. However, importing in this way will cause the texture image to be stretched to the same size as the model face and pasted onto the model. I would like to ask which parameters or code changes should be made if I want the texture image to be repeatedly tiled on the model. Thank you!
It’s unclear where that code snippet you posted comes from.
None of those functions are part of the OptiX SDKs.
Which OptiX SDK version are you using?
The following applies to all graphics APIs and isn’t OptiX specific.
The placement of textures is controlled by the texture coordinates used inside the texture lookup functions of the respective graphics API.
Means if your 2D texture is applied to a rectangular geometry exactly once, then the 2D texture coordinates of the four corner vertices (in counter-clockwise ordering) are usually (0, 0), (1, 0), (1,1), (0, 1).
If you want the texture to be repeated more than once over that same geometry, than you would need to scale the texture coordinates bigger, e.g. using a factor of 2 would display the same texture four times on the same rectangle.
If the texture is repeated (or clamped or mirrored), depends on the texture wrap mode of that texture object.
The texture coordinates are usually defined by the OBJ file you loaded.
Check if there is a pool of texture coordinates inside your OBJ file. The lines with vt.
Then check if the geometric faces make use of them. That’s the case for OBJ face definitions with the second index set, like f 1/1 2/2 3/3 (vertex index, texcoord index) or f 1/1/1 2/2/2 3/3/3 (vertex index, texcoord index, normal index).
If that is the case, then you would either need to change the texture coordinates inside the OBJ during export to the desired texture coordinates, or change them after the OBJ has been loaded.
Means whatever the createTriangleMesh() does, that holds the texture coordinates somehere and you could change them inside that function.
Change the lines with vt which are the 2D uv texture coordinates at the face vertices defined later
For example, as I said before, scale all by a factor of two to have the texture displayed 4 times:
vt 0 0
vt 0 2
vt 2 2
vt 2 0
If you want it tiled vertically twice, only multiply the v coordinate like this:
vt 0 0
vt 0 2
vt 1 2
vt 1 0
Please don’t attach images of text, just post the text itself. Your posts got automatically flagged as SPAM due to that. Using text would make answering this quicker.
Also this is unrelated to OptiX and much too fundamental for the audience of this developer forum.
If you’re unfamiliar with computer graphics programming, I would recommend starting with some more basic tutorials.