子叶梧桐 子叶梧桐
关注数: 3 粉丝数: 27 发帖数: 798 关注贴吧数: 51
【求助】根据mask图片生成网格,但是有一块黑色的,有大佬帮忙看 上代码: using UnityEngine; public class MeshGeneratorScript : MonoBehaviour { // 用于生成网格的颜色纹理 public Texture2D colorTexture; // 网格的单元格大小 public float gridSize = 0.1f; private void Start() { // 在启动时生成网格 GenerateMesh(); } private void GenerateMesh() { // 获取颜色纹理的宽度和高度 int width = colorTexture.width; int height = colorTexture.height; // 获取颜色纹理的像素数组 Color[] pixels = colorTexture.GetPixels(); // 计算顶点数量和三角形数量 int vertexCount = (width * height); int triangleCount = (width - 1) * (height - 1)*6; // 创建顶点数组、法线数组和UV坐标数组 Vector3[] vertices = new Vector3[vertexCount]; Vector3[] normals = new Vector3[vertexCount]; Vector2[] uv = new Vector2[vertexCount]; // 创建三角形索引数组 int[] triangles = new int[triangleCount]; int vertexIndex = 0; int triangleIndex = 0; Color previousColor = pixels[0]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // 获取当前像素的颜色 Color pixelColor = pixels[y * width + x]; if (pixelColor != previousColor) { // 根据像素位置生成顶点 vertices[vertexIndex] = new Vector3(x * gridSize, 0, y * gridSize); Debug.Log("当前像素位置:" + new Vector3(x * gridSize, 0, y * gridSize)); // 设置法线方向为向上 normals[vertexIndex] = Vector3.up; // 设置UV坐标 uv[vertexIndex] = new Vector2((float)x / width, (float)y / height); if (x < width - 1 && y < height - 1) { // 生成三角形索引 triangles[triangleIndex] = vertexIndex; triangles[triangleIndex + 1] = vertexIndex + width; triangles[triangleIndex + 2] = vertexIndex + width + 1; triangles[triangleIndex + 3] = vertexIndex; triangles[triangleIndex + 4] = vertexIndex + width + 1; triangles[triangleIndex + 5] = vertexIndex + 1; triangleIndex += 6; } vertexIndex++; } previousColor = pixelColor; } } // 创建网格并赋值给MeshFilter组件 Mesh mesh = new Mesh(); mesh.vertices = vertices; mesh.normals = normals; mesh.uv = uv; mesh.triangles = triangles; GetComponent<MeshFilter>().mesh = mesh; } }
小米提审,因为写入SDCard数据被拒,有遇到的嘛 行为阶段:授权前行为 行为名称:写入SDCard数据(APP私有目录) 触发频次:7 主体名称:com.unity3d.player 包名:com.unity3d.player 详情:/data/user/0/com.beeinc.SQSBMM/shared_prefs/device_detail.xml 函数调用栈:java.io.FileOutputStream.<init>(FileOutputStream.java:214)<---java.io.FileOutputStream.<init>(FileOutputStream.java:174)<---android.app.SharedPreferencesImpl.createFileOutputStream(SharedPreferencesImpl.java:629)<---android.app.SharedPreferencesImpl.writeToFile(SharedPreferencesImpl.java:720)<---android.app.SharedPreferencesImpl.-wrap2(Unknown Source:0)<---android.app.SharedPreferencesImpl$2.run(SharedPreferencesImpl.java:599)<---android.app.SharedPreferencesImpl.enqueueDiskWrite(SharedPreferencesImpl.java:618)<---android.app.SharedPreferencesImpl.-wrap0(Unknown Source:0)<---android.app.SharedPreferencesImpl$EditorImpl.commit(SharedPreferencesImpl.java:534)<---com.unity3d.player.UnityPlayer.getDeviceId(Unknown Source:35)<---com.unity3d.player.UnityPlayer$d.doInBackground(Unknown Source:80)<---com.unity3d.player.UnityPlayer$d.doInBackground(Unknown Source:2)<---android.os.AsyncTask$2.call(AsyncTask.java:333)<---java.util.concurrent.FutureTask.run(FutureTask.java:266)<---android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)<---java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)<---java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)<---java.lang.Thread.run(Thread.java:764)
1 下一页