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

我找到了一些很好的例子:统一4-三维纹理(卷)、统一三维纹理或颜色校正查找纹理
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];
}
}
}但只有当你有
Texture2D.height= Mathf.FloorToInt(Mathf.Sqrt(Texture2D.width))或者如果
Depth = Width = Height当深度不等于宽度或高度时,如何提取值?看起来很简单但我遗漏了一些东西..。
非常感谢。
发布于 2014-05-11 08:22:15
您可以按以下方式分割纹理:
//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 (跳过一幅图像行)的增量.
或者如果你更喜欢另一个方向:
//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];发布于 2014-05-10 15:10:43
不幸的是,没有多少关于三维纺织的文件。我尝试过简单地使用c2D作为纹理的数据,但是它并没有给出一个适当的结果。
现在我试了一下,结果更好,但我不知道这是正确的。
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];
}
}
}发布于 2014-05-10 17:17:01
从你的照片,它看起来你有平面的三维纹理,你想并排?所以你想要三维纹理的尺寸(宽度,高度,深度)从二维纹理(宽度*深度,高度)?您应该能够这样做:
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));
}
}https://stackoverflow.com/questions/23582192
复制相似问题