首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Texture2D到Texture3D

Texture2D到Texture3D
EN

Stack Overflow用户
提问于 2014-05-10 14:24:32
回答 3查看 1.6K关注 0票数 1

我想知道如何从一个Texture3D创建一个Texture2D。

我找到了一些很好的例子:统一4-三维纹理(卷)统一三维纹理颜色校正查找纹理

代码语言:javascript
复制
int     dim = tex2D.height;
Color[] c2D = tex2D.GetPixels();
Color[] c3D = new Color[c2D.Length];
for (int x = 0; x < dim; ++x)
{
    for (int y = 0; y < dim; ++y)
    {
        for (int z = 0; z < dim; ++z)
        {
            int y_ = dim - y - 1;
            c3D[x + (y * dim) + (z * dim * dim)] = c2D[z * dim + x + y_ * dim * dim];
        }
    }
}

但只有当你有

代码语言:javascript
复制
Texture2D.height= Mathf.FloorToInt(Mathf.Sqrt(Texture2D.width))

或者如果

代码语言:javascript
复制
Depth = Width = Height

当深度不等于宽度或高度时,如何提取值?看起来很简单但我遗漏了一些东西..。

非常感谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-05-11 08:22:15

您可以按以下方式分割纹理:

代码语言:javascript
复制
//Iterate the result
for(int z = 0; z < depth; ++z)
    for(int y = 0; y < height; ++y)
        for(int x = 0; x < width; ++x)
            c3D[x + y * width + z * width * height]
              = c2D[x + y * width * depth + z * width]

您可以按以下方式得到这个索引公式:

在x方向上前进1会导致1 (仅下一个像素)的增量.

在y方向上前进1会导致depth * width的增量(跳过4幅具有相应宽度的图像)。

在z方向上前进1会导致width (跳过一幅图像行)的增量.

或者如果你更喜欢另一个方向:

代码语言:javascript
复制
//Iterate the original image
for(int y = 0; y < height; ++y)
    for(int x = 0; x < width * depth; ++x)
         c3D[(x % width) + y * width + (x / width) * width * height] = c2D[x + y * width * depth];
票数 2
EN

Stack Overflow用户

发布于 2014-05-10 15:10:43

不幸的是,没有多少关于三维纺织的文件。我尝试过简单地使用c2D作为纹理的数据,但是它并没有给出一个适当的结果。

现在我试了一下,结果更好,但我不知道这是正确的。

代码语言:javascript
复制
for (int x = 0; x < width; ++x)
{
    for (int y = 0; y < height; ++y)
    {
        for (int z = 0; z < depth; ++z)
        {
            int y_ = height - y - 1;
            c3D[x + (y * height) + (z * height * depth)] = c2D[z * height + x + y_ * height * depth];
        }
    }
}
票数 1
EN

Stack Overflow用户

发布于 2014-05-10 17:17:01

从你的照片,它看起来你有平面的三维纹理,你想并排?所以你想要三维纹理的尺寸(宽度,高度,深度)从二维纹理(宽度*深度,高度)?您应该能够这样做:

代码语言:javascript
复制
for (int z = 0; z < depth; ++z)
{
    for (int y = 0; y < height; ++y)
    {
        memcpy(c3D + (z * height + y) * width, c2D + (y * depth + z) * width, width * sizeof(Color));
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23582192

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档