简体   繁体   English

如何生成纹理映射图像?

[英]How to generate texture mapping images?

I want to put/wrap images to 3D objects. 我想将图像放到/包装到3D对象。 To keep things simple and fast, instead of using(and learning) a 3D library I want to use mapping images. 为了保持简单和快速,我想使用映射图像,而不是使用(和学习)3D库。 Mapping images are used in such a way: 映射图像以这种方式使用:

映射用法

So you generate the mapping images once for each object and use the same mapping for all images you want to wrap. 因此,您为每个对象生成一次映射图像,并对要包装的所有图像使用相同的映射。

My question is how can I generate such mapping images (given the 3D model)? 我的问题是如何生成这样的映射图像(给定3D模型)? Since I don't know about the terminology my searches failed me. 由于我不知道术语,我的搜索失败了。 Sorry if I am using the wrong jargon. 对不起,如果我使用错误的行话。

Below you can see a description of the workflow. 您可以在下面看到工作流程的说明。
在此输入图像描述
I have the 3D model of the object and the input image, i want to generate mapping images that I can use to generate the textured image. 我有对象的3D模型和输入图像,我想生成可以用来生成纹理图像的映射图像。

I don't even know where to start, any pointers are appreciated. 我甚至不知道从哪里开始,任何指针都表示赞赏。

More info 更多信息

My initial idea was to somehow wrap a identity mappings (see below) using an external program. 我最初的想法是以某种方式使用外部程序包装身份映射(见下文)。 I have generated horizontal and vertical gradient images in Photoshop just to see if mapping works using photoshop generated images. 我已经在Photoshop中生成了水平和垂直渐变图像,只是为了看看是否使用photoshop生成的图像进行映射。 The result doesn't look good. 结果看起来不太好。 I wasn't hopeful but it was worth a shot. 我没有希望,但值得一试。

input 输入
在此输入图像描述

mappings (x and y), they just resize the image, they don't do anything fancy. 映射(x和y),它们只是调整图像大小,它们没有做任何花哨的事情。
在此输入图像描述在此输入图像描述

result 结果
在此输入图像描述
as you can see there are lots of artifacts. 你可以看到有很多文物。 Custom mapping images I have generated by warping the gradients even looks worse. 我通过扭曲渐变产生的自定义映射图像甚至看起来更糟。

Here is some more information on mappings: http://www.imagemagick.org/Usage/mapping/#distortion_maps 以下是有关映射的更多信息: http//www.imagemagick.org/Usage/mapping/#distortion_maps

I am using OpenCV remap() function for mapping. 我正在使用OpenCV remap()函数进行映射。

if i understand you right here, you want to do all of it in 2D ? 如果我在这里理解你,你想在2D中做所有这些吗?

calling warpPerspective() for each of your cube surfaces will be much more successful, than using remap() 为每个立方体曲面调用warpPerspective()将比使用remap()更成功

pseudocode outline: 伪代码轮廓:

// for each surface:
//  get the desired src and dst polygon
//  the src one is your texture-image, so that's:
     vector<Point> p_src(4), p_dst(4); 
     p_src[0] = Point(0,0); 
     p_src[1] = Point(0,src.rows-1); 
     p_src[2] = Point(src.cols-1,0);
     p_src[3] = Point(src.cols-1,src.rows-1);
// the dst poly is the one you want textured, a 3d->2d projection of the cube surface.
// sorry, you've got to do that on your own ;(
// let's say, you've come up with this for the cube - top:
     p_dst[0] = Point(15,15); 
     p_dst[1] = Point(44,19); 
     p_dst[2] = Point(56,30);
     p_dst[3] = Point(33,44);

// now you need the projection matrix to transform from one to another:
Mat proj = getPerspectiveTransform( p_src, p_dst );

// finally, you can warp your texture to the dst-polygon:
warpPerspective(src, dst, proj, dst.size());

if you can get hold of the 'Learning Opencv' book, it's described around p 170. 如果您能掌握“学习Opencv”一书,那么它将在第170页左右进行描述。

final word of warning, since youre complaining about artefacts, - yes, it'll all look pretty cheesy, 'real' 3d engines do a lot of work here, subpixel-uv mapping, filtering, mipmapping, etc. if you want it to look nice, consider using the 'real' thing. 警告的最后一句话,因为你抱怨人工制品, - 是的,它看起来都很俗气,'真正的'3D引擎在这里做了很多工作,亚像素映射,过滤,mipmapping等等,如果你想要它看起来不错,考虑使用'真实'的东西。

btw, there's nice opengl support built into opencv 顺便说一句,opencv内置了很好的opengl支持

To achieve what you are trying to do, you need to render the 3D-models UV to a texture. 要实现您要执行的操作,您需要将3D模型UV渲染到纹理。 It will be easier to learn to render 3D than to do things this way. 学习渲染3D比以这种方式做事更容易。 Especially since there are a lot of weaknesses in your aproach. 特别是因为你的方法存在很多缺点。 difficult to to lighting and problems til the depth-buffer will be abundant. 难以照明和问题直到深度缓冲将是丰富的。

Assuming all your objects shul ever only be viewed from one angle, you need to render each of them to 3 textures: 假设所有对象只能从一个角度查看,则需要将每个对象渲染为3个纹理:

UV-map UV-地图
Normal-map 普通地图
Depth-map (to correct the depth-buffer) 深度图(纠正深度缓冲区)

You will still have to do shading in order to draw these to look like your object, and I don't even know how to do the depth-buffer-thing, I just know it can be done. 你仍然需要做阴影以便将它们画成看起来像你的对象,我甚至不知道如何做深度缓冲的东西,我只知道它可以完成。

So in order to avoid learning 3D, your will have to learn all the difficult parts of 3D-rendering. 因此,为了避免学习3D,您必须学习3D渲染的所有难点部分。 Does not seem the easier route... 似乎不是更容易的路线......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM