我想知道如何从Texture2D创建Texture3D。
我找到了一些很好的例子:Unity 4-3D纹理(体积)或Unity-3D纹理或颜色校正查找纹理
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
当深度不等于宽度或高度时,如何提取值?看起来很简单,但我想念的东西...
非常感谢你。
您可以按如下方式分割纹理:
//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];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句