示例#1
0
        /// <summary>
        /// Adds a new mesh to the scene.
        /// </summary>
        /// <param name="resGeometry">The geometry.</param>
        /// <param name="layer">The layer on which to add the object.</param>
        /// <param name="resMaterials">All materials to be mapped to the geometry.</param>
        public Mesh AddMeshObject(NamedOrGenericKey resGeometry, string layer, params NamedOrGenericKey[] resMaterials)
        {
            var result = new Mesh(resGeometry, resMaterials);

            this.AddObject(result, layer);
            return(result);
        }
示例#2
0
        /// <summary>
        /// Gets the postrocess effect with the given key.
        /// </summary>
        /// <param name="namedOrGenericKey">The key of the effect.</param>
        /// <param name="resourceDictionary">The resource dictionary where to load the effect.</param>
        internal PostprocessEffectResource GetPostprocessEffect(NamedOrGenericKey namedOrGenericKey, ResourceDictionary resourceDictionary)
        {
            m_postprocessEffectKey = namedOrGenericKey;

            // Handle empty key
            if (namedOrGenericKey.IsEmpty)
            {
                m_postprocessEffect = null;
                return(null);
            }

            // Check for current effect object
            if (m_postprocessEffect != null)
            {
                // Good case, return current one
                if (m_postprocessEffect.Key == namedOrGenericKey)
                {
                    return(m_postprocessEffect);
                }

                // Bad case, effect has changed
                m_postprocessEffect = null;
            }

            m_postprocessEffect    = resourceDictionary.GetResourceAndEnsureLoaded <PostprocessEffectResource>(namedOrGenericKey);
            m_postprocessEffectKey = namedOrGenericKey;
            return(m_postprocessEffect);
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TexturePainterHelper"/> class.
 /// </summary>
 /// <param name="textureKey">The texture key.</param>
 internal TexturePainterHelper(NamedOrGenericKey textureKey)
 {
     m_texture            = textureKey;
     m_scaling            = 1f;
     m_opacity            = 1f;
     m_accentuationFactor = 0f;
 }
        /// <summary>
        /// Removes the resource with the given key.
        /// </summary>
        /// <param name="key">The key to check.</param>
        internal void RemoveResource(NamedOrGenericKey key)
        {
            if (_resources.ContainsKey(key))
            {
                var resourceInfo = _resources[key];

                //Unload the resource
                if (resourceInfo.Resource.IsLoaded)
                {
                    resourceInfo.Resource.UnloadResource();
                }
                if (resourceInfo.RenderableResource != null)
                {
                    _renderableResources.Remove(resourceInfo.RenderableResource);
                }
                if (resourceInfo.UpdatableResource != null)
                {
                    _updatableResources.Remove(resourceInfo.UpdatableResource);
                }

                //RemoveObject the resource
                _resources.Remove(key);

                resourceInfo.Resource.Dictionary = null;
            }
        }
示例#5
0
        /// <summary>
        /// Gets the resource with the given key. CreateMethod will be called to create
        /// the resource if it is not available yet.
        /// </summary>
        /// <param name="resourceKey">Key of the resource.</param>
        /// <param name="createMethod">Method wich creates the resource.</param>
        internal T GetResource <T>(NamedOrGenericKey resourceKey, Func <T> createMethod)
            where T : Resource
        {
            if (m_resources.ContainsKey(resourceKey))
            {
                T result = m_resources[resourceKey].Resource as T;

                if (result != null)
                {
                    return(result);
                }
                else
                {
                    m_resources.Remove(resourceKey);
                }
            }

            T newResource = createMethod();

            if (newResource == null)
            {
                return(null);
            }

            AddResource(resourceKey, newResource);
            return(newResource);
        }
示例#6
0
        /// <summary>
        /// Imports a model from the given file.
        /// </summary>
        /// <param name="sourceFile">The source file to be loaded.</param>
        /// <param name="importOptions">Some configuration for the importer.</param>
        public ImportedModelContainer ImportModel(ResourceLink sourceFile, ImportOptions importOptions)
        {
            // Get import options
            ACImportOptions acImportOptions = importOptions as ACImportOptions;

            if (acImportOptions == null)
            {
                throw new SeeingSharpException("Invalid import options for ACImporter!");
            }

            ImportedModelContainer result = new ImportedModelContainer(acImportOptions);

            // Get needed resource key
            NamedOrGenericKey resGeometry = GraphicsCore.GetNextGenericResourceKey();

            // Load and fill result object
            ObjectType objType = ACFileLoader.ImportObjectType(sourceFile);

            result.ImportedResources.Add(new ImportedResourceInfo(
                                             resGeometry,
                                             () => new GeometryResource(objType)));
            result.Objects.Add(new GenericObject(resGeometry));

            return(result);
        }
示例#7
0
        /// <summary>
        /// Queries all resources of the given resource key.
        /// </summary>
        /// <param name="resourceKey">The key of the resource to get all resource instances for.</param>
        public IEnumerable <T> QueryResources <T>(NamedOrGenericKey resourceKey)
            where T : Resource
        {
            this.CheckValid();

            return(this.Owner.QueryResources <T>(resourceKey, this.CheckValid));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TexturePainterHelper"/> class.
 /// </summary>
 /// <param name="textureKey">The texture key.</param>
 internal TexturePainterHelper(NamedOrGenericKey textureKey)
 {
     _texture                = textureKey;
     this.Scaling            = 1f;
     this.Opacity            = 1f;
     this.AccentuationFactor = 0f;
 }
示例#9
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)));
        }
