async Task Save()
        {
            var editor = EngineNS.CEngine.Instance.GameEditorInstance as CoreEditor.CEditorInstance;

            using (var i = editor.World.GetSceneEnumerator())
            {
                while (i.MoveNext())
                {
                    var scene = i.Current.Value;
                    if (scene.SceneFilename == null)
                    {
                        continue;
                    }

                    await scene.SaveScene(scene.SceneFilename, VP1.Camera);

                    // 生成缩略图
                    var snapShotFile = scene.SceneFilename.Address + EditorCommon.Program.SnapshotExt;
                    var data         = new EngineNS.Support.CBlobObject[1];
                    data[0] = new EngineNS.Support.CBlobObject();
                    var rc = EngineNS.CEngine.Instance.RenderContext;
                    VP1.RPolicy.mCopyPostprocessPass.mScreenView.FrameBuffer.GetSRV_RenderTarget(0).Save2Memory(rc, data[0], EngineNS.EIMAGE_FILE_FORMAT.PNG);
                    EngineNS.CShaderResourceView.SaveSnap(snapShotFile, data);
                }
            }

            await CurrentResourceInfo?.Save(true);
        }
Exemple #2
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);
        }
Exemple #3
0
        public static void CaptureGeoBox(EngineNS.Bricks.HollowMaker.Agent.GeoBox geoBox,
                                         EngineNS.Bricks.HollowMaker.GeomScene.AgentBoxs agentData,
                                         EngineNS.Graphics.CGfxCamera camera,
                                         EngineNS.CRenderContext rc,
                                         UInt32 numElem,
                                         EngineNS.Graphics.RenderPolicy.CGfxRP_SceneCapture rp,
                                         EngineNS.CCommandList cmd,
                                         UInt32 cbIndex,
                                         EngineNS.CConstantBuffer cbuffer,
                                         EngineNS.CGpuBuffer buffer_visible,
                                         EngineNS.CShaderDesc csMain_visible,
                                         EngineNS.CComputeShader cs_visible,
                                         EngineNS.CUnorderedAccessView uav_visible,
                                         EngineNS.CGpuBuffer buffer_setBit,
                                         EngineNS.CShaderDesc csMain_setBit,
                                         EngineNS.CComputeShader cs_setBit,
                                         EngineNS.CUnorderedAccessView uav_setBit,
                                         EngineNS.CComputeShader cs_Clear,
                                         List <EngineNS.Support.BitSet> savedBitsets,
                                         UInt32 textureIdx,
                                         Action <int, EngineNS.Support.CBlobObject, EngineNS.Support.CBlobObject> actionAfterCapturePerDir)
        {
            var cornerPos = geoBox.Box.GetCorners();

            //for(int posIdx = 0; posIdx < cornerPos.Length; posIdx++)
            //{
            //    await CaptureSceneWithPoint(cornerPos[posIdx], world, camera, rc, camDirs, camUps, dataBlobs, picBlobs);
            //}
            cmd.SetComputeShader(cs_visible);
            UInt32[] pUAVInitialCounts = new UInt32[1] {
                1,
            };
            cmd.CSSetUnorderedAccessView(0, uav_visible, pUAVInitialCounts);

            //await CaptureSceneWithPoint(geoBox.Box.GetCenter(), agentData.Mat , camera, rc, camDirs, camUps, numElem/*, dataBlobs, picBlobs*/);
            for (int camIdx = 0; camIdx < 6; camIdx++)
            {
                EngineNS.Support.CBlobObject idBlob  = null;
                EngineNS.Support.CBlobObject picBlob = null;
                EditorCommon.PVSAssist.CaptureWithPoint(geoBox.Box.GetCenter(), agentData.Mat, camera, rc, camDirs[camIdx], camUps[camIdx], numElem, rp, textureIdx, ref idBlob, ref picBlob);

                actionAfterCapturePerDir?.Invoke(camIdx, idBlob, picBlob);
            }

            // gbuffer0
            var blob = new EngineNS.Support.CBlobObject();

            buffer_visible.GetBufferData(rc, blob);
            var idArray = blob.ToUInts();

            // fill uav1, clear uav0
            cmd.SetComputeShader(cs_setBit);
            UInt32[] pUAVInitialCounts1 = new UInt32[1] {
                1,
            };
            cmd.CSSetUnorderedAccessView(0, uav_visible, pUAVInitialCounts);
            cmd.CSSetUnorderedAccessView(1, uav_setBit, pUAVInitialCounts);
            var cbDesc = new EngineNS.CConstantBufferDesc();

            if (csMain_setBit.GetCBufferDesc(cbIndex, ref cbDesc))
            {
                if (cbDesc.Type == EngineNS.ECBufferRhiType.SIT_CBUFFER)
                {
                    cmd.CSSetConstantBuffer(cbDesc.CSBindPoint, cbuffer);
                }
            }
            cmd.CSDispatch(numElem, 1, 1);

            var blob0 = new EngineNS.Support.CBlobObject();

            buffer_visible.GetBufferData(rc, blob0);
            var visArray = blob0.ToUInts();
            // gbuffer1
            var blob1 = new EngineNS.Support.CBlobObject();

            buffer_setBit.GetBufferData(rc, blob1);
            var idArray1 = blob1.ToBytes();

            var bitSet  = new EngineNS.Support.BitSet();
            var bitSet1 = new EngineNS.Support.BitSet();

            bitSet.Init(numElem * 2, idArray1);
            bitSet1.Init(numElem);
            for (UInt32 e = 0; e < numElem; e++)
            {
                var bit1 = bitSet.IsBit(e * 2 + 0);
                var bit2 = bitSet.IsBit(e * 2 + 1);

                bitSet1.SetBit(e, bit1 || bit2);
            }

            savedBitsets.Add(bitSet1);

            cmd.SetComputeShader(cs_Clear);
            cmd.CSSetUnorderedAccessView(0, uav_visible, pUAVInitialCounts);
            cmd.CSSetUnorderedAccessView(1, uav_setBit, pUAVInitialCounts);
            cmd.CSDispatch(numElem / 16 + 1, 1, 1);
        }
        public void TestComputeShader()
        {
            const string CSVersion = "cs_5_0";
            var          rc        = EngineNS.CEngine.Instance.RenderContext;
            var          macros    = new CShaderDefinitions();

            macros.SetDefine("USE_STRUCTURED_BUFFERS", "");
            var shaderFile            = RName.GetRName("Shaders/Compute/test1.compute").Address;
            var shaderRName_extractID = RName.GetRName("Shaders/Compute/test1.compute");
            var shaderRName_calcRate  = RName.GetRName("Shaders/Compute/calcrate.compute");
            //var shaderRName_clearID = RName.GetRName("Shaders/Compute/clearid.compute");

            var csMain0 = rc.CreateShaderDesc(shaderRName_extractID, "CSMain", EShaderType.EST_ComputeShader, macros, CIPlatform.Instance.PlatformType);
            var csMain1 = rc.CreateShaderDesc(shaderRName_calcRate, "CSMain1", EShaderType.EST_ComputeShader, macros, CIPlatform.Instance.PlatformType);
            //var csMain2 = rc.CreateShaderDesc(shaderRName_clearID, "CSMain_Clear", EShaderType.EST_ComputeShader, macros, CIPlatform.Instance.PlatformType);
            var csExtractID = rc.CreateComputeShader(csMain0);
            var csCalcRate  = rc.CreateComputeShader(csMain1);
            //var csClearID = rc.CreateComputeShader(csMain2);

            uint numElem = 8;
            var  bfDesc  = new CGpuBufferDesc();

            bfDesc.SetMode(false, true);
            bfDesc.ByteWidth           = 4 * numElem;
            bfDesc.StructureByteStride = 4;
            var buffer  = rc.CreateGpuBuffer(bfDesc, IntPtr.Zero);
            var uavDesc = new CUnorderedAccessViewDesc();

            uavDesc.ToDefault();
            uavDesc.Buffer.NumElements = numElem;
            var uav = rc.CreateUnorderedAccessView(buffer, uavDesc);

            var buffer1 = rc.CreateGpuBuffer(bfDesc, IntPtr.Zero);
            var uav1    = rc.CreateUnorderedAccessView(buffer1, uavDesc);

            var cmd = rc.ImmCommandList;

            cmd.SetComputeShader(csExtractID);

            UInt32[] pUAVInitialCounts = new UInt32[1] {
                1,
            };

            var dsv        = this.RenderPolicy.BaseSceneView.FrameBuffer.GetSRV_DepthStencil();
            var viewWidth  = this.RenderPolicy.BaseSceneView.Viewport.Width;
            var viewHeight = this.RenderPolicy.BaseSceneView.Viewport.Height;

            System.Diagnostics.Trace.WriteLine("[TestComputeShader] Framebuffer width :" + viewWidth.ToString() + ", height: " + viewHeight.ToString());
            var camVP = this.RenderPolicy.Camera.CameraData.ViewProjection;

            //var srcTex = CEngine.Instance.TextureManager.GetShaderRView(rc, RName.GetRName("Texture/testActorID.txpic"), true);
            //if (srcTex != null)
            //{
            //    srcTex.PreUse(true);
            //    cmd.CSSetShaderResource(0, srcTex);
            //}
            cmd.CSSetShaderResource(0, dsv);
            cmd.CSSetUnorderedAccessView(0, uav, pUAVInitialCounts);
            //uint texSizeW = 1092;
            //uint texSizeH = 516;
            cmd.CSDispatch((uint)viewWidth / 4, (uint)viewHeight / 4, 1);
            System.Diagnostics.Trace.WriteLine("[TestComputeShader] Dispatch width :" + viewWidth.ToString() + ", height: " + viewHeight.ToString());
            //uint texSize = 512;
            //cmd.CSDispatch(texSize/8, texSize/8, 1);

            var blob = new EngineNS.Support.CBlobObject();

            buffer.GetBufferData(rc, blob);
            var idArray = blob.ToUInts();

            // fill uav1, clear uav0
            cmd.SetComputeShader(csCalcRate);
            UInt32[] pUAVInitialCounts1 = new UInt32[1] {
                1,
            };
            var tempBufferData = new uint[8];

            tempBufferData[0] = 9543;
            tempBufferData[1] = 3756;
            tempBufferData[2] = 2716;
            tempBufferData[3] = 297;
            tempBufferData[4] = 961;
            tempBufferData[5] = 45046;
            tempBufferData[6] = 0;
            tempBufferData[7] = 5686;
            unsafe
            {
                fixed(uint *pData = &tempBufferData[0])
                {
                    var buffer2 = rc.CreateGpuBuffer(bfDesc, (IntPtr)pData);
                    var uav2    = rc.CreateUnorderedAccessView(buffer2, uavDesc);

                    cmd.CSSetUnorderedAccessView(0, uav2, pUAVInitialCounts);
                }
            }
            //cmd.CSSetUnorderedAccessView(0, uav, pUAVInitialCounts);
            cmd.CSSetUnorderedAccessView(1, uav1, pUAVInitialCounts);
            var cbIndex = csMain1.FindCBufferDesc("CaptureEnv");

            if (cbIndex != uint.MaxValue)
            {
                var cbuffer = rc.CreateConstantBuffer(csMain1, cbIndex);
                var varIdx  = cbuffer.FindVar("rateWeight");
                cbuffer.SetValue(varIdx, new EngineNS.Quaternion(100, 1000, 10000, 100000), 0);
                cbuffer.FlushContent(rc.ImmCommandList);
                var cbDesc = new EngineNS.CConstantBufferDesc();
                if (csMain1.GetCBufferDesc(cbIndex, ref cbDesc))
                {
                    if (cbDesc.Type == EngineNS.ECBufferRhiType.SIT_CBUFFER)
                    {
                        cmd.CSSetConstantBuffer(cbDesc.CSBindPoint, cbuffer);
                    }
                }
            }

            cmd.CSDispatch(8, 1, 1);

            // gbuffer1
            buffer.GetBufferData(rc, blob);
            idArray = blob.ToUInts();
            var blob1 = new EngineNS.Support.CBlobObject();

            buffer1.GetBufferData(rc, blob1);
            var idArray1     = blob1.ToBytes();
            var idUintArray1 = blob1.ToUInts();
        }
        async Task Save()
        {
            //CurrentResourceInfo.ReferenceRNameList.Clear();
            //Particle_Client.Save();

            //CurrentResourceInfo.CustomFunctions_Client.Clear();
            //Particle_Client.CollectFuncDatas(CurrentResourceInfo.CustomFunctions_Client);

            ////await CompileCode(EngineNS.EPlatformType.PLATFORM_DROID);
            //await CompileCode(EngineNS.EPlatformType.PLATFORM_WIN);

            //List<RName> rnames = new List<RName>();
            //await mCodeGenerator.GenerateMacrossResource(Particle_Client, rnames);


            //foreach (var rname in rnames)
            //{
            //    CurrentResourceInfo.ReferenceRNameList.Add(rname);
            //}
            //await CurrentResourceInfo.Save();



            CurrentResourceInfo.ReferenceRNameList.Clear();
            Particle_Client.Save();

            var className     = Program.GetClassName(CurrentResourceInfo, ECSType.Client);
            var classFullName = Program.GetClassNamespace(CurrentResourceInfo, ECSType.Client) + "." + className;

            WPG.Data.PropertyCollection.RemoveCache(EngineNS.CEngine.Instance.MacrossDataManager.MacrossScripAssembly.GetType(classFullName));

            CurrentResourceInfo.CustomFunctions_Client.Clear();
            Particle_Client.CollectFuncDatas(CurrentResourceInfo.CustomFunctions_Client);

            //await CompileCode(EngineNS.EPlatformType.PLATFORM_DROID);
            await CompileCode(EngineNS.EPlatformType.PLATFORM_WIN);

            List <RName> rnames = new List <RName>();
            await mCodeGenerator.CollectMacrossResource(Particle_Client, rnames);

            foreach (var rname in rnames)
            {
                CurrentResourceInfo.ReferenceRNameList.Add(rname);
            }

            await CurrentResourceInfo.Save();

            var IsShowFloor  = Particle_Client.SceneControl.IsShowFloor;
            var IsShowSkyBox = Particle_Client.SceneControl.IsShowSkyBox;

            Particle_Client.SceneControl.IsShowFloor  = false;
            Particle_Client.SceneControl.IsShowSkyBox = false;

            var snapShotFile = CurrentResourceInfo.ResourceName.Address + EditorCommon.Program.SnapshotExt;
            var data         = new EngineNS.Support.CBlobObject[1];

            data[0] = new EngineNS.Support.CBlobObject();
            var rc = EngineNS.CEngine.Instance.RenderContext;

            Particle_Client.SceneControl.ViewPort.RPolicy.mCopyPostprocessPass.mScreenView.FrameBuffer.GetSRV_RenderTarget(0).Save2Memory(rc, data[0], EngineNS.EIMAGE_FILE_FORMAT.PNG);
            EngineNS.CShaderResourceView.SaveSnap(snapShotFile, data);

            Particle_Client.SceneControl.IsShowFloor  = IsShowFloor;
            Particle_Client.SceneControl.IsShowSkyBox = IsShowSkyBox;
        }
        public override void DoImport(string file, string target, bool overwrite = false)
        {
            var rawData = EditorCommon.ImageInit.ReadRawData(file);
            //var pngData = EditorCommon.ImageInit.ConverImage2PNG(file);
            //if (pngData == null)
            //{
            //    EngineNS.Profiler.Log.WriteLine(EngineNS.Profiler.ELogTag.Error, "Resource", $"Texture {file} is not found");
            //    return;
            //}

            var xnd = EngineNS.IO.XndHolder.NewXNDHolder();
            var attr = xnd.Node.AddAttrib("Desc");

            attr.Version = 1;
            attr.BeginWrite();
            attr.Write(file);
            //这里最好导出的时候有参数,确定是否sRGB
            var txDesc = new EngineNS.CTxPicDesc();
            txDesc.SetDefault();
            unsafe
            {
                attr.Write((IntPtr)(&txDesc), sizeof(EngineNS.CTxPicDesc));
            }
            attr.EndWrite();

            attr = xnd.Node.AddAttrib("RawImage");
            attr.BeginWrite();
            attr.Write(rawData);
            attr.EndWrite();

            attr = xnd.Node.AddAttrib("PNG");
            attr.BeginWrite();
            var pngBlob = new EngineNS.Support.CBlobObject();
            EngineNS.CShaderResourceView.ConvertImage(EngineNS.CEngine.Instance.RenderContext, rawData, EIMAGE_FILE_FORMAT.PNG, pngBlob);
            var pngData = pngBlob.ToBytes();
            attr.Write(pngData);
            attr.EndWrite();

            attr = xnd.Node.AddAttrib("JPG");
            attr.BeginWrite();
            var jpgBlob = new EngineNS.Support.CBlobObject();
            EngineNS.CShaderResourceView.ConvertImage(EngineNS.CEngine.Instance.RenderContext, rawData, EIMAGE_FILE_FORMAT.JPG, jpgBlob);
            attr.Write(jpgBlob.ToBytes());
            attr.EndWrite();

            attr = xnd.Node.AddAttrib("DDS");
            attr.BeginWrite();
            var ddsBlob = new EngineNS.Support.CBlobObject();
            EngineNS.CShaderResourceView.ConvertImage(EngineNS.CEngine.Instance.RenderContext, rawData, EIMAGE_FILE_FORMAT.DDS, ddsBlob);
            attr.Write(ddsBlob.ToBytes());
            attr.EndWrite();

            attr = xnd.Node.AddAttrib("ETC2");
            attr.BeginWrite();
            //EngineNS.CShaderResourceView.SaveETC2(file, attr, 0, true);
            EngineNS.CShaderResourceView.SaveETC2_Png(pngData, attr, 0, true);
            attr.EndWrite();

            var pos = target.LastIndexOf('.');
            target = target.Substring(0, pos);
            target += EngineNS.CEngineDesc.TextureExtension;
            EngineNS.IO.XndHolder.SaveXND(target, xnd);

            pos = this.ResourceName.Name.LastIndexOf('.');
            var newRName = this.ResourceName.Name.Substring(0, pos);
            newRName += EngineNS.CEngineDesc.TextureExtension;
            this.ResourceName = RName.GetRName(newRName);
        }
        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);
        }
