Example #1
0
        private void ReleaseOldData()
        {
            for (int i = 0; i < objects.Count; i++)
            {
                GameObject go = objects[i];
                // If the component does not exist it means nothing else has been added as well
                if (go == null)
                {
                    continue;
                }

#if DEBUG
                go.name = prefabName;
#endif

                MeshFilter filter = go.GetComponent <MeshFilter>();
                filter.sharedMesh.Clear(false);
                Globals.MemPools.meshPool.Push(filter.sharedMesh);
                filter.sharedMesh = null;

                Renderer renderer = go.GetComponent <Renderer>();
                renderer.sharedMaterial = null;

                GameObjectProvider.PushObject(prefabName, go);
            }

            objects.Clear();
        }
Example #2
0
        /// <summary>
        ///     Creates a mesh and commits it to the engine. Bounding box set according to value passed in bounds
        /// </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++)
            {
                List <ColliderGeometryBuffer> holder = buffers[j];
                PhysicMaterial material = (materials == null || materials.Length < 1) ? null : materials[j];

                for (int i = 0; i < holder.Count; i++)
                {
                    ColliderGeometryBuffer buffer = holder[i];

                    // No data means there's no mesh to build
                    if (buffer.IsEmpty)
                    {
                        continue;
                    }

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

                    {
#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;

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

                        objects.Add(go);
                    }

                    buffer.Clear();
                }
            }
        }
Example #3
0
        /// <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++)
            {
                List <RenderGeometryBuffer> holder = Buffers[j];
                Material material = (materials == null || materials.Length < 1) ? null : materials[j];

                for (int i = 0; i < holder.Count; i++)
                {
                    RenderGeometryBuffer buffer = holder[i];

                    // No data means there's no mesh to build
                    if (buffer.IsEmpty)
                    {
                        continue;
                    }

                    GameObject go = GameObjectProvider.PopObject(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;
                        Transform t = filter.transform;
                        t.position = position;
                        t.rotation = rotation;

                        Renderer renderer = go.GetComponent <Renderer>();
                        renderer.enabled        = true;
                        renderer.sharedMaterial = material;

                        objects.Add(go);
                    }

                    buffer.Clear();
                }
            }
        }