网上有很多,但大多使用Camera.RenderToCubemap接口,不能满足需求。
写了段代码可以载入6张图片,生成Cubemap
//Define Texture2D member p_x, p_y, p_z n_x, n_y, n_z if (p_x.width != p_x.height) throw new System.Exception("Create Error! width != height"); var cubemap = new Cubemap(p_x.width, p_x.format, false); var textureArr = new Texture2D[] { p_x, p_y, p_z, n_x, n_y, n_z }; for (int i = 0; i < textureArr.Length; i++) { var item = textureArr[i]; var path = AssetDatabase.GetAssetPath(item); var textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; textureImporter.isReadable = true; textureImporter.SaveAndReimport(); } //textureImporter. cubemap.SetPixels(p_x.GetPixels(), CubemapFace.PositiveX); cubemap.SetPixels(p_y.GetPixels(), CubemapFace.PositiveY); cubemap.SetPixels(p_z.GetPixels(), CubemapFace.PositiveZ); cubemap.SetPixels(n_x.GetPixels(), CubemapFace.NegativeX); cubemap.SetPixels(n_y.GetPixels(), CubemapFace.NegativeY); cubemap.SetPixels(n_z.GetPixels(), CubemapFace.NegativeZ); cubemap.Apply(); AssetDatabase.CreateAsset(cubemap, "Assets/MyCubemap.cubemap"); AssetDatabase.SaveAssets();
生成结果:
时间: 2024-11-17 03:48:39