Exemple #1
0
        public static void CaptureWithPoint(EngineNS.Vector3 point,
                                            EngineNS.Matrix worldMatrix,
                                            EngineNS.Graphics.CGfxCamera camera,
                                            EngineNS.CRenderContext rc,
                                            EngineNS.Vector3 camDir,
                                            EngineNS.Vector3 camUp,
                                            UInt32 actorsCount,
                                            EngineNS.Graphics.RenderPolicy.CGfxRP_SceneCapture rp,
                                            UInt32 textureIdx,
                                            ref EngineNS.Support.CBlobObject dataBlob,
                                            ref EngineNS.Support.CBlobObject picBlob)
        {
            var lookat = point + camDir;

            lookat = EngineNS.Vector3.TransformCoordinate(lookat, worldMatrix);
            point  = EngineNS.Vector3.TransformCoordinate(point, worldMatrix);
            camUp  = EngineNS.Vector3.TransformNormal(camUp, worldMatrix);
            camera.LookAtLH(point, lookat, camUp);
            camera.BeforeFrame();

            //world.Tick();
            //world.SlowDrawAll(rc, camera);

            var maxId = actorsCount;

            rp.TickLogic(null, rc);
            camera.SwapBuffer(true);
            rp.TickRender(null);
            //camera.ClearAllRenderLayerData();

            // debug
#pragma warning disable 0162
            if (false)
            {
                var texRGB = rp.CaptureSV.FrameBuffer.GetSRV_RenderTarget(1);
                texRGB.Save2File(rc, "e:/testCapture.bmp", EngineNS.EIMAGE_FILE_FORMAT.BMP);
            }
#pragma warning restore 0162

            if (rp.UseCapture)
            {
                var blob = new EngineNS.Support.CBlobObject();
                blob.PushData(rp.TexData0.Data, rp.TexData0.Size);
                dataBlob = blob;
                if (rp.CaptureRGBData)
                {
                    blob = new EngineNS.Support.CBlobObject();
                    blob.PushData(rp.TexData1.Data, rp.TexData1.Size);
                    picBlob = blob;
                }
                //await EngineNS.CEngine.Instance.EventPoster.Post(() =>
                //{
                //    rp.CaptureSV.mFrameBuffer.GetSRV_RenderTarget(0).Save2File($"D:\\{camIdx}.png", (int)mWidth, (int)mHeight, (int)(mWidth * 4), rp.TexData0.ToBytes(), EngineNS.EIMAGE_FILE_FORMAT.PNG);
                //    rp.CaptureSV.mFrameBuffer.GetSRV_RenderTarget(1).Save2File($"D:\\{camIdx}_ref.png", (int)mWidth, (int)mHeight, (int)(mWidth * 4), rp.TexData1.ToBytes(), EngineNS.EIMAGE_FILE_FORMAT.PNG);

                //    return true;
                //}, EngineNS.Thread.Async.EAsyncTarget.AsyncEditor);
            }

            var cmd            = EngineNS.CEngine.Instance.RenderContext.ImmCommandList;
            var actirIdTexture = rp.GetActoridTexture();
            cmd.CSSetShaderResource(textureIdx, actirIdTexture);


            uint texSize = 512;
            cmd.CSDispatch(texSize / 8, texSize / 8, 1);
        }
        private void AddActorToNavModifierVolume(EngineNS.GamePlay.Actor.GActor actor)
        {
            if (RCTileMeshBuilder.InputGeom == null)
            {
                return;
            }

            var component = actor.GetComponent <EngineNS.Bricks.RecastRuntime.NavMeshBoundVolumeComponent>();

            if (component == null)
            {
                return;
            }

            EngineNS.Support.CBlobObject blob    = new EngineNS.Support.CBlobObject();
            EngineNS.BoundingBox         box     = component.GetBox();
            EngineNS.Vector3[]           corners = box.GetCorners();
            EngineNS.Vector3[]           Points  = new EngineNS.Vector3[8 * 3];
            Points[0] = corners[0];
            Points[1] = corners[1];

            Points[2] = corners[0];
            Points[3] = corners[4];

            Points[4] = corners[0];
            Points[5] = corners[3];

            Points[6] = corners[1];
            Points[7] = corners[5];

            Points[8] = corners[1];
            Points[9] = corners[2];

            Points[10] = corners[2];
            Points[11] = corners[3];

            Points[12] = corners[2];
            Points[13] = corners[6];

            Points[14] = corners[3];
            Points[15] = corners[7];

            Points[16] = corners[4];
            Points[17] = corners[5];

            Points[18] = corners[4];
            Points[19] = corners[7];

            Points[20] = corners[5];
            Points[21] = corners[6];

            Points[22] = corners[6];
            Points[23] = corners[7];

            List <float> data = new List <float>();

            for (int i = 0; i < 24; i++)
            {
                data.Add(Points[i].X);
                data.Add(Points[i].Y);
                data.Add(Points[i].Z);
            }

            float[] blobdata = data.ToArray();
            unsafe
            {
                fixed(float *p = &blobdata[0])
                {
                    blob.PushData((IntPtr)p, (uint)(sizeof(float) * blobdata.Length));
                }
            }


            RCTileMeshBuilder.InputGeom.CreateConvexVolumes(component.RCAreaType, blob, ref box.Minimum, ref box.Maximum);
        }