public static GameObject CreateGameObject( this IMeshBuilder meshBuilder, string name, Material material, bool meshCollider = false, bool calculateNormals = true, bool calculateBounds = true) { var go = new GameObject(); if (!string.IsNullOrEmpty(name)) { go.name = name; } var meshFilter = go.AddComponent <MeshFilter>(); var meshRenderer = go.AddComponent <MeshRenderer>(); meshFilter.mesh = meshBuilder.BuildMesh(calculateNormals, calculateBounds); meshRenderer.material = material; if (meshCollider) { go.AddComponent <MeshCollider>().sharedMesh = meshFilter.sharedMesh; } return(go); }
public static GameObject CreateGameObject(this IMeshBuilder meshBuilder, Material material) { var go = new GameObject(); var meshFilter = go.AddComponent <MeshFilter>(); var meshRenderer = go.AddComponent <MeshRenderer>(); meshFilter.mesh = meshBuilder.BuildMesh(); meshRenderer.material = material; return(go); }
/// <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(); } }); }
public static Mesh BuildMesh(this IMeshBuilder meshBuilder) { return(meshBuilder.BuildMesh(true, true)); }
public void BuildMesh(Mesh mesh, MeshData meshData) { builder.BuildMesh(mesh, meshData); }