public void Draw3DAsset(Asset3D asset) { Model model = asset.GetModel(); // Copy any parent transforms. Matrix[] transforms = new Matrix[model.Bones.Count]; model.CopyAbsoluteBoneTransformsTo(transforms); // Draw the model. A model can have multiple meshes, so loop. foreach (ModelMesh mesh in model.Meshes) { // This is where the mesh orientation is set, as well // as our camera and projection. foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateScale(0.1f) * Matrix.CreateFromQuaternion(asset.GetDirection()) * Matrix.CreateTranslation(asset.GetPosition()); effect.View = viewMatrix; effect.Projection = projectionMatrix; effect.FogEnabled = Fog.On; effect.FogStart = Fog.Start; effect.FogEnd = Fog.End; effect.FogColor = Fog.Colour; } // Draw the mesh, using the effects set above. mesh.Draw(); } }
public ActionResult Publish(AssetImages model) { if (!ModelState.IsValid) { return(View("Publish", model)); } model.asset.Publisher = User.Identity.Name; model.asset.ReleaseDate = DateTime.Now.ToString(); if (!model.File.FileName.EndsWith("rar") && !model.File.FileName.EndsWith("zip")) { return(View("Publish", model)); } string[] formats = new string[] { ".jpg", ".png", ".jpeg" }; bool Wrong = true; foreach (var image in model.Files) { foreach (var item in formats) { if (image.FileName.Contains(item)) { Wrong = false; break; } } } if (Wrong) { return(View("Publish", model)); } foreach (var file in model.Files) { if (file == null) { //at least 1 photo per asset return(View(model)); } else if (file.ContentLength > 0) { Picture c = new Picture(); c.ImageData = new byte[file.ContentLength]; file.InputStream.Read(c.ImageData, 0, c.ImageData.Length); _photoContext.AssetsPhotos.Add(c); _photoContext.SaveChanges(); if (model.asset.imagesId == null) { model.asset.imagesId = c.Id.ToString(); } else { model.asset.imagesId += "," + c.Id.ToString(); } } } if (model.File.ContentLength > 0) { MemoryStream target = new MemoryStream(); model.File.InputStream.CopyTo(target); byte[] data = target.ToArray(); model.asset.assetZip = data; } model.asset.Size = model.asset.assetZip.Count() / 1048576f; ////// if (model.asset.Type == "2D") { Asset2D asset2D = new Asset2D(model.asset); _context.Assets2D.Add(asset2D); } else if (model.asset.Type == "3D") { Asset3D asset3D = new Asset3D(model.asset); _context.Assets3D.Add(asset3D); } else if (model.asset.Type == "Audio") { AssetAudio assetAudio = new AssetAudio(model.asset); _context.AssetsAudio.Add(assetAudio); } else if (model.asset.Type == "Tools") { AssetTools assetTools = new AssetTools(model.asset); _context.AssetsTools.Add(assetTools); } else { return(HttpNotFound()); } try { _context.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Debug.WriteLine(model.asset.Type); } AllAssets allAssets = new AllAssets(); allAssets.assets2D = _context.Assets2D.ToList(); allAssets.assets3D = _context.Assets3D.ToList(); allAssets.assetsAudio = _context.AssetsAudio.ToList(); allAssets.assetsTools = _context.AssetsTools.ToList(); return(RedirectToAction("Index", allAssets)); }