コード例 #1
0
        protected override Task <bool> Initialize(EditorServiceGame editorGame)
        {
            game = (EntityHierarchyEditorGame)editorGame;
            game.Script.AddTask(Update);

            return(Task.FromResult(true));
        }
コード例 #2
0
        /// <inheritdoc/>
        protected override Task <bool> Initialize(EditorServiceGame editorGame)
        {
            game = (EntityHierarchyEditorGame)editorGame;

            Editor.SelectedContent.CollectionChanged += SelectedContentChanged;
            game.Script.AddTask(Execute);
            return(Task.FromResult(true));
        }
コード例 #3
0
        protected override Task <bool> Initialize(EditorServiceGame editorGame)
        {
            if (editorGame == null)
            {
                throw new ArgumentNullException(nameof(editorGame));
            }
            game = (EntityHierarchyEditorGame)editorGame;

            return(Task.FromResult(true));
        }
コード例 #4
0
        protected override Task <bool> Initialize(EditorServiceGame editorGame)
        {
            game = (EntityHierarchyEditorGame)editorGame;

            // create the default font
            var fontItem = OfflineRasterizedSpriteFontFactory.Create();

            fontItem.FontType.Size = 8;
            defaultFont            = OfflineRasterizedFontCompiler.Compile(game.Services.GetService <IFontFactory>(), fontItem, game.GraphicsDevice.ColorSpace == ColorSpace.Linear);

            incrustBatch = new SpriteBatch(game.GraphicsDevice);

            // SpriteEffect will be used to draw camera incrust border
            spriteEffect = new EffectInstance(new Graphics.Effect(game.GraphicsDevice, SpriteEffect.Bytecode));
            spriteEffect.Parameters.Set(TexturingKeys.Texture0, game.GraphicsDevice.GetSharedWhiteTexture());
            spriteEffect.UpdateEffect(game.GraphicsDevice);

            borderPipelineState = new MutablePipelineState(game.GraphicsDevice);
            borderPipelineState.State.RootSignature   = spriteEffect.RootSignature;
            borderPipelineState.State.EffectBytecode  = spriteEffect.Effect.Bytecode;
            borderPipelineState.State.InputElements   = VertexPositionTexture.Layout.CreateInputElements();
            borderPipelineState.State.PrimitiveType   = PrimitiveType.LineStrip;
            borderPipelineState.State.RasterizerState = RasterizerStates.CullNone;

            unsafe
            {
                var borderVertices = new[]
                {
                    new VertexPositionTexture(new Vector3(0.0f, 0.0f, 0.0f), Vector2.Zero),
                    new VertexPositionTexture(new Vector3(0.0f, 1.0f, 0.0f), Vector2.Zero),
                    new VertexPositionTexture(new Vector3(1.0f, 1.0f, 0.0f), Vector2.Zero),
                    new VertexPositionTexture(new Vector3(1.0f, 0.0f, 0.0f), Vector2.Zero),
                    new VertexPositionTexture(new Vector3(0.0f, 0.0f, 0.0f), Vector2.Zero),
                    new VertexPositionTexture(new Vector3(0.0f, 1.0f, 0.0f), Vector2.Zero), // extra vertex so that left-top corner is not missing (likely due to rasterization rule)
                };

                fixed(VertexPositionTexture *borderVerticesPtr = borderVertices)
                borderVertexBuffer = Graphics.Buffer.Vertex.New(game.GraphicsDevice, new DataPointer(borderVerticesPtr, VertexPositionTexture.Size * borderVertices.Length));
            }

            var editorTopLevel = game.EditorSceneSystem.GraphicsCompositor.Game as EditorTopLevelCompositor;

            if (editorTopLevel != null)
            {
                // Display it as incrust
                editorTopLevel.PostGizmoCompositors.Add(renderIncrustRenderer = new RenderIncrustRenderer(this));
            }

            Services.Get <IEditorGameEntitySelectionService>().SelectionUpdated += UpdateModifiedEntitiesList;

            return(Task.FromResult(true));
        }
        protected override Task <bool> Initialize(EditorServiceGame editorGame)
        {
            if (editorGame == null)
            {
                throw new ArgumentNullException(nameof(editorGame));
            }
            game = (EntityHierarchyEditorGame)editorGame;

            var pickingRenderStage = game.EditorSceneSystem.GraphicsCompositor.RenderStages.First(x => x.Name == "Picking");
            // TODO: Move selection/wireframe render stage in EditorGameComponentGizmoService (as last render step?)
            var selectionRenderStage = new RenderStage("SelectionGizmo", "Wireframe");

            selectionRenderStage.Filter = new WireframeFilter();

            var lightProbeGizmoRenderStage     = new RenderStage("LightProbeGizmo", "Main");
            var lightProbeWireframeRenderStage = new RenderStage("LightProbeWireframe", "Main");

            game.EditorSceneSystem.GraphicsCompositor.RenderStages.Add(selectionRenderStage);
            game.EditorSceneSystem.GraphicsCompositor.RenderStages.Add(lightProbeGizmoRenderStage);
            game.EditorSceneSystem.GraphicsCompositor.RenderStages.Add(lightProbeWireframeRenderStage);

            // Meshes
            var meshRenderFeature = game.EditorSceneSystem.GraphicsCompositor.RenderFeatures.OfType <MeshRenderFeature>().First();

            meshRenderFeature.RenderStageSelectors.Add(new SimpleGroupToRenderStageSelector
            {
                EffectName  = EditorGraphicsCompositorHelper.EditorForwardShadingEffect,
                RenderGroup = LightProbeGizmo.LightProbeGroupMask,
                RenderStage = lightProbeGizmoRenderStage
            });
            meshRenderFeature.RenderStageSelectors.Add(new SimpleGroupToRenderStageSelector
            {
                EffectName  = EditorGraphicsCompositorHelper.EditorForwardShadingEffect + ".Picking",
                RenderGroup = LightProbeGizmo.LightProbeGroupMask,
                RenderStage = pickingRenderStage,
            });
            meshRenderFeature.RenderStageSelectors.Add(new SimpleGroupToRenderStageSelector
            {
                EffectName  = EditorGraphicsCompositorHelper.EditorForwardShadingEffect + ".Wireframe",
                RenderGroup = LightProbeGizmo.LightProbeGroupMask,
                RenderStage = selectionRenderStage,
            });
            meshRenderFeature.RenderFeatures.Add(new WireframeRenderFeature());

            meshRenderFeature.RenderStageSelectors.Add(new SimpleGroupToRenderStageSelector
            {
                EffectName  = EditorGraphicsCompositorHelper.EditorForwardShadingEffect,
                RenderGroup = LightProbeWireGroupMask,
                RenderStage = lightProbeWireframeRenderStage,
            });
            meshRenderFeature.PipelineProcessors.Add(new AntiAliasLinePipelineProcessor {
                RenderStage = lightProbeWireframeRenderStage
            });
            var editorCompositor = (EditorTopLevelCompositor)game.EditorSceneSystem.GraphicsCompositor.Game;

            editorCompositor.PostGizmoCompositors.Add(new SingleStageRenderer {
                RenderStage = lightProbeWireframeRenderStage, Name = "LightProbe Wireframe Gizmos"
            });
            editorCompositor.PostGizmoCompositors.Add(new ClearRenderer {
                ClearFlags = ClearRendererFlags.DepthOnly
            });
            editorCompositor.PostGizmoCompositors.Add(new SingleStageRenderer {
                RenderStage = lightProbeGizmoRenderStage, Name = "LightProbe Gizmos"
            });
            editorCompositor.PostGizmoCompositors.Add(new SingleStageRenderer {
                RenderStage = selectionRenderStage, Name = "LightProbe Selection Gizmo"
            });

            // Add debug entity
            debugEntity = new Entity("Navigation debug entity");
            game.EditorScene.Entities.Add(debugEntity);

            var color = Color.Yellow;

            color.A           = 0x9F;
            wireframeMaterial = CreateDebugMaterial(color);

            game.Script.AddTask(Update);

            return(Task.FromResult(true));
        }
