예제 #1
0
        public static SceneBuildSettings ByParameters(string transformationStrategy,
                                                      string positioningStrategy,
                                                      CRSTransform crs,
                                                      UnitScale unitScale,
                                                      string[] sceneContexts,
                                                      string identificationStrategy)
        {
            if (string.IsNullOrEmpty(transformationStrategy) || string.IsNullOrEmpty(positioningStrategy) || string.IsNullOrEmpty(identificationStrategy))
            {
                throw new ArgumentNullException("transformationStrategy | positioningStrategy | identificationStrategy");
            }

            var settings = new SceneBuildSettings(new ExportPreferences
            {
                Transforming    = DynamicArgumentDelegation.TryCastEnumOrDefault <SceneTransformationStrategy>(transformationStrategy),
                Positioning     = DynamicArgumentDelegation.TryCastEnumOrDefault <ScenePositioningStrategy>(positioningStrategy),
                UserModelCenter = crs.Transform.T,
                CRS             = crs.Transform.R * (unitScale?.UnitsPerMeter ?? 1),
                SelectedContext = sceneContexts?.Select(c => new SceneContext {
                    Name = c.ToQualifier()
                }).ToArray() ?? new SceneContext[] { },
                ComponentIdentificationStrategy = DynamicArgumentDelegation.TryCastEnumOrDefault <SceneComponentIdentificationStrategy>(identificationStrategy)
            });

            return(settings);
        }
예제 #2
0
        public void ExportAsFBX()
        {
            try
            {
                var format3DS = ComponentScene.exportAsFormats.FirstOrDefault(f => f.ID == "fbx");
                Assert.IsNotNull(format3DS, "FBX export module exists");

                var exported = ComponentScene.Export(testScene, UnitScale.defined["m"], CRSTransform.ByLefthandYUp(CRSTransform.ByRighthandZUp()), format3DS.Extension, null);
                var log      = exported.GetActionLog();
                Assert.IsTrue(log.Select(l => l.Severity).All(s => LogSeverity.Info.IsAboveOrEqual(s)), "No warnings");
                Assert.IsTrue(log.Select(l => l.Reason).All(r => r.HasFlag(LogReason.Saved)), "Has been saved successfully");
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }
예제 #3
0
        /// <summary>
        /// Exports the current component scene to the given format indicated by the extension.
        /// </summary>
        /// <param name="scene">The scene</param>
        /// <param name="unitScale">The scale</param>
        /// <param name="transform">The axes transform</param>
        /// <param name="formatID">The format ID (one of <see cref="exportAsFormats"/>)</param>
        /// <param name="canonicalSeparator">The canonical fragment separator</param>
        /// <returns>The exported scene</returns>
        public static ComponentScene Export(ComponentScene scene, UnitScale unitScale, CRSTransform transform, string formatID, string canonicalSeparator)
        {
            if (null == scene)
            {
                throw new ArgumentNullException(nameof(scene));
            }

            var format = exportAsFormats.FirstOrDefault(f => f.ID == formatID);

            if (null == format)
            {
                throw new ArgumentException($"Unknown format ID {formatID}.");
            }

            var qualifier = BuildQualifierByExtension(scene.Qualifier, format.Extension);
            var fileName  = GetFilePathName(qualifier, canonicalSeparator, true);

            using (var monitor = scene.CreateProgressMonitor(LogReason.Saved))
            {
                try
                {
                    var exp = new TRexAssimp.TRexAssimpExport(new TRexAssimp.TRexAssimpPreferences(transform, unitScale));
                    monitor.NotifyProgressEstimateUpdate(1);
                    monitor.NotifyOnProgressChange(0, "Start exporting");

                    if (!exp.ExportTo(scene.SceneModel, fileName, format))
                    {
                        monitor.State.MarkBroken();
                        scene.OnActionLogged(
                            LogMessage.ByErrorMessage(scene.Name, LogReason.Saved, "An error occured while exporting to '{0}'. {1}", fileName, exp.StatusMessage));
                    }
                    else
                    {
                        monitor.NotifyOnProgressChange(1, "Exported");
                        scene.OnActionLogged(
                            LogMessage.BySeverityAndMessage(scene.Name, LogSeverity.Info, LogReason.Saved, "Scene exported to '{0}'.", fileName));
                    }
                }
                catch (Exception e)
                {
                    monitor.State.MarkBroken();

                    scene.Logger?.LogError(e, "An exception has been caught: {0}", e.Message);
                    scene.OnActionLogged(
                        LogMessage.ByErrorMessage(scene.Name, LogReason.Saved, "Exception '{0}' thrown while exporting to '{1}'.", e.Message, fileName));
                }

                monitor.State.MarkTerminated();
                monitor.NotifyOnProgressEnd();
            }

            return(scene);
        }