Ejemplo n.º 1
0
        /// <summary>
        /// Adds a new voxel model or updates it
        /// </summary>
        /// <param name="model"></param>
        public void SaveModel(VisualVoxelModel model)
        {
            model.VoxelModel.UpdateHash();

            lock (_syncRoot)
            {
                if (_models.ContainsKey(model.VoxelModel.Name))
                {
                    _models.Remove(model.VoxelModel.Name);
                    VoxelModelStorage.Delete(model.VoxelModel.Name);
                }
                _models.Add(model.VoxelModel.Name, model);
                VoxelModelStorage.Save(model.VoxelModel);
            }
        }
Ejemplo n.º 2
0
 public void Rename(string oldName, string newName)
 {
     lock (_syncRoot)
     {
         VisualVoxelModel model;
         if (!_models.TryGetValue(oldName, out model))
         {
             throw new InvalidOperationException("No such model to rename");
         }
         model.VoxelModel.Name = newName;
         VoxelModelStorage.Delete(oldName);
         VoxelModelStorage.Save(model.VoxelModel);
         _models.Remove(oldName);
         _models.Add(newName, model);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Request a missing model from the server
        /// </summary>
        /// <param name="name"></param>
        public void DownloadModel(string name)
        {
            logger.Info("Downloading model: {0}", name);

            try
            {
                var req      = WebRequest.Create(string.Format("http://utopiarealms.com/models/{0}/download", Uri.EscapeDataString(name)));
                var response = req.GetResponse();

                using (var stream = response.GetResponseStream())
                {
                    var voxelModel = VoxelModel.LoadFromStream(stream);

                    lock (_syncRoot)
                    {
                        if (_models.ContainsKey(voxelModel.Name))
                        {
                            _models.Remove(voxelModel.Name);
                        }

                        var model = new VisualVoxelModel(voxelModel, VoxelMeshFactory);
                        model.BuildMesh();
                        _models.Add(voxelModel.Name, model);
                        _pendingModels.Remove(voxelModel.Name);
                    }

                    _receivedModels.Enqueue(voxelModel);
                    VoxelModelStorage.Save(voxelModel);
                }

                response.Close();
            }
            catch (Exception x)
            {
                logger.Error("Unable to download the model: {0}", x.Message);
            }
        }