/// <summary>
        /// Builds the standard scene.
        /// </summary>
        /// <param name="newScene">The scenegraph to be updated.</param>
        /// <param name="newCamera">The camera to be updated.</param>
        public static void BuildStandardFloor(SceneManipulator manipulator, string sceneLayer)
        {
            SceneLayer bgLayer = manipulator.AddLayer("BACKGROUND");

            manipulator.SetLayerOrderID(bgLayer, 0);
            manipulator.SetLayerOrderID(Scene.DEFAULT_LAYER_NAME, 1);
            ResourceLink sourceBackgroundTexture = new AssemblyResourceLink(
                typeof(SeeingSharpSampleResources),
                "Textures.Background.dds");
            ResourceLink sourceTileTexture = new AssemblyResourceLink(
                typeof(SeeingSharpSampleResources),
                "Textures.Floor.dds");

            var resBackgroundTexture = manipulator.AddTexture(sourceBackgroundTexture);

            manipulator.Add(new FullscreenTextureObject(resBackgroundTexture), bgLayer.Name);

            // Define textures and materials
            var resTileTexture  = manipulator.AddResource(() => new StandardTextureResource(sourceTileTexture));
            var resTileMaterial = manipulator.AddResource(() => new SimpleColoredMaterialResource(resTileTexture));

            // Define floor geometry
            FloorType floorType = new FloorType(new Vector2(4f, 4f), 0f);

            floorType.BottomMaterial       = resTileMaterial;
            floorType.DefaultFloorMaterial = resTileMaterial;
            floorType.SideMaterial         = resTileMaterial;
            floorType.SetTilemap(25, 25);

            // Add floor to scene
            var resFloorGeometry = manipulator.AddResource((() => new GeometryResource(floorType)));
            var floorObject      = manipulator.AddGeneric(resFloorGeometry, sceneLayer);
        }
Example #2
0
        /// <summary>
        /// Builds a floor to the given scene.
        /// </summary>
        protected void BuildStandardFloor(SceneManipulator manipulator, string sceneLayer)
        {
            var bgLayer = manipulator.AddLayer("BACKGROUND");

            manipulator.SetLayerOrderId(bgLayer, 0);
            manipulator.SetLayerOrderId(Scene.DEFAULT_LAYER_NAME, 1);
            ResourceLink sourceBackgroundTexture = new AssemblyResourceLink(
                typeof(SampleBase),
                "Assets.Background.dds");
            ResourceLink sourceTileTexture = new AssemblyResourceLink(
                typeof(SampleBase),
                "Assets.Floor.dds");

            var resBackgroundTexture = manipulator.AddTextureResource(sourceBackgroundTexture);

            manipulator.AddObject(new FullscreenTexture(resBackgroundTexture), bgLayer.Name);

            // Define textures and materials
            var resTileTexture  = manipulator.AddResource(device => new StandardTextureResource(sourceTileTexture));
            var resTileMaterial = manipulator.AddResource(device => new StandardMaterialResource(resTileTexture));

            // Define floor geometry
            var floorType = new FloorGeometryFactory(new Vector2(4f, 4f));

            floorType.SetTilemap(25, 25);

            // AddObject floor to scene
            var resFloorGeometry = manipulator.AddResource(device => new GeometryResource(floorType));

            manipulator.AddMeshObject(resFloorGeometry, sceneLayer, resTileMaterial);
        }
Example #3
0
 /// <summary>
 /// Adds a new texture resource to the scene.
 /// </summary>
 /// <param name="sceneManipulator">The manipulator of the scene.</param>
 /// <param name="textureSourceHighQuality">The source of the texture in high quality.</param>
 /// <param name="textureSourceLowQuality">The texture in low quality.</param>
 public static NamedOrGenericKey AddTextureResource(
     this SceneManipulator sceneManipulator,
     ResourceLink textureSourceHighQuality,
     ResourceLink textureSourceLowQuality)
 {
     return sceneManipulator.AddResource(_ => new StandardTextureResource(textureSourceHighQuality, textureSourceLowQuality));
 }
Example #4
0
 /// <summary>
 /// Adds a new simple colored material resource to the scene.
 /// </summary>
 /// <param name="sceneManipulator">The manipulator of the scene.</param>
 /// <param name="textureSourceHighQuality">The source of the texture which should be loaded.</param>
 /// <param name="textureSourceLowQuality">The source of the texture with low quality.</param>
 public static NamedOrGenericKey AddStandardMaterialResource(
     this SceneManipulator sceneManipulator,
     ResourceLink textureSourceHighQuality, ResourceLink textureSourceLowQuality)
 {
     var resTexture = sceneManipulator.AddTextureResource(textureSourceHighQuality, textureSourceLowQuality);
     return sceneManipulator.AddResource(_ => new StandardMaterialResource(resTexture));
 }
