Esempio n. 1
0
        /// <summary>
        /// Create a VoxelModel and add it to the renderer
        /// </summary>
        /// <param name="width">The width of the model in voxels</param>
        /// <param name="height">The height of the model in voxels</param>
        /// <param name="depth">The depth of the model in voxels</param>
        /// <param name="transform">The transform of the model</param>
        /// <returns>The created VoxelModel</returns>
        public VoxelModel CreateModel(int width, int height, int depth, Transform transform)
        {
            VoxelModel model = new VoxelModel(_voxelData, _voxelData.Count, width, height, depth, transform);

            _models.Add(model);
            _modelData[0] = (ushort)_models.Count;
            _modelData.AddRange(new [] { width, height, depth, model.Offset });
            _voxelData.AddRange(new byte[model.Footprint]);
            _modelTransformations.AddRange(
                new [] {
                model.Transform.CalculateInverseMatrix(),
                model.Transform.CalculateMatrix(),
                model.Transform.CalculateNormalMatrix()
            });

            return(model);
        }
Esempio n. 2
0
        /// <summary>
        /// Remove a model from the renderer
        /// If this function returns true, using the model will result in undefined behaviour
        /// </summary>
        /// <param name="model">The model that needs to be removed</param>
        /// <returns>If the removal was successful</returns>
        public bool Remove(VoxelModel model)
        {
            int index = _models.FindIndex(0, m => m == model);

            if (!_models.Remove(model))
            {
                return(false);
            }

            _voxelData.Erase(model.Offset, model.Footprint);
            _modelData.Erase((index + 1) * 4, 4);
            _modelTransformations.Erase(index * 3, 3);

            for (int i = index; i < _models.Count; i++)
            {
                _models[i].Offset -= model.Footprint;
            }

            return(true);
        }