Example #1
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);
        }
        /// <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 #3
0
        /// <summary>
        /// Creates the configured layer if it does not exist on the given scene.
        /// </summary>
        /// <param name="manipulator">The manipulator for manipulating the scene.</param>
        protected void CreateLayerIfNotAvailable(SceneManipulator manipulator)
        {
            this.TargetLayer.EnsureNotNullOrEmptyOrWhiteSpace(nameof(this.TargetLayer));

            if (!manipulator.ContainsLayer(this.TargetLayer))
            {
                SceneLayer bgLayer = manipulator.AddLayer(this.TargetLayer);
                manipulator.SetLayerOrderID(bgLayer, this.TargetLayerOrderID);
            }
        }
        /// <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;
        }
        /// <summary>
        /// Updates the given body model.
        /// Be carefull.. this method runs within 3D-Engine update thread.
        /// </summary>
        /// <param name="scene">The scene to be manipulated.</param>
        /// <param name="manipulator">The manipulator.</param>
        /// <param name="bodyObject">The body object.</param>
        /// <param name="bodyIndex">Index of the body.</param>
        private static void UpdateBodyModel(Scene scene, SceneManipulator manipulator, Body bodyObject, int bodyIndex)
        {
            // Ensure we have a layer for this body
            string actBodyLayerName = "Body_" + bodyIndex;
            SceneLayer actBodyLayer = manipulator.TryGetLayer(actBodyLayerName);
            if(actBodyLayer == null)
            {
                actBodyLayer = manipulator.AddLayer(actBodyLayerName);
                manipulator.SetLayerOrderID(actBodyLayer, bodyIndex);

            }
        }