コード例 #1
0
        public virtual async System.Threading.Tasks.Task <bool> InitEnviroment(UInt32 w, UInt32 h, string name)
        {
            mWidth  = w;
            mHeight = h;
            var rc = EngineNS.CEngine.Instance.RenderContext;

            mCamera = new EngineNS.Graphics.CGfxCamera();
            mCamera.Init(rc, false);

            Vector3 Eye = new Vector3();

            Eye.SetValue(0.0f, 0.0f, -3.0f);
            Vector3 At = new Vector3();

            At.SetValue(0.0f, 0.0f, 0.0f);
            Vector3 Up = new Vector3();

            Up.SetValue(0.0f, 1.0f, 0.0f);
            mCamera.LookAtLH(Eye, At, Up);

            mCamera.PerspectiveFovLH(mCamera.mDefaultFoV, (float)mWidth, (float)mHeight, 0.1f, 1000.0f);
            mCamera.BeforeFrame();
            mCamera.SwapBuffer(false);

            mRP_OffScreen           = new EngineNS.Graphics.RenderPolicy.CGfxRP_OffScreen();
            mRP_OffScreen.OnDrawUI += (CCommandList cmd, Graphics.View.CGfxScreenView view) =>
            {
                if (UIHost != null)
                {
                    UIHost.Draw(CEngine.Instance.RenderContext, cmd, view);
                }
            };
            await mRP_OffScreen.Init(rc, mWidth, mHeight, mCamera, IntPtr.Zero);

            return(await InitWorld(name));
        }
コード例 #2
0
        public virtual async System.Threading.Tasks.Task <bool> InitEnvWithScene(UInt32 w, UInt32 h,
                                                                                 [Editor.Editor_RNameType(Editor.Editor_RNameTypeAttribute.Scene)]
                                                                                 RName map, bool startDraw = true)
        {
            if (w == 0)
            {
                w = 128;
            }
            if (h == 0)
            {
                h = 128;
            }
            if (map == null)
            {
                map = RName.EmptyName;
            }
            mWidth  = w;
            mHeight = h;
            var rc = EngineNS.CEngine.Instance.RenderContext;

            mCamera = new EngineNS.Graphics.CGfxCamera();
            mCamera.Init(rc, false);

            mCamera.PerspectiveFovLH(mCamera.mDefaultFoV, (float)mWidth, (float)mHeight, 0.1f, 1000.0f);
            mCamera.BeforeFrame();
            //mCamera.SwapBuffer(false);

            Vector3 Eye = new Vector3();

            Eye.SetValue(0.0f, 50.0f, -30.0f);
            Vector3 At = new Vector3();

            At.SetValue(0.0f, 0.0f, 0.0f);
            Vector3 Up = new Vector3();

            Up.SetValue(0.0f, 1.0f, 0.0f);
            mCamera.LookAtLH(Eye, At, Up);

            mRP_OffScreen           = new EngineNS.Graphics.RenderPolicy.CGfxRP_OffScreen();
            mRP_OffScreen.OnDrawUI += (CCommandList cmd, Graphics.View.CGfxScreenView view) =>
            {
                if (UIHost != null)
                {
                    UIHost.Draw(CEngine.Instance.RenderContext, cmd, view);
                }
            };
            await mRP_OffScreen.Init(rc, mWidth, mHeight, mCamera, IntPtr.Zero);

            UIHost.Initializer.Id = 1;
            UIHost.WindowSize     = new SizeF(mWidth, mHeight);

            mWorld = new EngineNS.GamePlay.GWorld();

            if (false == mWorld.Init())
            {
                return(false);
            }

            mWorld.CheckVisibleParam.UsePVS = false;
            SceneGraph.GSceneGraph scene = null;
            IO.XndHolder           xnd   = await IO.XndHolder.LoadXND(map.Address + "/scene.map");

            if (xnd == null)
            {
                scene = await GamePlay.SceneGraph.GSceneGraph.CreateSceneGraph(this.World, typeof(GamePlay.SceneGraph.GSceneGraph), new SceneGraph.GSceneGraphDesc());

                mWorld.AddScene(map, scene);
            }
            else
            {
                var type = Rtti.RttiHelper.GetTypeFromSaveString(xnd.Node.GetName());
                if (type == null)
                {
                    return(false);
                }
                scene = await GamePlay.SceneGraph.GSceneGraph.CreateSceneGraph(this.World, type, null);

                if (false == await scene.LoadXnd(rc, xnd.Node, map))
                {
                    return(false);
                }

                if (scene != null)
                {
                    World.AddScene(map, scene);
                    mWorld.SetDefaultScene(scene.SceneId);

                    if (mWorld.DefaultScene.SunActor != null)
                    {
                        var sunComp = mWorld.DefaultScene?.SunActor.GetComponent <EngineNS.GamePlay.Component.GDirLightComponent>();
                        if (sunComp != null)
                        {
                            sunComp.View = mRP_OffScreen.BaseSceneView;
                        }
                    }
                    if (scene.McSceneGetter != null && scene.McSceneGetter.Get(false) != null)
                    {
                        await scene.McSceneGetter.Get(false).OnSceneLoaded(scene);

                        scene.McSceneGetter.Get(false).OnRegisterInput();
                    }
                }
            }

            if (startDraw)
            {
                this.Start();
            }

            return(true);
        }