示例#10
0
        /// <summary>
        /// Adds a new generic object targeting to the given geometry resource.
        /// </summary>
        /// <param name="geometryResource">The geometry to be used.</param>
        /// <param name="position">The position for the created object.</param>
        /// <param name="layer">The layer on which to add the object.</param>
        public GenericObject AddGeneric(NamedOrGenericKey geometryResource, Vector3 position, string layer)
        {
            GenericObject newGenericObject = new GenericObject(geometryResource);

            newGenericObject.Position = position;

            return(this.Add(newGenericObject, layer));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleColoredMaterialResource"/> class.
 /// </summary>
 /// <param name="textureKey">The name of the texture to be rendered.</param>
 public SimpleColoredMaterialResource(NamedOrGenericKey textureKey = new NamedOrGenericKey())
 {
     m_textureKey               = textureKey;
     m_maxClipDistance          = 1000f;
     m_adjustTextureCoordinates = false;
     m_addToAlpha               = 0f;
     m_materialDiffuseColor     = Color4.White;
 }
示例#12
0
        /// <summary>
        /// Removes the resource with the given key.
        /// </summary>
        /// <param name="resourceKey">The key of the resource to be deleted.</param>
        internal void RemoveResource(NamedOrGenericKey resourceKey)
        {
            InitializeResourceDictionaries(true);

            foreach (ResourceDictionary actResourceDict in m_registeredResourceDicts)
            {
                actResourceDict.RemoveResource(resourceKey);
            }
        }
示例#13
0
        /// <summary>
        /// Removes the resource with the given key.
        /// </summary>
        /// <param name="resourceKey">The key of the resource to be deleted.</param>
        internal void RemoveResource(NamedOrGenericKey resourceKey)
        {
            this.InitializeResourceDictionaries();

            foreach (var actResourceDict in _registeredResourceDicts)
            {
                actResourceDict.RemoveResource(resourceKey);
            }
        }
示例#14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenericObject"/> class.
        /// </summary>
        /// <param name="geometryResource">The geometry resource.</param>
        public GenericObject(NamedOrGenericKey geometryResource)
        {
            m_localResources = new IndexBasedDynamicCollection <GeometryResource>();

            m_resGeometryKey = geometryResource;

            //m_opacity = 1f;
            m_passRelevantValuesChanged = true;
        }
示例#15
0
        /// <summary>
        /// Reads the model in ASCII format from the specified stream.
        /// </summary>
        private ImportedModelContainer TryReadAscii(Stream stream, StlImportOptions importOptions)
        {
            using (var reader = new StreamReader(stream, ENCODING, false, 128, true))
            {
                VertexStructure newStructure = new VertexStructure();
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    if (line == null)
                    {
                        continue;
                    }

                    line = line.Trim();
                    if (line.Length == 0 || line.StartsWith("\0") || line.StartsWith("#") || line.StartsWith("!") ||
                        line.StartsWith("$"))
                    {
                        continue;
                    }

                    string id, values;
                    ParseLine(line, out id, out values);
                    switch (id)
                    {
                    // Header.. not needed here
                    case "solid":
                        break;

                    // Geometry data
                    case "facet":
                        this.ReadFacet(reader, values, newStructure, importOptions);
                        break;

                    // End of file
                    case "endsolid":
                        break;
                    }
                }

                // Generate result container
                ImportedModelContainer result         = new ImportedModelContainer(importOptions);
                NamedOrGenericKey      geoResourceKey = result.GetResourceKey(
                    RES_KEY_GEO_CLASS, RES_KEY_GEO_NAME);
                result.ImportedResources.Add(new ImportedResourceInfo(
                                                 geoResourceKey,
                                                 () => new GeometryResource(newStructure)));
                GenericObject geoObject = new GenericObject(geoResourceKey);
                result.Objects.Add(geoObject);

                // Append an object which transform the whole coordinate system
                ScenePivotObject rootObject = result.CreateAndAddRootObject();
                result.ParentChildRelationships.Add(new Tuple <SceneObject, SceneObject>(rootObject, geoObject));

                return(result);
            }
        }