Exemple #8
0
        public async System.Threading.Tasks.Task SaveToFile(string strFileName, long duration, int frame = 4)
        {
            mDuration = duration;
            mFrameNum = 1;// frame;
            mRP_Snapshot.OnAfterTickLogic = (InView, InRc, InCmd, InArg) =>
            {
                CTexture2D ReadableTex = null;
                InCmd.CreateReadableTexture2D(ref ReadableTex, mRP_Snapshot.BaseSceneView.FrameBuffer.GetSRV_RenderTarget(0), mRP_Snapshot.BaseSceneView.FrameBuffer);
                EngineNS.CEngine.Instance.GpuFetchManager.RegFetchTexture2D(ReadableTex, (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);
                        }
                    }
                    EngineNS.CEngine.Instance.EventPoster.RunOn(() =>
                    {
                        var blbArray = new EngineNS.Support.CBlobObject[] { blob };
                        CShaderResourceView.SaveSnap(strFileName, blbArray);
                        return(true);
                    }, EngineNS.Thread.Async.EAsyncTarget.AsyncEditor);
                });
            };
            var rp = CEngine.Instance.GetCurrentModule().RenderPolicy as EngineNS.Graphics.RenderPolicy.CGfxRP_EditorMobile;

            if (rp != null)
            {
                lock (rp.mSnapshots)
                {
                    rp.mSnapshots.Add(this);
                }
            }
            //frame = 1;
            //await EngineNS.Thread.AsyncDummyClass.DummyFunc();
            //var rc = CEngine.Instance.RenderContext;

            //foreach (var actor in mWorld.Actors.Values)
            //{
            //    actor.PreUse(true);
            //}

            //CalculateCamera(mCamera, 1.0);

            //EngineNS.CEngine.Instance.TextureManager.PauseKickResource = true;
            //var saveTime = EngineNS.CEngine.Instance.EngineTime;
            //var saveElapse = EngineNS.CEngine.Instance.EngineElapseTime;
            //EngineNS.Support.CBlobObject[] data = new EngineNS.Support.CBlobObject[frame];
            //mRP_Snapshot.OnAfterTickLogic = (InView, InRc, InCmd, InArg) =>
            //{
            //    CTexture2D ReadableTex = null;
            //    InCmd.CreateReadableTexture2D(ref ReadableTex, mRP_Snapshot.BaseSceneView.FrameBuffer.GetSRV_RenderTarget(0), mRP_Snapshot.BaseSceneView.FrameBuffer);
            //    EngineNS.CEngine.Instance.GpuFetchManager.RegFetchTexture2D(ReadableTex, (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 = true;
            //        //    if (bSave)
            //        //    {
            //        //        var blbArray = new EngineNS.Support.CBlobObject[] { blob };
            //        //        CShaderResourceView.SaveSnap(strFileName, blbArray);
            //        //    }
            //        //    return;
            //        //}
            //        if (InArg == null)
            //            InArg = (int)0;
            //        data[(int)InArg] = new EngineNS.Support.CBlobObject();

            //        var t1 = EngineNS.Support.Time.HighPrecision_GetTickCount();
            //        unsafe
            //        {
            //            void* pData;
            //            uint rowPitch;
            //            uint depthPitch;
            //            if (InSrv.Map(CEngine.Instance.RenderContext.ImmCommandList, 0, &pData, &rowPitch, &depthPitch))
            //            {
            //                InSrv.BuildImageBlob(data[(int)InArg], pData, rowPitch);
            //                InSrv.Unmap(CEngine.Instance.RenderContext.ImmCommandList, 0);
            //            }
            //        }
            //        var t2 = EngineNS.Support.Time.HighPrecision_GetTickCount();

            //        System.Diagnostics.Debug.WriteLine($"Fetch Snap time : {t2 - t1}");

            //        int finishCount = 0;
            //        foreach (var i in data)
            //        {
            //            if (i != null)
            //                finishCount++;
            //        }
            //        if (finishCount == data.Length)
            //        {
            //            EngineNS.CEngine.Instance.EventPoster.RunOn(() =>
            //            {
            //                CShaderResourceView.SaveSnap(strFileName, data);
            //                //foreach (var i in data)
            //                //{
            //                //    i.Dispose();
            //                //}
            //                //data = null;
            //                //System.GC.Collect();
            //                return true;
            //            }, EngineNS.Thread.Async.EAsyncTarget.AsyncEditor);
            //        }
            //        return;
            //    });
            //};
            //for (int i = 0; i < frame; i++)
            //{
            //    EngineNS.CEngine.Instance._UpdateEngineTime(saveTime + duration * i / frame);
            //    EngineNS.CEngine.Instance.SetPerFrameCBuffer();

            //    TickLogicEvent?.Invoke(this, i);
            //    mRP_Snapshot.TickSync();
            //    mRP_Snapshot.TickRender(null);

            //    TickLogicEvent?.Invoke(this, i);
            //    mRP_Snapshot.TickSync();
            //    mRP_Snapshot.TickRender(null);
            //}
            //EngineNS.CEngine.Instance._ResetTime(saveTime, saveElapse);
            //EngineNS.CEngine.Instance.SetPerFrameCBuffer();
            //EngineNS.CEngine.Instance.TextureManager.PauseKickResource = false;
            //mRP_Snapshot.OnAfterTickLogic = null;

            //FinalCleanup();
        }
