Esempio n. 1
0
        /// <summary>
        /// Called when the sample has to startup.
        /// </summary>
        /// <param name="targetRenderLoop">The target render loop.</param>
        public override async Task OnStartupAsync(RenderLoop targetRenderLoop)
        {
            targetRenderLoop.EnsureNotNull(nameof(targetRenderLoop));

            // Build dummy scene
            Scene        scene  = targetRenderLoop.Scene;
            Camera3DBase camera = targetRenderLoop.Camera as Camera3DBase;

            await targetRenderLoop.Scene.ManipulateSceneAsync((manipulator) =>
            {
                // Create floor
                SampleSceneBuilder.BuildStandardFloor(
                    manipulator, Scene.DEFAULT_LAYER_NAME);

                TextGeometryOptions textOptions = TextGeometryOptions.Default;
                textOptions.FontSize            = 50;
                textOptions.MakeVolumetricText  = true;
                textOptions.SurfaceVertexColor  = Color.Blue;
                textOptions.VolumetricSideSurfaceVertexColor = Color4.CornflowerBlue;

                GenericObject textObject = manipulator.Add3DText($"Seeing# {Environment.NewLine} Text3D Sample", textOptions);
                textObject.YPos          = textOptions.VolumetricTextDepth;
            });

            // Configure camera
            camera.Position       = new Vector3(0.7f, 8.5f, -15f);
            camera.RelativeTarget = new Vector3(0.44f, -0.62f, 0.64f);
            camera.UpdateCamera();
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a text geometry resource.
        /// </summary>
        /// <param name="textToDisplay">The text to be displayed.</param>
        /// <param name="textOptions">All options regarding the text geometry generator.</param>
        /// <param name="realignToCenter">Moves all vertices so that the center is 0.</param>
        public NamedOrGenericKey Add3DTextGeometryResource(string textToDisplay, TextGeometryOptions textOptions, bool realignToCenter = false)
        {
            var newGeometry = new Geometry();

            newGeometry.FirstSurface.BuildTextGeometry(
                textToDisplay,
                textOptions);
            if (realignToCenter)
            {
                newGeometry.RealignToCenter();
            }

            return(this.AddResource(_ => new GeometryResource(newGeometry)));
        }
        /// <summary>
        /// Adds a text object displaying the given text.
        /// </summary>
        /// <param name="textToDisplay">The text to be displayed.</param>
        /// <param name="textOptions">All options regarding the text geometry generator.</param>
        /// <param name="realignToCenter">Moves all vertices so that the center is 0.</param>
        /// <param name="layer">The layer on which to add the object.</param>
        public GenericObject Add3DText(string textToDisplay, TextGeometryOptions textOptions, bool realignToCenter = false, string layer = Scene.DEFAULT_LAYER_NAME)
        {
            VertexStructure newStructure = new VertexStructure();

            newStructure.FirstSurface.BuildTextGeometry(
                textToDisplay,
                textOptions);

            if (realignToCenter)
            {
                newStructure.RealignToCenter();
            }

            var resTextGeometry = this.AddResource(() => new GeometryResource(newStructure));

            return(this.AddGeneric(resTextGeometry, layer));
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a new text geometry with the given text.
        /// </summary>
        internal static GeometryResource AddTextGeometry(this ResourceDictionary resourceDictionary, NamedOrGenericKey resourceKey, string textToAdd, TextGeometryOptions textGeometryOptions)
        {
            var newGeometry = new Geometry();

            newGeometry.FirstSurface.BuildTextGeometry(textToAdd, textGeometryOptions);
            return(resourceDictionary.AddGeometry(resourceKey, newGeometry));
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes the scene for this model viewer.
        /// </summary>
        internal async Task InitializeAsync()
        {
            await m_scene.ManipulateSceneAsync((manipulator) =>
            {
                SceneLayer bgImageLayer = null;
                bool isBgImageCreated   = false;
                if (manipulator.ContainsLayer(Constants.LAYER_BACKGROUND_FLAT))
                {
                    bgImageLayer     = manipulator.GetLayer(Constants.LAYER_BACKGROUND_FLAT);
                    isBgImageCreated = true;
                }
                else
                {
                    bgImageLayer = manipulator.AddLayer(Constants.LAYER_BACKGROUND_FLAT);
                }

                SceneLayer bgLayer = manipulator.AddLayer(Constants.LAYER_BACKGROUND);
                manipulator.SetLayerOrderID(bgImageLayer, 0);
                manipulator.SetLayerOrderID(bgLayer, 1);
                manipulator.SetLayerOrderID(Scene.DEFAULT_LAYER_NAME, 2);

                var keyPostprocess = manipulator.AddResource <FocusPostprocessEffectResource>(
                    () => new FocusPostprocessEffectResource(false));
                if (!manipulator.ContainsLayer(Constants.LAYER_HOVER))
                {
                    SceneLayer layerHover                      = manipulator.AddLayer(Constants.LAYER_HOVER);
                    layerHover.PostprocessEffectKey            = keyPostprocess;
                    layerHover.ClearDepthBufferBeforeRendering = true;
                    manipulator.SetLayerOrderID(layerHover, 3);
                }

                // Store a reference to the background layer
                m_bgLayer = bgLayer;

                // Define background texture
                if (!isBgImageCreated)
                {
                    ResourceLink linkBackgroundTexture = new AssemblyResourceUriBuilder(
                        "SeeingSharpModelViewer", true,
                        "Assets/Textures/Background.dds");
                    NamedOrGenericKey resBackgroundTexture = manipulator.AddTexture(linkBackgroundTexture);
                    manipulator.Add(new FullscreenTextureObject(resBackgroundTexture), bgImageLayer.Name);
                }

                // Define ground
                Grid3DType objTypeGrid          = new Grid3DType();
                objTypeGrid.TilesX              = m_tilesPerSide * 4;
                objTypeGrid.TilesZ              = m_tilesPerSide * 4;
                objTypeGrid.HighlightXZLines    = true;
                objTypeGrid.TileWidth           = 0.25f;
                objTypeGrid.GroupTileCount      = 4;
                objTypeGrid.GenerateGround      = false;
                objTypeGrid.XLineHighlightColor = Color4.GreenColor;
                objTypeGrid.ZLineHighlightColor = Color4.BlueColor;

                NamedOrGenericKey resGridGeometry = manipulator.AddGeometry(objTypeGrid);
                manipulator.Add(new GenericObject(resGridGeometry), Constants.LAYER_BACKGROUND);

                TextGeometryOptions textXOptions = TextGeometryOptions.Default;
                textXOptions.SurfaceVertexColor  = Color4.GreenColor;
                textXOptions.MakeVolumetricText  = false;
                textXOptions.FontSize            = 30;
                GenericObject textX = manipulator.Add3DText(
                    "X", textXOptions,
                    realignToCenter: true,
                    layer: Constants.LAYER_BACKGROUND);
                textX.Position = new Vector3((m_tilesPerSide / 2f) + 1f, 0, 0);

                TextGeometryOptions textZOptions = TextGeometryOptions.Default;
                textZOptions.SurfaceVertexColor  = Color4.BlueColor;
                textZOptions.MakeVolumetricText  = false;
                textZOptions.FontSize            = 30;

                GenericObject textZ = manipulator.Add3DText(
                    "Z", textZOptions,
                    realignToCenter: true,
                    layer: Constants.LAYER_BACKGROUND);
                textZ.Position = new Vector3(0f, 0f, (m_tilesPerSide / 2f) + 1f);
            });
        }
        /// <summary>
        /// Adds a new text geometry with the given text.
        /// </summary>
        internal static GeometryResource AddTextGeometry(this ResourceDictionary resourceDiciontary, NamedOrGenericKey resourceKey, string textToAdd, TextGeometryOptions textGeometryOptions)
        {
            VertexStructure newStructure = new VertexStructure();

            newStructure.FirstSurface.BuildTextGeometry(textToAdd, textGeometryOptions);
            newStructure.FirstSurface.Material = textGeometryOptions.SurfaceMaterial;
            return(resourceDiciontary.AddGeometry(resourceKey, newStructure));
        }