Ejemplo n.º 1
0
        public void Clear()
        {
            foreach (var batch in batches.Values)
            {
                batch.Ranges.Clear();
            }

            gb.Clear();
            gb.ClearIndexes();
        }
        /// <summary>
        ///     Finalize the draw calls
        /// </summary>
        public void Commit(Vector3 position, Quaternion rotation, PhysicMaterial 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];

                // Create a game object for collider. Unfortunatelly, we can't use object pooling
                // here for otherwise, unity would have to rebake because of change in object position
                // and that is very time consuming.
                GameObject prefab = GameObjectProvider.GetPool(m_prefabName).Prefab;
                GameObject go     = Object.Instantiate(prefab);
                go.transform.parent = GameObjectProvider.Instance.ProviderGameObject.transform;

                {
#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.BuildColliderMesh(mesh, buffer);

                    MeshCollider collider = go.GetComponent <MeshCollider>();
                    collider.sharedMesh         = null;
                    collider.sharedMesh         = mesh;
                    collider.transform.position = position;
                    collider.transform.rotation = rotation;
                    collider.sharedMaterial     = material;

                    m_objects.Add(go);
                    m_colliders.Add(collider);
                }

                buffer.Clear();
            }
        }
Ejemplo n.º 3
0
        /// <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();
            }
        }
Ejemplo n.º 4
0
        /// <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();
            }
        }