コード例 #6
0
        protected override Task <bool> Initialize(EditorServiceGame editorGame)
        {
            game        = (EntityHierarchyEditorGame)editorGame;
            editorScene = game.EditorScene;

            var transformMainGizmoRenderStage        = new RenderStage("TransformGizmoOpaque", "Main");
            var transformTransparentGizmoRenderStage = new RenderStage("TransformGizmoTransparent", "Main")
            {
                SortMode = new BackToFrontSortMode()
            };

            game.EditorSceneSystem.GraphicsCompositor.RenderStages.Add(transformMainGizmoRenderStage);
            game.EditorSceneSystem.GraphicsCompositor.RenderStages.Add(transformTransparentGizmoRenderStage);

            var meshRenderFeature = game.EditorSceneSystem.GraphicsCompositor.RenderFeatures.OfType <MeshRenderFeature>().First();

            // Reset all stages for TransformationGrizmoGroup
            meshRenderFeature.RenderStageSelectors.Add(new SimpleGroupToRenderStageSelector
            {
                RenderGroup = TransformationGizmo.TransformationGizmoGroupMask,
            });
            meshRenderFeature.RenderStageSelectors.Add(new MeshTransparentRenderStageSelector
            {
                EffectName             = EditorGraphicsCompositorHelper.EditorForwardShadingEffect,
                RenderGroup            = TransformationGizmo.TransformationGizmoGroupMask,
                OpaqueRenderStage      = transformMainGizmoRenderStage,
                TransparentRenderStage = transformTransparentGizmoRenderStage,
            });
            meshRenderFeature.PipelineProcessors.Add(new MeshPipelineProcessor {
                TransparentRenderStage = transformTransparentGizmoRenderStage
            });

            var editorCompositor = (EditorTopLevelCompositor)game.EditorSceneSystem.GraphicsCompositor.Game;

            editorCompositor.PostGizmoCompositors.Add(new ClearRenderer {
                ClearFlags = ClearRendererFlags.DepthOnly
            });
            editorCompositor.PostGizmoCompositors.Add(new SingleStageRenderer {
                RenderStage = transformMainGizmoRenderStage, Name = "Transform Opaque Gizmos"
            });
            editorCompositor.PostGizmoCompositors.Add(new SingleStageRenderer {
                RenderStage = transformTransparentGizmoRenderStage, Name = "Transform Transparent Gizmos"
            });

            TranslationGizmo = new TranslationGizmo();
            RotationGizmo    = new RotationGizmo();
            ScaleGizmo       = new ScaleGizmo();
            TranslationGizmo.TransformationEnded += OnGizmoTransformationFinished;
            ScaleGizmo.TransformationEnded       += OnGizmoTransformationFinished;
            RotationGizmo.TransformationEnded    += OnGizmoTransformationFinished;

            transformationGizmos.Add(TranslationGizmo);
            transformationGizmos.Add(RotationGizmo);
            transformationGizmos.Add(ScaleGizmo);

            Services.Get <IEditorGameEntitySelectionService>().SelectionUpdated += UpdateModifiedEntitiesList;

            // Initialize and add the Gizmo entities to the gizmo scene
            MicrothreadLocalDatabases.MountCommonDatabase();

            // initialize the gizmo
            foreach (var gizmo in transformationGizmos)
            {
                gizmo.Initialize(game.Services, editorScene);
            }

            // Deactivate all transformation gizmo by default
            foreach (var gizmo in transformationGizmos)
            {
                gizmo.IsEnabled = false;
            }

            // set the default active transformation gizmo
            ActiveTransformationGizmo = TranslationGizmo;

            // Start update script (with priority 1 so that it happens after UpdateModifiedEntitiesList is called -- which usually happens from a EditorGameComtroller.PostAction() which has a default priority 0)
            game.Script.AddTask(Update, 1);
            return(Task.FromResult(true));
        }