Exemple #9
0
        public static bool SaveTxPic(IO.XndHolder xnd, ref CTxPicDesc txDesc, string filename,
                                     ETCFormat etcFormat = ETCFormat.RGBA8,
                                     int mipMapLevel     = 0)
        {
            #region Read Pixels
            var imageimport = new EngineNS.Bricks.ImageImport.ImageImport();
            EngineNS.Support.CBlobObject blob = new EngineNS.Support.CBlobObject();
            imageimport.LoadTexture(filename, blob);
            int w        = imageimport.GetWidth();
            int h        = imageimport.GetHeight();
            int channels = imageimport.GetChannels();

            byte[] data = blob.ToBytes();//new byte[w * h * channels];
            System.Drawing.Imaging.PixelFormat format = System.Drawing.Imaging.PixelFormat.Undefined;
            if (channels == 4)
            {
                format = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
            }
            else if (channels == 3)
            {
                format = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
            }
            else if (channels == 1)
            {
                format = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
            }

            var bitmap = new System.Drawing.Bitmap(w, h, format);
            int offset = 0;
            for (int j = 0; j < h; j++)
            {
                for (int i = 0; i < w; i++)
                {
                    if (channels == 4)
                    {
                        System.Drawing.Color color = System.Drawing.Color.FromArgb(data[offset + 3], data[offset], data[offset + 1], data[offset + 2]);
                        offset += 4;
                        bitmap.SetPixel(i, j, color);
                    }
                    else if (channels == 3)
                    {
                        System.Drawing.Color color = System.Drawing.Color.FromArgb(data[offset], data[offset + 1], data[offset + 2]);
                        offset += 3;
                        bitmap.SetPixel(i, j, color);
                    }
                    else if (channels == 1)
                    {
                        System.Drawing.Color color = System.Drawing.Color.FromArgb(data[offset++]);
                        bitmap.SetPixel(i, j, color);
                    }
                }
            }
            var tagBitmap = bitmap.Clone(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            #endregion

            if (bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
            {
                txDesc.EtcFormat = ETCFormat.UNKNOWN;
            }
            txDesc.Width  = w;
            txDesc.Height = h;

            SaveTxPic(xnd, ref txDesc, tagBitmap, etcFormat, mipMapLevel);
            return(true);
        }
        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);
        }