/// <summary> /// Finalize the draw calls /// </summary> public void Commit(Vector3 position, Quaternion rotation, ref Bounds bounds #if DEBUG , string debugName = null #endif ) { ReleaseOldData(); for (int j = 0; j < Buffers.Length; j++) { var holder = Buffers[j]; var material = (m_materials == null || m_materials.Length < 1) ? null : m_materials[j]; for (int i = 0; i < holder.Count; i++) { var buffer = holder[i]; // No data means there's no mesh to build if (buffer.IsEmpty) { continue; } var go = GameObjectProvider.PopObject(m_prefabName); Assert.IsTrue(go != null); if (go != null) { #if DEBUG go.name = string.Format(debugName, "_", i.ToString()); #endif Mesh mesh = Globals.MemPools.MeshPool.Pop(); Assert.IsTrue(mesh.vertices.Length <= 0); buffer.SetupMesh(mesh, false); mesh.bounds = bounds; MeshFilter filter = go.GetComponent <MeshFilter>(); filter.sharedMesh = null; filter.sharedMesh = mesh; var t = filter.transform; t.position = position; t.rotation = rotation; Renderer renderer = go.GetComponent <Renderer>(); renderer.enabled = true; renderer.sharedMaterial = material; m_objects.Add(go); } buffer.Clear(); } } }
/// <summary> /// Finalize the draw calls /// </summary> public void Commit(Vector3 position, Quaternion rotation, Material material #if DEBUG , string debugName = null #endif ) { ReleaseOldData(); // No data means there's no mesh to build if (m_buffers[0].IsEmpty()) { return; } for (int i = 0; i < m_buffers.Count; i++) { GeometryBuffer buffer = m_buffers[i]; var go = GameObjectProvider.PopObject(m_prefabName); Assert.IsTrue(go != null); if (go != null) { #if DEBUG if (!string.IsNullOrEmpty(debugName)) { go.name = debugName; if (i > 0) { go.name = go.name + "_" + i; } } #endif Mesh mesh = Globals.MemPools.MeshPool.Pop(); Assert.IsTrue(mesh.vertices.Length <= 0); UnityMeshBuilder.BuildGeometryMesh(mesh, buffer); MeshFilter filter = go.GetComponent <MeshFilter>(); filter.sharedMesh = null; filter.sharedMesh = mesh; filter.transform.position = position; filter.transform.rotation = rotation; Renderer renderer = go.GetComponent <Renderer>(); renderer.material = material; m_objects.Add(go); m_renderers.Add(renderer); } buffer.Clear(); } }
/// <summary> /// Finalize the draw calls /// </summary> public void Commit() { ReleaseOldData(); // No data means there's no mesh to build if (m_renderBuffers[0].IsEmpty()) { return; } for (int i = 0; i < m_renderBuffers.Count; i++) { var go = GameObjectProvider.PopObject(GOPChunk); Assert.IsTrue(go != null); if (go != null) { Mesh mesh = Globals.Pools.MeshPool.Pop(); Assert.IsTrue(mesh.vertices.Length <= 0); m_meshBuilder.BuildMesh(mesh, m_renderBuffers[i]); MeshFilter filter = go.GetComponent <MeshFilter>(); filter.sharedMesh = null; filter.sharedMesh = mesh; filter.transform.position = Vector3.zero; m_drawCalls.Add(go); m_drawCallRenderers.Add(go.GetComponent <Renderer>()); } } // Make vertex data available again. We need to make this a task because our pooling system works on a per-thread // basis. Therefore, all Push()-es need to be called on the same thread as their respective Pop()-s. m_chunk.EnqueueGenericTask( () => { LocalPools pools = m_chunk.Pools; for (int i = 0; i < m_renderBuffers.Count; i++) { RenderBuffer buffer = m_renderBuffers[i]; for (int v = 0; v < buffer.Vertices.Count; v++) { pools.PushVertexData(buffer.Vertices[v]); } buffer.Clear(); } }); }
/// <summary> /// Finalize the draw calls /// </summary> public void Commit() { ReleaseOldData(); // No data means there's no mesh to build if (m_buffers[0].IsEmpty()) { return; } for (int i = 0; i < m_buffers.Count; i++) { GeometryBuffer buffer = m_buffers[i]; var go = GameObjectProvider.PopObject(GOPChunk); Assert.IsTrue(go != null); if (go != null) { #if DEBUG if (EngineSettings.CoreConfig.Mutlithreading == false) { go.name = m_chunk.Pos.ToString(); } #endif Mesh mesh = Globals.MemPools.MeshPool.Pop(); Assert.IsTrue(mesh.vertices.Length <= 0); m_meshBuilder.BuildMesh(mesh, buffer); MeshFilter filter = go.GetComponent <MeshFilter>(); filter.sharedMesh = null; filter.sharedMesh = mesh; filter.transform.position = Vector3.zero; filter.transform.rotation = Quaternion.identity; Renderer renderer = go.GetComponent <Renderer>(); //renderer.material = m_chunk.world.chunkMaterial; m_objects.Add(go); m_renderers.Add(renderer); } buffer.Clear(); } }