public static JsonWrappers.AdvancedDownloadPreviewSettings ViewButton_Click(string PID, bool bConvert, bool bConvertTextures, bool bResizeTextures, bool bReducePolys, string NewModelFormat, string NewTextureFormat, int NewTextureSize, float PolygonThresh, bool Smoothing, bool IgnoreBoundry, float MaxError, float MaxEdgeLength, string mode) { if (!bConvert) { NewModelFormat = ".dae"; } Utility_3D.ConverterOptions opts = new Utility_3D.ConverterOptions(); if (bConvertTextures) { opts.EnableTextureConversion(NewTextureFormat); } if (bResizeTextures) { opts.EnableScaleTextures(NewTextureSize); } if (bReducePolys) { opts.EnablePolygonReduction(PolygonThresh); } opts.SetPolygonReductionSmoothing(Smoothing); opts.SetPolygonReductionMaxLength(MaxEdgeLength); opts.SetPolygonReductionMaxError(MaxError); if (mode == "Simple") { opts.SetPolygonReductionModeSimple(); } else { opts.SetPolygonReductionModeComplex(); } HttpContext.Current.Session["options"] = opts; HttpContext.Current.Session["format"] = NewModelFormat; // string PID = HttpContext.Current.Request.QueryString["ContentObjectID"]; DataAccessFactory factory = new vwarDAL.DataAccessFactory(); vwarDAL.IDataRepository vd = factory.CreateDataRepositorProxy(); ContentObject co = vd.GetContentObjectById(PID, false, false); JsonWrappers.AdvancedDownloadPreviewSettings jsReturnParams = new JsonWrappers.AdvancedDownloadPreviewSettings(); jsReturnParams.FlashLocation = co.Location; Utils.FileStatus currentStatus = new Utils.FileStatus("", Utils.FormatType.UNRECOGNIZED); //tempFedoraCO.DisplayFile = currentStatus.filename.Replace("zip", "o3d").Replace("skp", "o3d"); currentStatus.filename = co.Location; currentStatus.hashname = co.Location; jsReturnParams.IsViewable = true; jsReturnParams.BasePath = "../Public/"; jsReturnParams.BaseContentUrl = "Model.ashx?temp=true&file="; jsReturnParams.O3DLocation = currentStatus.hashname.ToLower().Replace("zip", "o3d").Replace("skp", "o3d"); jsReturnParams.FlashLocation = currentStatus.hashname; jsReturnParams.ShowScreenshot = true; jsReturnParams.UpAxis = co.UpAxis; jsReturnParams.UnitScale = co.UnitScale; string optionalPath = (co.Location.LastIndexOf("o3d", StringComparison.CurrentCultureIgnoreCase) != -1) ? "viewerTemp/" : "converterTemp/"; string pathToTempFile = "~/App_Data/" + optionalPath + co.Location; using (FileStream stream = new FileStream(HttpContext.Current.Server.MapPath(pathToTempFile), FileMode.Create, FileAccess.Write)) { Utility_3D.ConvertedModel model = GetAndConvertModel(PID); byte[] data = model.data; Utility_3D.ConvertedModel model2 = (new Utility_3D.Model_Packager()).Convert(new MemoryStream(model.data), "test.zip"); jsReturnParams.Polygons = model2._ModelData.VertexCount.Polys; stream.Write(data, 0, data.Length); stream.Close(); } HttpContext.Current.Session["contentObject"] = co; vd.Dispose(); return(jsReturnParams); // HttpContext.Current.Response.BinaryWrite(GetAndConvertModel().data); }
public static FileStatus DetectFormat(string filename) { FileStatus currentStatus = new FileStatus("", FormatType.UNRECOGNIZED); //The temp filename (hashname) is a sha1 hash plus a random number currentStatus.hashname = filename; currentStatus.msg = FileStatus.UnrecognizedMessage; //Check to see if it's an skp file if (string.Compare(currentStatus.hashname.Substring(currentStatus.hashname.LastIndexOf('.')), ".skp", true) == 0) { currentStatus.type = FormatType.VIEWABLE; currentStatus.extension = ".skp"; } else { int recognizedCount = 0; int viewableCount = 0; try { using (ZipFile zip = ZipFile.Read(HttpContext.Current.Server.MapPath("~/App_Data/") + currentStatus.hashname)) { int i = 0; foreach (string s in zip.EntryFileNames) { System.IO.FileInfo f = new System.IO.FileInfo(s); if (FileStatus.GetType(f.Extension) == FormatType.VIEWABLE) { if (zip.Entries[i].UncompressedSize == 0) { currentStatus.msg = FileStatus.ModelFileEmptyMessage; return currentStatus; } currentStatus.extension = f.Extension; currentStatus.type = FormatType.VIEWABLE; recognizedCount++; } else if (FileStatus.GetType(f.Extension) == FormatType.RECOGNIZED) { if (currentStatus.type != FormatType.VIEWABLE) { if (zip.Entries[i].UncompressedSize == 0) { currentStatus.msg = FileStatus.ModelFileEmptyMessage; return currentStatus; } currentStatus.extension = f.Extension; currentStatus.type = FormatType.RECOGNIZED; } currentStatus.msg = FileStatus.WarningMessage; viewableCount++; } i++; } } } catch (ZipException e) { currentStatus.msg = FileStatus.InvalidZipMessage; return currentStatus; } //Make sure there is only one recognized or viewable model format in the zip file //If multiple have been detected, set the format type and break if (viewableCount > 1) { currentStatus.type = FormatType.MULTIPLE_RECOGNIZED; currentStatus.msg = FileStatus.MultipleRecognizedMessage; } } if (currentStatus.type == FormatType.UNRECOGNIZED || currentStatus.type == FormatType.MULTIPLE_RECOGNIZED) { deleteTempFile(currentStatus.hashname); } else { HttpContext.Current.Session["fileStatus"] = currentStatus; } ContentObject tempFedoraObject = new ContentObject(); tempFedoraObject.UploadedDate = DateTime.Now; tempFedoraObject.LastModified = DateTime.Now; tempFedoraObject.Views = 0; tempFedoraObject.SubmitterEmail = HttpContext.Current.User.Identity.Name.Trim(); tempFedoraObject.Format = currentStatus.extension; HttpContext.Current.Session["contentObject"] = tempFedoraObject; return currentStatus; }
public static JsonWrappers.AdvancedDownloadPreviewSettings ViewButton_Click(string PID, bool bConvert, bool bConvertTextures, bool bResizeTextures, bool bReducePolys, string NewModelFormat, string NewTextureFormat, int NewTextureSize, float PolygonThresh, bool Smoothing, bool IgnoreBoundry, float MaxError, float MaxEdgeLength, string mode) { if (!bConvert) NewModelFormat = ".dae"; Utility_3D.ConverterOptions opts = new Utility_3D.ConverterOptions(); if (bConvertTextures) opts.EnableTextureConversion(NewTextureFormat); if (bResizeTextures) opts.EnableScaleTextures(NewTextureSize); if (bReducePolys) opts.EnablePolygonReduction(PolygonThresh); opts.SetPolygonReductionSmoothing(Smoothing); opts.SetPolygonReductionMaxLength(MaxEdgeLength); opts.SetPolygonReductionMaxError(MaxError); if (mode == "Simple") opts.SetPolygonReductionModeSimple(); else opts.SetPolygonReductionModeComplex(); HttpContext.Current.Session["options"] = opts; HttpContext.Current.Session["format"] = NewModelFormat; // string PID = HttpContext.Current.Request.QueryString["ContentObjectID"]; DataAccessFactory factory = new vwarDAL.DataAccessFactory(); vwarDAL.IDataRepository vd = factory.CreateDataRepositorProxy(); ContentObject co = vd.GetContentObjectById(PID, false, false); JsonWrappers.AdvancedDownloadPreviewSettings jsReturnParams = new JsonWrappers.AdvancedDownloadPreviewSettings(); jsReturnParams.FlashLocation = co.Location; Utils.FileStatus currentStatus = new Utils.FileStatus("", Utils.FormatType.UNRECOGNIZED); //tempFedoraCO.DisplayFile = currentStatus.filename.Replace("zip", "o3d").Replace("skp", "o3d"); currentStatus.filename = co.Location; currentStatus.hashname = co.Location; jsReturnParams.IsViewable = true; jsReturnParams.BasePath = "../Public/"; jsReturnParams.BaseContentUrl = "Model.ashx?temp=true&file="; jsReturnParams.O3DLocation = currentStatus.hashname.ToLower().Replace("zip", "o3d").Replace("skp", "o3d"); jsReturnParams.FlashLocation = currentStatus.hashname; jsReturnParams.ShowScreenshot = true; jsReturnParams.UpAxis = co.UpAxis; jsReturnParams.UnitScale = co.UnitScale; string optionalPath = (co.Location.LastIndexOf("o3d", StringComparison.CurrentCultureIgnoreCase) != -1) ? "viewerTemp/" : "converterTemp/"; string pathToTempFile = "~/App_Data/" + optionalPath + co.Location; using (FileStream stream = new FileStream(HttpContext.Current.Server.MapPath(pathToTempFile), FileMode.Create, FileAccess.Write)) { Utility_3D.ConvertedModel model = GetAndConvertModel(PID); byte[] data = model.data; Utility_3D.ConvertedModel model2 = (new Utility_3D.Model_Packager()).Convert(new MemoryStream(model.data), "test.zip"); jsReturnParams.Polygons = model2._ModelData.VertexCount.Polys; stream.Write(data, 0, data.Length); stream.Close(); } HttpContext.Current.Session["contentObject"] = co; vd.Dispose(); return jsReturnParams; // HttpContext.Current.Response.BinaryWrite(GetAndConvertModel().data); }