public bool Init(CRenderContext rc, bool autoFlush) { mCamera = new CGfxCamera(); Camera.DebugName = "GCameraComponent"; if (!Camera.Init(rc, autoFlush)) { return(false); } PerspectiveFovLH(); var eye = new EngineNS.Vector3(); eye.SetValue(0.0f, 0.0f, -3.6f); var at = new EngineNS.Vector3(); at.SetValue(0.0f, 0.0f, 0.0f); var up = new EngineNS.Vector3(); up.SetValue(0.0f, 1.0f, 0.0f); Camera.LookAtLH(eye, at, up); return(true); }
private async System.Threading.Tasks.Task <bool> TestSnapRender(CRenderContext rc) { var mCurMesh = await CEngine.Instance.MeshManager.CreateMeshAsync(rc, RName.GetRName("editor/basemesh/box.gms")); if (mCurMesh == null) { return(false); } mTestSnapshort = new Editor.GSnapshotCreator(); mTestSnapshort.SkyName = EngineNS.RName.GetRName("Mesh/sky.gms"); mTestSnapshort.FloorName = EngineNS.RName.GetRName(@"editor/floor.gms"); var eye = new EngineNS.Vector3(); eye.SetValue(1.6f, 1.5f, -3.6f); var at = new EngineNS.Vector3(); at.SetValue(0.0f, 0.0f, 0.0f); var up = new EngineNS.Vector3(); up.SetValue(0.0f, 1.0f, 0.0f); await mTestSnapshort.InitEnviroment(); mTestSnapshort.Camera.LookAtLH(eye, at, up); var actor = EngineNS.GamePlay.Actor.GActor.NewMeshActorDirect(mCurMesh); mCurMesh.PreUse(true);//就这个地方用,别的地方别乱用,效率不好 mTestSnapshort.World.AddActor(actor); mTestSnapshort.World.GetScene(RName.GetRName("SnapshorCreator")).AddActor(actor); mTestSnapshort.FocusActor = actor; actor.Placement.Location = new Vector3(0, 0, 0); OnFetchFinished = (InSrv) => { var blob = new EngineNS.Support.CBlobObject(); unsafe { void *pData; uint rowPitch; uint depthPitch; if (InSrv.Map(CEngine.Instance.RenderContext.ImmCommandList, 0, &pData, &rowPitch, &depthPitch)) { InSrv.BuildImageBlob(blob, pData, rowPitch); InSrv.Unmap(CEngine.Instance.RenderContext.ImmCommandList, 0); } } bool bSave = false; if (bSave) { var blbArray = new EngineNS.Support.CBlobObject[] { blob }; CShaderResourceView.SaveSnap(@"D:\OpenSource\titan3d\Content\editor\basemesh\box.gms.snap", blbArray); } }; mTestSnapshort.mRP_Snapshot.OnAfterTickLogic = (InView, InRc, InCmd, InArg) => { CTexture2D ReadableTex = null; InCmd.CreateReadableTexture2D(ref ReadableTex, mTestSnapshort.mRP_Snapshot.BaseSceneView.FrameBuffer.GetSRV_RenderTarget(0), mTestSnapshort.mRP_Snapshot.BaseSceneView.FrameBuffer); EngineNS.CEngine.Instance.GpuFetchManager.RegFetchTexture2D(ReadableTex, OnFetchFinished); }; return(true); }