示例#1
0
 protected override void OnCreateManager()
 {
     volumesGroup = GetComponentGroup(
         ComponentType.ReadOnly <VolumeAsset>(),
         ComponentType.Subtractive <VolumeSize>(),
         ComponentType.Subtractive <VolumePivot>());
     registry = World.GetOrCreateManager <VolumeAssetRegistry>();
 }
示例#2
0
        protected override void OnCreateManager()
        {
            // TODO: lets try to not shoot in feet. Check available VRAM before allocate memory :D
            //                     world size   chunk size
            cb            = new ComputeBuffer(ALLOCATION_SIZE, sizeof(int));
            allocationMap = new ComputeBuffer(WORLD_SIZE_X * WORLD_SIZE_Y * WORLD_SIZE_Z, sizeof(int));

            pooledIndexes = new Stack <int>();
            chunkIndexes  = new int[WORLD_SIZE_X * WORLD_SIZE_Y * WORLD_SIZE_Z];
            lastIndex     = 1;

            chunkViewArchetype = EntityManager.CreateArchetype(typeof(RenderMesh), typeof(Position));

            // create chunk mesh
            var tempCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            var mf       = tempCube.GetComponent <MeshFilter>();
            var cubeMesh = mf.mesh;

            mesh = new Mesh();
            // slide vertices (move pivot) to proper shader work
            mesh.vertices  = cubeMesh.vertices.Select(v => v * 2.05f + Vector3.one).ToArray();
            mesh.normals   = cubeMesh.normals;
            mesh.uv        = cubeMesh.uv;
            mesh.tangents  = cubeMesh.tangents;
            mesh.triangles = cubeMesh.triangles;

            Object.Destroy(tempCube);

            shader       = Shader.Find("Unlit/VoxelRender");
            bufferShader = Shader.Find("Unlit/VoxelRenderForBuffer");

            registry       = World.GetExistingManager <VolumeAssetRegistry>();
            renderingQueue = GetComponentGroup(new EntityArchetypeQuery
            {
                All = new[]
                {
                    ComponentType.ReadOnly <Chunk>(),
                    ComponentType.ReadOnly <ChunkPosition>(),
                    ComponentType.ReadOnly <ChunkVolumes>(),
                    ComponentType.ReadOnly <UpdateRenderCommand>(),
                },
            });
        }
示例#3
0
        protected override void OnCreateManager()
        {
            // TODO: lets try to not shoot in feet. Check available VRAM before allocate memory :D
            //                     world size   chunk size
            ChunksBuffer  = new ComputeBuffer(ALLOCATION_SIZE, sizeof(uint));
            AllocationMap = new ComputeBuffer(WORLD_SIZE_X * WORLD_SIZE_Y * WORLD_SIZE_Z, sizeof(uint));

            pooledIndexes = new Stack <uint>();
            chunkIndexes  = new NativeArray <uint>(WORLD_SIZE_X * WORLD_SIZE_Y * WORLD_SIZE_Z, Allocator.Persistent);

            lastIndex = 0;

            registry       = World.GetOrCreateManager <VolumeAssetRegistry>();
            renderingQueue = GetComponentGroup(new EntityArchetypeQuery
            {
                All = new[]
                {
                    ComponentType.ReadOnly <Chunk>(),
                    ComponentType.ReadOnly <ChunkPosition>(),
                    ComponentType.ReadOnly <ChunkVolumes>(),
                    ComponentType.ReadOnly <UpdateRenderCommand>(),
                },
            });
        }