Exemple #1
0
        async System.Threading.Tasks.Task InitUIDrawer()
        {
            var rc   = EngineNS.CEngine.Instance.RenderContext;
            var font = CEngine.Instance.FontManager.GetFont(EngineNS.CEngine.Instance.Desc.DefaultFont, 24, 1024, 128);
            var mtl  = await CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(rc, RName.GetRName("Material/font.instmtl"));

            var textMeshInfo = new EngineNS.Bricks.FreeTypeFont.CFontMesh();
            await textMeshInfo.SetMaterial(rc, mtl, "txDiffuse");

            textMeshInfo.DrawText(rc, font, "模型", true);

            textMeshInfo.RenderMatrix = EngineNS.Matrix.Translate(20, 0, 0);
            //textMeshInfo.Offset = new Vector2(20, 0);
            //textMeshInfo.Scale = new Vector2(1, 1);

            var rp = mPreviewSceneControl.ViewPort.RPolicy as EngineNS.Graphics.RenderPolicy.CGfxRP_EditorMobile;

            rp.OnDrawUI += (cmd, view) =>
            {
                var    mesh    = mPreviewActor.GetComponentMesh(null);
                string outInfo = $"材质数:{mesh.MeshPrimitives.AtomNumber}:";
                for (int i = 0; i < mesh.MeshPrimitives.AtomNumber; i++)
                {
                    CDrawPrimitiveDesc desc = new CDrawPrimitiveDesc();
                    mesh.MeshPrimitives.GetAtom((UInt32)i, 0, ref desc);

                    var lodLvl = mesh.MeshPrimitives.GetLodLevel((UInt32)i, CurLod);

                    CDrawPrimitiveDesc desc1 = new CDrawPrimitiveDesc();
                    mesh.MeshPrimitives.GetAtom((UInt32)i, lodLvl, ref desc1);

                    outInfo += $"({desc1.NumPrimitives}/{desc.NumPrimitives}) ";
                }

                textMeshInfo.DrawText(rc, font, outInfo, true);
                for (int i = 0; i < textMeshInfo.PassNum; i++)
                {
                    var pass = textMeshInfo.GetPass(i);
                    if (pass == null)
                    {
                        continue;
                    }

                    pass.ViewPort = view.Viewport;
                    pass.BindCBuffer(pass.Effect.ShaderProgram, pass.Effect.CacheData.CBID_View, view.ScreenViewCB);
                    pass.ShadingEnv.BindResources(textMeshInfo.Mesh, pass);

                    cmd.PushPass(pass);
                }
            };
        }
        public async Task SetObjectToEditor(EngineNS.CRenderContext rc, EditorCommon.Resources.ResourceEditorContext context)
        {
            await Viewport.WaitInitComplated();

            if (mWindowRectUIShow == null)
            {
                var imgInit = new EngineNS.UISystem.Controls.ImageInitializer();
                imgInit.ImageBrush.ImageName = EngineNS.RName.GetRName("uieditor/uvanim_dottedline.uvanim", EngineNS.RName.enRNameType.Editor);
                imgInit.ImageBrush.TileMode  = EngineNS.UISystem.Brush.enTileMode.Both;
                mWindowRectUIShow            = new EngineNS.UISystem.Controls.Image();
                await mWindowRectUIShow.Initialize(rc, imgInit);
            }
            if (mMousePointAtUIRectShow == null)
            {
                var imgInit = new EngineNS.UISystem.Controls.ImageInitializer();
                imgInit.ImageBrush.ImageName = EngineNS.RName.GetRName("uieditor/uva_pointatrect.uvanim", EngineNS.RName.enRNameType.Editor);
                imgInit.ImageBrush.TileMode  = EngineNS.UISystem.Brush.enTileMode.None;
                mMousePointAtUIRectShow      = new EngineNS.UISystem.Controls.Image();
                await mMousePointAtUIRectShow.Initialize(rc, imgInit);

                mMousePointAtUIRectShow.Visibility = EngineNS.UISystem.Visibility.Collapsed;
            }
            if (mGridlineImage2D == null)
            {
                mGridlineImage2D = await EngineNS.Graphics.Mesh.CGfxImage2D.CreateImage2D(rc, EngineNS.RName.GetRName("uieditor/mi_background_grid.instmtl", EngineNS.RName.enRNameType.Editor), 0, 0, 0, 1, 1);

                mGridlineImage2D.RenderMatrix = EngineNS.Matrix.Scaling(Viewport.GetViewPortWidth(), Viewport.GetViewPortHeight(), 1);
            }
            await InitPanelRectsShow();

            var font = EngineNS.CEngine.Instance.FontManager.GetFont(EngineNS.CEngine.Instance.Desc.DefaultFont, 12, 1024, 128);

            if (mScaleFontMesh == null)
            {
                var mtl = await EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(rc, EngineNS.RName.GetRName("Material/font.instmtl"));

                mScaleFontMesh = new EngineNS.Bricks.FreeTypeFont.CFontMesh();
                await mScaleFontMesh.SetMaterial(rc, mtl, "txDiffuse");

                mScaleFontMesh.RenderMatrix = EngineNS.Matrix.Translate(20, 20, 0);
                //mScaleFontMesh.Offset = new EngineNS.Vector2(20, 20);
                //mScaleFontMesh.Scale = new EngineNS.Vector2(1, 1);
            }

            //var color = new EngineNS.FrameBufferClearColor();
            //color.r = 0.1f;
            //color.g = 0.1f;
            //color.b = 0.1f;
            //color.a = 1.0f;
            //Viewport.RPolicy.SetClearColorRT(0, ref color);
            var smp = EngineNS.Thread.ASyncSemaphore.CreateSemaphore(1);

            Viewport.RPolicy.OnDrawUI += (cmd, view) =>
            {
                var mtlmesh = mGridlineImage2D.Mesh.MtlMeshArray[0];
                var pass    = mGridlineImage2D.GetPass();
                pass.ViewPort = view.Viewport;
                if (pass.RenderPipeline == null)
                {
                    var rplDesc = new EngineNS.CRenderPipelineDesc();
                    pass.RenderPipeline = rc.CreateRenderPipeline(rplDesc);
                }
                pass.RenderPipeline.RasterizerState   = mtlmesh.MtlInst.CustomRasterizerState;
                pass.RenderPipeline.DepthStencilState = mtlmesh.MtlInst.CustomDepthStencilState;
                pass.RenderPipeline.BlendState        = mtlmesh.MtlInst.CustomBlendState;
                //pass.ShaderSamplerBinder = mtlmesh.GetSamplerBinder(rc, pass.Effect.ShaderProgram);
                pass.BindCBuffer(pass.Effect.ShaderProgram, pass.Effect.CacheData.CBID_View, view.ScreenViewCB);
                pass.ShadingEnv.BindResources(mGridlineImage2D.Mesh, pass);
                cmd.PushPass(pass);

                mWindowRectUIShow.Draw(rc, cmd, view);

                foreach (var rect in mPanelRectsShow.Values)
                {
                    rect.Draw(rc, cmd, view);
                }

                HostDesignPanel.CurrentUI.Draw(rc, cmd, view);
                mMousePointAtUIRectShow.Draw(rc, cmd, view);
                foreach (var data in mSelectedUIDatas.Values)
                {
                    data.ShowRect?.Draw(rc, cmd, view);
                }
                mSlotOperator?.Draw(rc, cmd, view);
                mScaleFontMesh.DrawText(rc, font, "缩放:" + mUIScale.ToString("F"), true);
                for (int i = 0; i < mScaleFontMesh.PassNum; i++)
                {
                    var fontPass = mScaleFontMesh.GetPass(i);
                    if (fontPass == null)
                    {
                        continue;
                    }

                    fontPass.ViewPort = view.Viewport;
                    fontPass.BindCBuffer(fontPass.Effect.ShaderProgram, fontPass.Effect.CacheData.CBID_View, view.ScreenViewCB);
                    fontPass.ShadingEnv.BindResources(mScaleFontMesh.Mesh, fontPass);
                    cmd.PushPass(fontPass);
                }

                if (smp.IsValid)
                {
                    smp.Release();
                }
            };
            await smp.Await();

            HostDesignPanel.CurrentUI.SetDesignRect(ref mWindowDesignSize);
            ShowAll();
        }