示例#16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FullscreenTextureObject"/> class.
        /// </summary>
        /// <param name="texture">The texture.</param>
        public FullscreenTextureObject(NamedOrGenericKey texture)
        {
            m_resTexture         = texture;
            m_scaling            = 1f;
            m_opacity            = 1f;
            m_accentuationFactor = 0f;
            m_alphaMode          = TexturePainterAlphaBlendMode.AlphaBlend;

            m_texturePainterHelpers = new IndexBasedDynamicCollection <TexturePainterHelper>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FullscreenTexture"/> class.
        /// </summary>
        /// <param name="texture">The texture.</param>
        public FullscreenTexture(NamedOrGenericKey texture)
        {
            _resTexture             = texture;
            this.Scaling            = 1f;
            this.Opacity            = 1f;
            this.AccentuationFactor = 0f;
            this.AlphaBlendMode     = TexturePainterAlphaBlendMode.AlphaBlend;

            _texturePainterHelpers = new IndexBasedDynamicCollection <TexturePainterHelper>();
        }
示例#18
0
        /// <summary>
        /// Reads the model from the specified binary stream.
        /// </summary>
        private ImportedModelContainer TryReadBinary(Stream stream, StlImportOptions importOptions)
        {
            // Check length
            long length = stream.Length;

            if (length < 84)
            {
                throw new SeeingSharpException("Incomplete file (smaller that 84 bytes)");
            }

            // Read number of triangles
            uint numberTriangles = 0;

            using (var reader = new BinaryReader(stream, Encoding.GetEncoding("us-ascii"), true))
            {
                // Read header (is not needed)
                //  (solid stands for Ascii format)
                string header = ENCODING.GetString(reader.ReadBytes(80), 0, 80).Trim();
                if (header.StartsWith("solid", StringComparison.OrdinalIgnoreCase))
                {
                    return(null);
                }

                // Read and check number of triangles
                numberTriangles = ReadUInt32(reader);
                if (length - 84 != numberTriangles * 50)
                {
                    throw new SeeingSharpException("Incomplete file (smaller that expected byte count)");
                }

                // Read geometry data
                VertexStructure newStructure = new VertexStructure((int)numberTriangles * 3);
                newStructure.CreateSurface((int)numberTriangles);
                for (int loop = 0; loop < numberTriangles; loop++)
                {
                    this.ReadTriangle(reader, newStructure, importOptions);
                }

                // Generate result container
                ImportedModelContainer result         = new ImportedModelContainer(importOptions);
                NamedOrGenericKey      geoResourceKey = result.GetResourceKey(
                    RES_KEY_GEO_CLASS, RES_KEY_GEO_NAME);
                result.ImportedResources.Add(new ImportedResourceInfo(
                                                 geoResourceKey,
                                                 () => new GeometryResource(newStructure)));
                GenericObject geoObject = new GenericObject(geoResourceKey);
                result.Objects.Add(geoObject);

                // Append an object which transform the whole coordinate system
                ScenePivotObject rootObject = result.CreateAndAddRootObject();
                result.ParentChildRelationships.Add(new Tuple <SceneObject, SceneObject>(rootObject, geoObject));

                return(result);
            }
        }
        /// <summary>
        /// Adds the given resource to the dictionary and loads it directly.
        /// </summary>
        /// <param name="resourceKey">The key of the resource.</param>
        /// <param name="resource">The resource to add.</param>
        internal TResourceType AddAndLoadResource <TResourceType>(NamedOrGenericKey resourceKey, TResourceType resource)
            where TResourceType : Resource
        {
            this.AddResource(resourceKey, resource);
            if (!resource.IsLoaded)
            {
                resource.LoadResource();
            }

            return(resource);
        }
示例#20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Mesh"/> class.
        /// </summary>
        /// <param name="geometryResourceKey">The geometry resource.</param>
        /// <param name="materialResourceKeys">The material resources to apply on this Mesh.</param>
        public Mesh(NamedOrGenericKey geometryResourceKey, params NamedOrGenericKey[] materialResourceKeys)
        {
            _localResGeometry  = new IndexBasedDynamicCollection <GeometryResource>();
            _localResMaterials = new IndexBasedDynamicCollection <MaterialResource[]>();
            _localChunks       = new IndexBasedDynamicCollection <RenderingChunk[]>();

            _resGeometryKey          = geometryResourceKey;
            _resMaterialResourceKeys = materialResourceKeys;

            _passRelevantValuesChanged = true;
        }
示例#21
0
        /// <summary>
        /// Gets the resource with the given key.
        /// </summary>
        /// <typeparam name="T">Type of the resource.</typeparam>
        /// <param name="resourceKey">Key of the resource.</param>
        internal T GetResourceAndEnsureLoaded <T>(NamedOrGenericKey resourceKey)
            where T : Resource
        {
            T resource = GetResource <T>(resourceKey);

            if (!resource.IsLoaded)
            {
                resource.LoadResource();
            }
            return(resource);
        }
示例#22
0
        ///// <summary>
        ///// Adds a new material for texture drawing pointing to the given texture resource.
        ///// </summary>
        ///// <param name="textureResourceKey">The key of the texture the material is pointing to.</param>
        //public SimpleColoredMaterialResource AddSimpleTexturedMaterial(NamedOrGenericKey textureResourceKey)
        //{
        //    return this.AddResource(new SimpleColoredMaterialResource(textureResourceKey));
        //}

        ///// <summary>
        ///// Adds a new material for texture drawing pointing to the given texture resource.
        ///// </summary>
        ///// <param name="resourceKey">The key of the resource.</param>
        ///// <param name="textureResourceKey">The key of the texture the material is pointing to.</param>
        //public SimpleColoredMaterialResource AddSimpleTexturedMaterial(NamedOrGenericKey resourceKey, NamedOrGenericKey textureResourceKey)
        //{
        //    return this.AddResource(resourceKey, new SimpleColoredMaterialResource(textureResourceKey));
        //}

        ///// <summary>
        ///// Adds a new material for drawing a simple colored mesh.
        ///// </summary>
        //public SimpleColoredMaterialResource AddSimpleColoredMaterial()
        //{
        //    return this.AddResource(new SimpleColoredMaterialResource());
        //}

        ///// <summary>
        ///// Adds a new material for drawing a simple colored mesh.
        ///// </summary>
        ///// <param name="resourceKey">The key of the resource.</param>
        //public SimpleColoredMaterialResource AddSimpleColoredMaterial(NamedOrGenericKey resourceKey)
        //{
        //    return this.AddResource(resourceKey, new SimpleColoredMaterialResource());
        //}

        /// <summary>
        /// Adds the given resource to the dictionary and loads it directly.
        /// </summary>
        /// <param name="resourceKey">The key of the resource.</param>
        /// <param name="resource">The resource to add.</param>
        internal ResourceType AddAndLoadResource <ResourceType>(NamedOrGenericKey resourceKey, ResourceType resource)
            where ResourceType : Resource
        {
            AddResource(resourceKey, resource);
            if (!resource.IsLoaded)
            {
                resource.LoadResource();
            }

            return(resource);
        }
示例#23
0
        protected override PerSceneContext Attach(SceneManipulator manipulator, ViewInformation correspondingView)
        {
            PerSceneContext context = new PerSceneContext();

            NamedOrGenericKey resCubeGeometry = manipulator.AddGeometry(new CubeType());

            context.CubeObject       = manipulator.AddGeneric(resCubeGeometry);
            context.CubeObject.Color = Color4.RedColor;

            return(context);
        }
示例#24
0
        /// <summary>
        /// Gets the resource with the given key. CreateMethod will be called to create
        /// the resource if it is not available yet.
        /// </summary>
        /// <param name="resourceKey">Key of the resource.</param>
        /// <param name="createMethod">Method wich creates the resource.</param>
        internal T GetResourceAndEnsureLoaded <T>(NamedOrGenericKey resourceKey, Func <T> createMethod)
            where T : Resource
        {
            T resource = GetResource(resourceKey, createMethod);

            if (!resource.IsLoaded)
            {
                resource.LoadResource();
            }
            return(resource);
        }
        /// <summary>
        /// Applies the given material to all contained vertex structures.
        /// </summary>
        /// <param name="materialToApply">The materials to apply.</param>
        public void ApplyMaterialForAll(NamedOrGenericKey materialToApply)
        {
            foreach (VertexStructureSurface actSurface in m_vertexStructure.Surfaces)
            {
                actSurface.Material = materialToApply;
            }

            foreach (VertexStructureSurface actSurface in m_vertexStructureLowDetail.Surfaces)
            {
                actSurface.Material = materialToApply;
            }
        }
示例#26
0
        public async Task Render_SimpleRoundedRect_Filled_Over3D()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            using (SolidBrushResource solidBrush = new SolidBrushResource(Color4.Gray.ChangeAlphaTo(0.5f)))
                using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024))
                {
                    memRenderTarget.ClearColor = Color4.CornflowerBlue;

                    // Get and configure the camera
                    PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D;
                    camera.Position = new Vector3(0f, 5f, -5f);
                    camera.Target   = new Vector3(0f, 1f, 0f);
                    camera.UpdateCamera();

                    // Define scene
                    await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) =>
                    {
                        // Define object
                        NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>(
                            () => new GeometryResource(new PalletStackType(
                                                           NamedOrGenericKey.Empty, 10)));
                        var newObject           = manipulator.AddGeneric(geoResource);
                        newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                        newObject.Scaling       = new Vector3(2f, 2f, 2f);
                        newObject.Color         = Color4.Goldenrod;
                        newObject.EnableShaderGeneratedBorder();
                    });

                    // Define 2D overlay
                    await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync((graphics) =>
                    {
                        // 2D rendering is made here
                        graphics.FillRoundedRectangle(
                            new RectangleF(10, 10, 512, 512), 30, 30,
                            solidBrush);
                    });

                    // Take screenshot
                    GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                    //screenshot.DumpToDesktop("Blub.png");

                    // Calculate and check difference
                    float diff = BitmapComparison.CalculatePercentageDifference(
                        screenshot, Properties.Resources.ReferenceImage_RoundedRectOver3D);
                    Assert.True(diff < 0.2, "Difference to reference image is to big!");
                }

            // Finishing checks
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
示例#27
0
        /// <summary>
        /// Base method used as common test scenario for all video renderers.
        /// </summary>
        /// <param name="videoWriter">The VideoWriter to be testet.</param>
        /// <param name="countFrames">Total count of frames to be rendered.</param>
        /// <param name="doAnimate">Execute animation during recording.</param>
        private async Task RenderSimple_Generic(SeeingSharpVideoWriter videoWriter, int countFrames, bool doAnimate = true)
        {
            using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024))
            {
                memRenderTarget.ClearColor = Color4.CornflowerBlue;

                // Get and configure the camera
                PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D;
                camera.Position = new Vector3(0f, 5f, -7f);
                camera.Target   = new Vector3(0f, 0f, 0f);
                camera.UpdateCamera();

                // Define scene
                await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) =>
                {
                    NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>(
                        () => new GeometryResource(new PalletType()));

                    var newObject           = manipulator.AddGeneric(geoResource);
                    newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                    newObject.Scaling       = new Vector3(2f, 2f, 2f);

                    if (doAnimate)
                    {
                        newObject.BuildAnimationSequence()
                        .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromMilliseconds(500.0))
                        .WaitFinished()
                        .RotateEulerAnglesTo(new Vector3(0f, 0, 0f), TimeSpan.FromMilliseconds(500.0))
                        .WaitFinished()
                        .ApplyAndRewind();
                    }
                });

                await memRenderTarget.RenderLoop.WaitForNextFinishedRenderAsync();

                // Start video rendering
                await memRenderTarget.RenderLoop.RegisterVideoWriterAsync(videoWriter);

                // Write about 100 frames to the video
                for (int loop = 0; loop < countFrames; loop++)
                {
                    await memRenderTarget.RenderLoop.WaitForNextFinishedRenderAsync();
                }

                // finish video rendering
                await memRenderTarget.RenderLoop.FinishVideoWriterAsync(videoWriter);
            }

            // Make shure that all the renderloop is correctly disposed
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
        public async Task Postprocessing_EdgeDetect()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024))
            {
                memRenderTarget.ClearColor = Color4.CornflowerBlue;

                // Get and configure the camera
                PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D;
                camera.Position = new Vector3(0f, 5f, -7f);
                camera.Target   = new Vector3(0f, 0f, 0f);
                camera.UpdateCamera();

                // Define scene
                await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) =>
                {
                    var keyPostprocess = manipulator.AddResource <EdgeDetectPostprocessEffectResource>(
                        () => new EdgeDetectPostprocessEffectResource()
                    {
                        Thickness = 10f
                    });

                    SceneLayer defaultLayer           = manipulator.GetLayer(Scene.DEFAULT_LAYER_NAME);
                    defaultLayer.PostprocessEffectKey = keyPostprocess;

                    NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>(
                        () => new GeometryResource(new PalletType()));

                    GenericObject newObject = manipulator.AddGeneric(geoResource);
                    newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                    newObject.Scaling       = new Vector3(2f, 2f, 2f);
                    newObject.Color         = Color4.RedColor;
                });

                // Take screenshot
                GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                //screenshot.DumpToDesktop("Blub.png");

                // Calculate and check difference
                bool isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, Properties.Resources.ReferenceImage_PostProcess_EdgeDetect);
                Assert.True(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
示例#29
0
        /// <summary>
        /// Creates all objects and puts them into the given ModelContainer.
        /// </summary>
        public void GenerateObjects()
        {
            // For some files we have a separate subfolder for textures
            string[] textureSubfolderPath =
                string.IsNullOrEmpty(m_importOptions.TextureSubfolderName) ? new string[0] : new string[1] {
                m_importOptions.TextureSubfolderName
            };

            // Toggle triangle order, when configured
            if (m_importOptions.ToggleTriangleIndexOrder)
            {
                m_targetVertexStructure.ToggleTriangleIndexOrder();
            }

            // Define all material resources which where defined in the material file
            foreach (VertexStructureSurface actSurface in m_targetVertexStructure.Surfaces)
            {
                // Handle texture
                NamedOrGenericKey textureKey = NamedOrGenericKey.Empty;
                if (!string.IsNullOrEmpty(actSurface.TextureName))
                {
                    string actTextureName = actSurface.TextureName;
                    textureKey = m_targetContainer.GetResourceKey("Texture", actSurface.TextureName);
                    m_targetContainer.ImportedResources.Add(
                        new ImportedResourceInfo(
                            textureKey,
                            () => new StandardTextureResource(m_resource.GetForAnotherFile(actTextureName, textureSubfolderPath))));
                }
                actSurface.TextureKey = textureKey;

                // Handle material itself
                NamedOrGenericKey actMaterialKey = m_targetContainer.GetResourceKey("Material", actSurface.MaterialProperties.Name);
                actSurface.Material = actMaterialKey;
                m_targetContainer.ImportedResources.Add(new ImportedResourceInfo(
                                                            actMaterialKey,
                                                            () => new SimpleColoredMaterialResource(textureKey)
                {
                    ClipFactor           = textureKey != NamedOrGenericKey.Empty ? 0.1f : 0f,
                    MaterialDiffuseColor = actSurface.DiffuseColor
                }));
            }

            // Define geometry resource
            NamedOrGenericKey resGeometry = m_targetContainer.GetResourceKey("Geometry", "1");
            GenericObjectType newObjType  = new GenericObjectType(m_targetVertexStructure);

            m_targetContainer.ImportedResources.Add(new ImportedResourceInfo(
                                                        resGeometry,
                                                        () => new GeometryResource(newObjType)));
            m_targetContainer.Objects.Add(new GenericObject(resGeometry));
        }
示例#30
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
     }));
 }
        /// <summary>
        /// Builds all game objects for the given level.
        /// </summary>
        /// <param name="currentLevel">The current level.</param>
        /// <param name="scene">The scene to which to add all objects.</param>
        internal async Task BuildFirstScreenAsync(LevelData currentLevel, Scene scene)
        {
            m_scene = scene;
            m_currentLevel = currentLevel;

            int tilesX = currentLevel.Tilemap.TilesX;
            int tilesY = currentLevel.Tilemap.TilesY;
            float tileDistX = Constants.TILE_DISTANCE_X;
            float tileDistY = -Constants.TILE_DISTANCE_Y;
            Vector3 midPoint = new Vector3((tilesX - 1) * tileDistX / 2f, 0f, ((tilesY - 1) * tileDistY / 2f));

            m_cardMapOnScreen = new Card[tilesX, tilesY];
            m_cardPairsOnScreen = new List<CardPairLogic>();

            ScreenData currentScreen = currentLevel.Screens[0];
            m_actScreenIndex = 0;

            await scene.ManipulateSceneAsync((manipulator) =>
            {
                // Build background and define level-wide resources
                manipulator.BuildBackground(currentLevel.MainTextures.BackgroundTextureLink);
                m_resBackgroundMaterial1 = manipulator.AddSimpleColoredMaterial(
                    currentLevel.MainTextures.Tile1TextureLink);
                m_resBackgroundMaterial2 = manipulator.AddSimpleColoredMaterial(
                    currentLevel.MainTextures.Tile2TextureLink);

                // Build the current screen
                BuildScreen(manipulator, currentScreen);

                // Add all logic components to the scene
                manipulator.Add(new PairUncoverLogic());
                manipulator.Add(new VideoPlayLogic());
                manipulator.Add(new BackgroundMusicLogic(currentLevel));
                manipulator.Add(new EndGameLogic(currentLevel));
                manipulator.Add(this);
            });

            Messenger.BeginPublish<MainMemoryScreenEnteredMessage>();
        }
示例#32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Card"/> class.
 /// </summary>
 /// <param name="resGeometry">The key of the GeometryResource.</param>
 /// <param name="cardPair">The pair this card belongs to.</param>
 public Card(NamedOrGenericKey resGeometry, CardPairLogic cardPair)
     : base(resGeometry)
 {
     this.Pair = cardPair;
 }