public void RequestRock(RockData rockData, Vector3 Pos, Action <GameObject> callback) { if (ThreadsAlive.Count >= MaxThreads) { ThreadMethodsToStart.Enqueue(() => RequestRock(rockData, Pos, callback)); return; } RockThreadReturnData ReturnData = new RockThreadReturnData(); //rockData.Setup(); ReturnData.RockPos = Pos; ReturnData.RockData = rockData; ReturnData.ManagerCallBack = ManagerCallBack; ReturnData.OriginalCallBack = callback; Thread t = new Thread(delegate() { RockGenerator.Build(ReturnData); }); t.IsBackground = true; t.Start(); ThreadsAlive.Add(t); }
public static void Build(RockThreadReturnData returnData) { RockData data = returnData.RockData; MeshDraft MD; switch (data.RockBasePrimitiveShape) { case RockData.BasePrimitiveShapes.Dodecahedron: MD = MeshDraft.Dodecahedron(0.5f); break; case RockData.BasePrimitiveShapes.Icosahedron: MD = MeshDraft.Icosahedron(0.5f, false); break; case RockData.BasePrimitiveShapes.Prism: MD = MeshDraft.Prism(0.5f, data.Segments, 1f, false); break; case RockData.BasePrimitiveShapes.Pyramid: MD = MeshDraft.Pyramid(0.5f, data.Segments, 1f, false); break; default: MD = MeshDraft.Sphere(0.5f, data.Segments, data.Segments, false); break; } ; MeshObjectData rock = new MeshObjectData(); rock.vertices = MD.vertices.ToArray(); rock.triangles = MD.triangles.ToArray(); rock.tangents = MD.tangents.ToArray(); rock.AutoWeldMesh(0.0001f, 0.4f); Vector3[] verts = rock.vertices; INoise noise = new SimplexNoise(data.RockSeed, 0.3f, 0.2f); Rand r = new Rand(data.RockSeed); for (int i = 0; i < verts.Length; i++) { float currentNoise = NoiseGen(noise, 3, verts[i].x / 0.5f, verts[i].y / 0.5f, verts[i].z / 0.5f); //currentNoise*=2; Vector3 norm = verts[i].normalized; verts[i].x += currentNoise * norm.x; verts[i].y += currentNoise * norm.y; verts[i].z += currentNoise * norm.z; verts[i].x *= 3; verts[i].y *= 1.2f; verts[i].z *= 1.5f; } rock.vertices = verts; rock.flatShade(); Color[] vertexColor = new Color[rock.vertices.Length]; for (int i = 0; i < rock.vertices.Length; i++) { vertexColor[i] = data.RockGradientColor.Color.Evaluate(1 - rock.vertices[i].y); } rock.colors = vertexColor; returnData.RockBuildData = rock; returnData.ManagerCallBack(returnData); }