简体   繁体   English

在3D空间中旋转图像的一部分

[英]Rotating part of an image in 3D space

Here's the setup: This is for an ecommerce art site where some paintings are canvas transfers. 设置如下:这是一个电子商务艺术网站,其中一些画作是画布传输的。 The painting wraps around the sides and top and bottom of the canvas. 这幅画环绕着画布的侧面,顶部和底部。 We have high-res images of the entire painting, but what we want to display is a quasi-3D representation of the image in which you can see how the sides of the painting wrap around the canvas. 我们拥有整个绘画的高分辨率图像,但是我们要显示的是图像的准3D表示,您可以在其中看到绘画的侧面如何缠绕在画布上。 Here's a rough sketch of what I'm talking about: 这是我在说的粗略草图:

替代文字

My question is, how can I rotate an image in 3D space? 我的问题是,如何旋转3D空间中的图像? The approach I think I'd like to take, is to cut off a portion of the top and side of the image, and rotate then in 3D and then stich it back on to the top and side to give it the 3D look. 我想我要采取的方法是,切除图像顶部和侧面的一部分,然后以3D旋转,然后再将其粘贴回顶部和侧面,以使其具有3D外观。 How do I go about about doing that? 我该怎么做呢? It can be done using any .Net technology (GDI+, WPF etc.). 可以使用任何.Net技术(GDI +,WPF等)来完成。

In WPF using the ViewPort3D class you can create a cuboid which is 8x5x1 units. 在使用ViewPort3D类的WPF中,您可以创建一个8x5x1单位的长方体。 Create the image as a texture and then apply the texture to the front face (8x5) and the side faces (5x1) and the top and bottom faces (8x1) using texture coordinates. 将图像创建为纹理,然后使用纹理坐标将纹理应用于正面(8x5)和侧面(5x1)以及顶面和底面(8x1)。 The front face coordinates should be: (1/9, 1/6), (8/9, 1/6), (1/9, 5/6) and (8/9, 5/6) for the front face, and from the nearest edge to those coordinates for the sides, eg for the left side: (0, 1/6), (1/9, 1/6), (0, 5/6) and (1/9, 5/6) for the left side. 正面坐标应为:(1/9,1/6),(8/9,1/6),(1/9,5/6)和(8/9,5/6) ,以及从最接近的边缘到侧面的坐标,例如左侧:(0,1/6),(1/9,1/6),(0,5/6)和(1/9, 5/6)的左侧。

Edit: If you then want to be able to perform rotations on the 3D canvas model you can follow the advice here: How can I do 3D transformation in WPF? 编辑:如果您随后希望能够在3D画布模型上执行旋转,则可以遵循以下建议: 如何在WPF中进行3D转换?

It looks like you're not needing to do real 3D, but only needing to fake it. 看起来您不需要做真实的3D,而只需要伪造它。

Chop off four strips along the top, bottom, left and right of the image. 沿图像的顶部,底部,左侧和右侧切掉四个条。 Toss the bottom and right (going by your sketch in the question). 上下左右折腾(按问题中的草图进行)。 Scale and shear the strips (I'm not expert enough at .net/wpf to know how, but it can do it). 缩放和剪切条(我对.net / wpf不够专业,但是不知道如何做)。 The top would be scaled vertically by a factor of 0.5 (a guess - choose to fit the desired final 3D-looking image) and sheared horizontally. 顶部将垂直缩放0.5倍(猜测-选择以适合所需的最终3D外观图像),然后水平缩放。 The result is composited onto the output image as the top side of the canvas. 结果被合成到输出图像上,作为画布的顶部。 The left strip would be scaled horizontally and sheared vertically. 左侧的条将水平缩放并垂直剪切。

If the end user is to view the 3D canvas from different angles interactively, this method is probably faster than rendering an honest 3D model, which would have to do texture mapping and rasterizing the model into a final image, which amounts to doing the same math. 如果最终用户要从不同角度交互查看3D画布,则此方法可能比渲染诚实的3D模型更快,后者必须进行纹理映射并将模型栅格化为最终图像,这相当于执行相同的数学运算。 The fun part is figuring out how to adjust the scaling and shearing parameters. 有趣的部分是弄清楚如何调整缩放比例和剪切参数。

This page might be educational: http://www.idomaths.com/linear_transformation.php 该页面可能是教育性的: http : //www.idomaths.com/linear_transformation.php
and this could be useful reference http://en.csharp-online.net/GDIplus_Graphics_Transformation%E2%80%94Image_Transformation 这对参考http://en.csharp-online.net/GDIplus_Graphics_Transformation%E2%80%94Image_Transformation可能很有用

I dont have any experience in this kind of stuff. 我没有这类经验。 But when i saw this question, the first thing comes to my mind is the funny Unicornify for SO. 但是,当我看到这个问题时,我想到的第一件事就是有趣的Unicornify for SO。

In this making of article by balpha , he explained how the 2d unicorn sphere is rotated in 3d space. balpha 这篇文章中,他解释了2d独角兽球体如何在3d空间中旋转。

But the code is written in python. 但是代码是用python编写的。 If you are interested, you can take a look into that. 如果您有兴趣,可以看看。 But am not exactly sure this would help you. 但是我不确定这是否对您有帮助。

The brute force approach (which might be the easiest approach), is to map the u,v texture coordinates for each of the three faces, onto three billboards representing three sides of the canvas (a billboard is just two triangles that make a rectangle). 蛮力方法(可能是最简单的方法)是将三个面的每一个的u,v纹理坐标映射到代表画布三个侧面的三个广告牌上(一个广告牌只是两个三角形,组成一个矩形) 。 Then, rotate the whole canvas (all three billboards) using matrix transforms. 然后,使用矩阵变换旋转整个画布(所有三个广告牌)。 Tada! 田田!

Alternately, you can move the 3-space camera position with a transform, rather than the canvas. 或者,您可以通过变换而不是画布来移动3空间摄影机的位置。 Six of one, half the other - as they say. 六分之一,另一半-正如他们所说。

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

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