Exemplo n.º 1
0
 public GpuShape(VoxelCell[,,] shape)
 {
     Shape = new GpuShapeInfo
     {
         Bounds = DiscreteBounds.Of(shape),
         Voxels = Gpu.Default.Allocate(Flatten(shape))
     };
 }
Exemplo n.º 2
0
        public GpuSpaceBufferContext(uint buffer, DiscreteBounds bounds)
        {
            CUDAInterop.cuGLRegisterBufferObject(buffer);

            _buffer        = buffer;
            _devicePointer = new deviceptr <VoxelFace>(GetDevicePointer());
            _bounds        = bounds;
        }
Exemplo n.º 3
0
        public GpuSpace(DiscreteBounds bounds)
        {
            _buffer  = Gl.GenBuffer();
            _texture = Gl.GenTexture();

            Bounds = bounds;

            Gl.BindBuffer(BufferTarget.TextureBuffer, _buffer);
            Gl.BufferData(BufferTarget.TextureBuffer, (uint)Marshal.SizeOf <VoxelFace>() * (uint)bounds.Length, null, BufferUsage.DynamicDraw);
        }
Exemplo n.º 4
0
        private static VoxelCell[] Flatten(VoxelCell[,,] shape)
        {
            var bounds = DiscreteBounds.Of(shape);

            var flatShape = new VoxelCell[bounds.Length];

            foreach (var coordinates in bounds)
            {
                flatShape[bounds.Index(coordinates)] = shape.At(coordinates);
            }

            return(flatShape);
        }
Exemplo n.º 5
0
        public static GpuShape LoadShape(string path, DiscreteBounds size, int borderSize)
        {
            var normalizedBounds = new Bounds
            {
                MinX = size.MinX + borderSize,
                MinY = size.MinY + borderSize,
                MinZ = size.MinZ + borderSize,
                MaxX = size.MaxX - borderSize,
                MaxY = size.MaxY - borderSize,
                MaxZ = size.MaxZ - borderSize,
            };

            var stlShape        = StlReader.LoadShape(path);
            var normalizedShape = ShapeNormalizer.NormalizeShape(stlShape, normalizedBounds);
            var voxelizedShape  = VoxelSpaceBuilder.Build(normalizedShape, size);

            return(new GpuShape(voxelizedShape));
        }
Exemplo n.º 6
0
 public void Load()
 {
     _gpuShape = ShapeLoader.LoadShape("./Examples/ball.stl", DiscreteBounds.OfSize(30, 30, 30), 5);
 }
Exemplo n.º 7
0
 public void Initialize()
 {
     _box      = new Box();
     _gpuSpace = new GpuSpace(DiscreteBounds.OfSize(30, 30, 30));
     _program  = new ShadingProgram();
 }