Example #5
0
        /// <summary>
        /// Adds a new simple colored material resource to the scene.
        /// </summary>
        /// <param name="sceneManipulator">The manipulator of the scene.</param>
        /// <param name="textureSourceHighQuality">The source of the texture which should be loaded.</param>
        /// <param name="textureSourceLowQuality">The source of the texture with low quality.</param>
        public static NamedOrGenericKey AddSimpleColoredMaterial(
            this SceneManipulator sceneManipulator,
            ResourceLink textureSourceHighQuality, ResourceLink textureSourceLowQuality)
        {
            NamedOrGenericKey resTexture = sceneManipulator.AddTexture(textureSourceHighQuality, textureSourceLowQuality);

            return(sceneManipulator.AddResource <SimpleColoredMaterialResource>(() => new SimpleColoredMaterialResource(resTexture)));
        }
        /// <summary>
        /// Attaches this component to a scene.
        /// Be careful, this method gets called from a background thread of seeing#!
        /// It may also be called from multiple scenes in parallel or simply withoud previous Detach call.
        /// </summary>
        /// <param name="manipulator">The manipulator of the scene we attach to.</param>
        /// <param name="correspondingView">The view which attached this component.</param>
        protected override PerSceneContext Attach(SceneManipulator manipulator, ViewInformation correspondingView)
        {
            PerSceneContext context = new PerSceneContext();

            switch (m_gradientDirection)
            {
            case GradientDirection.LeftToRight:
                context.BrushResource = new LinearGradientBrushResource(
                    new System.Numerics.Vector2(0f, 0f),
                    new System.Numerics.Vector2(m_textureWidth, 0f),
                    new GradientStop[]
                {
                    new GradientStop(m_colorStart, 0f),
                    new GradientStop(m_colorEnd, 1f)
                });
                break;

            case GradientDirection.TopToBottom:
                context.BrushResource = new LinearGradientBrushResource(
                    new System.Numerics.Vector2(0f, 0f),
                    new System.Numerics.Vector2(0f, m_textureHeight),
                    new GradientStop[]
                {
                    new GradientStop(m_colorStart, 0f),
                    new GradientStop(m_colorEnd, 1f)
                });
                break;

            case GradientDirection.Directional:
                context.BrushResource = new LinearGradientBrushResource(
                    new System.Numerics.Vector2(0f, 0f),
                    new System.Numerics.Vector2(m_textureWidth, m_textureHeight),
                    new GradientStop[]
                {
                    new GradientStop(m_colorStart, 0f),
                    new GradientStop(m_colorEnd, 1f)
                });
                break;
            }

            // Create the background layer if not available already
            base.CreateLayerIfNotAvailable(manipulator);

            // Create and add the background
            context.BackgroundTextureKey = manipulator.AddResource(
                () => new Direct2DSingleRenderTextureResource(context.BrushResource, m_textureWidth, m_textureHeight));
            context.BackgroundPainter         = new FullscreenTextureObject(context.BackgroundTextureKey);
            context.BackgroundPainter.Scaling = 1.1f;
            manipulator.Add(context.BackgroundPainter, DEFAULT_LAYER);

            return(context);
        }
Example #7
0
 /// <summary>
 /// Adds a new simple colored material resource to the scene.
 /// </summary>
 /// <param name="sceneManipulator">The manipulator of the scene.</param>
 /// <param name="textureKey">The resource key of the texture to be used.</param>
 /// <param name="clipFactor">Pixel are clipped up to an alpha value defined by this Clipfactor within the pixel shader.</param>
 /// <param name="maxClipDistance">The maximum distance on which to apply pixel clipping (defined by ClipFactor property).</param>
 /// <param name="adjustTextureCoordinates">Interpolate texture coordinate based on xy-scaling.</param>
 /// <param name="addToAlpha">Needed for video rendering (Frames from the MF SourceReader have alpha always to zero).</param>
 public static NamedOrGenericKey AddSimpleColoredMaterial(
     this SceneManipulator sceneManipulator, NamedOrGenericKey textureKey,
     float clipFactor              = 0f,
     float maxClipDistance         = 1000f,
     bool adjustTextureCoordinates = false,
     float addToAlpha              = 0f)
 {
     return(sceneManipulator.AddResource <SimpleColoredMaterialResource>(
                () => new SimpleColoredMaterialResource(textureKey)
     {
         AdjustTextureCoordinates = adjustTextureCoordinates,
         MaxClipDistance = maxClipDistance,
         ClipFactor = clipFactor,
         AddToAlpha = addToAlpha
     }));
 }
        protected override Mesh CreateMesh(SceneManipulator manipulator, SampleSettings sampleSettings, NamedOrGenericKey resMaterial)
        {
            var castedSettings = (GeosphereSampleSettings)sampleSettings;

            var resGeometry = manipulator.AddResource(
                device => new GeometryResource(
                    new GeosphereGeometryFactory
            {
                CountSubdivisions = castedSettings.CountSubdivisions,
                Radius            = castedSettings.Radius
            }));

            var result = new Mesh(resGeometry, resMaterial);

            result.Position = new Vector3(0f, 0.5f + castedSettings.Radius, 0f);
            return(result);
        }
Example #9
0
        protected override Mesh CreateMesh(SceneManipulator manipulator, SampleSettings sampleSettings, NamedOrGenericKey resMaterial)
        {
            var castedSettings = (PyramidSampleSettings)sampleSettings;

            var resGeometry = manipulator.AddResource(
                device => new GeometryResource(
                    new PyramidGeometryFactory
            {
                Width  = castedSettings.Width,
                Height = castedSettings.Height
            }));

            var result = new Mesh(resGeometry, resMaterial);

            result.Position = new Vector3(0f, 0.5f + castedSettings.Height / 2f, 0f);
            return(result);
        }
        protected override Mesh CreateMesh(SceneManipulator manipulator, SampleSettings sampleSettings, NamedOrGenericKey resMaterial)
        {
            var castedSettings = (CylinderSampleSettings)sampleSettings;

            var resGeometry = manipulator.AddResource(
                device => new GeometryResource(
                    new CylinderGeometryFactory
            {
                Radius          = castedSettings.Radius,
                Height          = castedSettings.Height,
                CountOfSegments = castedSettings.CountOfSegments
            }));

            var result = new Mesh(resGeometry, resMaterial);

            result.Position = new Vector3(0f, 0.5f, 0f);
            return(result);
        }
Example #11
0
        protected override Mesh CreateMesh(SceneManipulator manipulator, SampleSettings sampleSettings, NamedOrGenericKey resMaterial)
        {
            var castedSettings = (TorusSampleSettings)sampleSettings;

            var resGeometry = manipulator.AddResource(
                device => new GeometryResource(
                    new TorusGeometryFactory()
            {
                TDiv        = castedSettings.TDiv,
                PDiv        = castedSettings.PDiv,
                TorusRadius = castedSettings.TorusRadius,
                TubeRadius  = castedSettings.TubeRadius,
            }));

            var result = new Mesh(resGeometry, resMaterial);

            result.Position = new Vector3(0f, 0.5f + castedSettings.TubeRadius + castedSettings.TorusRadius, 0f);
            return(result);
        }
Example #12
0
 /// <summary>
 /// Adds a new simple colored material resource to the scene.
 /// </summary>
 /// <param name="sceneManipulator">The manipulator of the scene.</param>
 /// <param name="textureKey">The resource key of the texture to be used.</param>
 /// <param name="clipFactor">Pixel are clipped up to an alpha value defined by this clipping factor within the pixel shader.</param>
 /// <param name="maxClipDistance">The maximum distance on which to apply pixel clipping (defined by ClipFactor property).</param>
 /// <param name="adjustTextureCoordinates">Interpolate texture coordinate based on xy-scaling.</param>
 /// <param name="addToAlpha">Needed for video rendering (Frames from the MF SourceReader have alpha always to zero).</param>
 /// <param name="materialDiffuseColor">The fixed diffuse color for this material.</param>
 /// <param name="useVertexColors">Set this to false to use the material's diffuse color.</param>
 /// <param name="enableShaderGeneratedBorder">Enable drawing of borders which are generated by the pixel shader?</param>
 public static NamedOrGenericKey AddStandardMaterialResource(
     this SceneManipulator sceneManipulator,
     NamedOrGenericKey textureKey = default,
     float clipFactor = 0f,
     float maxClipDistance = 1000f,
     bool adjustTextureCoordinates = false,
     float addToAlpha = 0f,
     Color4 materialDiffuseColor = default,
     bool useVertexColors = true,
     bool enableShaderGeneratedBorder = false)
 {
     return sceneManipulator.AddResource(
         _ => new StandardMaterialResource(textureKey, enableShaderGeneratedBorder)
         {
             AdjustTextureCoordinates = adjustTextureCoordinates,
             MaxClipDistance = maxClipDistance,
             ClipFactor = clipFactor,
             AddToAlpha = addToAlpha,
             MaterialDiffuseColor = materialDiffuseColor,
             UseVertexColors = useVertexColors
         });
 }
Example #13
0
 /// <summary>
 /// Adds a new geometry resource to the scene.
 /// </summary>
 /// <param name="sceneManipulator">The manipulator of the scene.</param>
 /// <param name="vertexStructure">The structures which define the geometry.</param>
 public static NamedOrGenericKey AddGeometry(this SceneManipulator sceneManipulator, VertexStructure vertexStructure)
 {
     return(sceneManipulator.AddResource <GeometryResource>(() => new GeometryResource(vertexStructure)));
 }
Example #14
0
 /// <summary>
 /// Adds a new simple colored material resource to the scene.
 /// </summary>
 /// <param name="sceneManipulator">The manipulator of the scene.</param>
 public static NamedOrGenericKey AddStandardMaterialResource(this SceneManipulator sceneManipulator)
 {
     return sceneManipulator.AddResource(_ => new StandardMaterialResource());
 }
Example #15
0
 /// <summary>
 /// Adds a new geometry resource to the scene.
 /// </summary>
 /// <param name="sceneManipulator">The manipulator of the scene.</param>
 /// <param name="objectType">The geometry to be loaded.</param>
 public static NamedOrGenericKey AddGeometry(this SceneManipulator sceneManipulator, ObjectType objectType)
 {
     return(sceneManipulator.AddResource <GeometryResource>(() => new GeometryResource(objectType)));
 }
Example #16
0
 /// <summary>
 /// Adds a new geometry resource to the scene.
 /// </summary>
 /// <param name="sceneManipulator">The manipulator of the scene.</param>
 /// <param name="objectType">The geometry to be loaded.</param>
 public static NamedOrGenericKey AddGeometryResource(this SceneManipulator sceneManipulator, GeometryFactory objectType)
 {
     return sceneManipulator.AddResource(_ => new GeometryResource(objectType));
 }
Example #17
0
 /// <summary>
 /// Adds a new geometry resource to the scene.
 /// </summary>
 /// <param name="sceneManipulator">The manipulator of the scene.</param>
 /// <param name="geometry">The geometry.</param>
 public static NamedOrGenericKey AddGeometryResource(this SceneManipulator sceneManipulator, Geometry geometry)
 {
     return sceneManipulator.AddResource(_ => new GeometryResource(geometry));
 }
        /// <summary>
        /// This method is called after the scene was created.
        /// Be carefull: This method run's in 3D-Engines update thread.
        /// </summary>
        /// <param name="manipulator">The manipulator.</param>
        private void OnBodyScene_Initialize(SceneManipulator manipulator)
        {
            SceneLayer bgLayer = manipulator.AddLayer("BACKGROUND");
            manipulator.SetLayerOrderID(bgLayer, 0);
            manipulator.SetLayerOrderID(Scene.DEFAULT_LAYER_NAME, 1);

            ResourceLink sourceWallTexture = new Uri(
                "/SeeingSharp.ModelViewer;component/Resources/Textures/Background.png",
                UriKind.Relative);
            var resBackgroundTexture = manipulator.AddTexture(sourceWallTexture);
            manipulator.Add(new TexturePainter(resBackgroundTexture), bgLayer.Name);

            FloorType floorType = new FloorType(new Vector2(3f, 3f), 0.1f);
            floorType.SetTilemap(40, 40);
            floorType.DefaultFloorMaterial = manipulator.AddSimpleColoredMaterial(new Uri(
                "/SeeingSharp.ModelViewer;component/Resources/Textures/Floor.png",
                UriKind.Relative));
            var resGeometry = manipulator.AddResource<GeometryResource>(() => new GeometryResource(floorType));
            GenericObject floorObject = manipulator.AddGeneric(resGeometry);
            floorObject.IsPickingTestVisible = false;
        }
Example #19
0
 /// <summary>
 /// Adds a new texture resource to the scene.
 /// </summary>
 /// <param name="sceneManipulator">The manipulator of the scene.</param>
 /// <param name="textureSource">The source of the texture.</param>
 public static NamedOrGenericKey AddTexture(this SceneManipulator sceneManipulator, ResourceLink textureSource)
 {
     return(sceneManipulator.AddResource <StandardTextureResource>(() => new StandardTextureResource(textureSource)));
 }
Example #20
0
 /// <summary>
 /// Adds a new simple colored material resource to the scene.
 /// </summary>
 /// <param name="sceneManipulator">The manipulator of the scene.</param>
 public static NamedOrGenericKey AddSimpleColoredMaterial(this SceneManipulator sceneManipulator)
 {
     return(sceneManipulator.AddResource <SimpleColoredMaterialResource>(() => new SimpleColoredMaterialResource()));
 }