Beispiel #1
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 BuildGeoScene(EngineNS.GamePlay.SceneGraph.GSceneGraph scene)
        {
            if (scene.SceneFilename == null)
            {
                return;
            }

            EngineNS.Bricks.HollowMaker.GeomScene geomscene = new EngineNS.Bricks.HollowMaker.GeomScene();
            HollowMakerAgent.AgentComponenetBox = new List <EngineNS.BoundingBox>();
            float osize = HollowMakerAgent.AgentGridSize;

            //先处理一遍摆放好的AgentGeomBoxComponent..
            foreach (var value in scene.Actors)
            {
                EngineNS.GamePlay.Actor.GActor actor = value.Value;
                if (actor != null)
                {
                    EngineNS.Bricks.HollowMaker.AgentGeomBoxComponent acom = actor.GetComponent <EngineNS.Bricks.HollowMaker.AgentGeomBoxComponent>();

                    if (acom != null)
                    {
                        HollowMakerAgent.AgentGridSize = acom.AgentGridSize;
                        EngineNS.Vector3    scale;
                        EngineNS.Quaternion rotation;
                        EngineNS.Vector3    translation;
                        if (actor.Placement != null && actor.Placement.WorldMatrix.Decompose(out scale, out rotation, out translation))
                        {
                            geomscene.AgentData = new List <EngineNS.Bricks.HollowMaker.Agent.GeoBox>();
                            BuildWalkables(acom.StartPos, translation, scale, rotation);
                            HollowMakerAgent.BuildGeomScene(geomscene);
                            //TODO..
                            HollowMakerAgent.AgentComponenetBox.Add(acom.Box);

                            EngineNS.Bricks.HollowMaker.GeomScene.AgentBoxs AgentBoxs = new EngineNS.Bricks.HollowMaker.GeomScene.AgentBoxs();
                            AgentBoxs.AgentData = geomscene.AgentData;
                            AgentBoxs.Mat       = EngineNS.Matrix.Transformation(EngineNS.Vector3.UnitXYZ, rotation, translation);
                            AgentBoxs.BVSize    = scale;
                            geomscene.AgentDatas.Add(AgentBoxs);
                        }
                    }
                }
            }

            //HollowMakerAgent.AgentGridSize = osize;
            //foreach (var value in scene.Actors)
            //{
            //    EngineNS.GamePlay.Actor.GActor actor;
            //    var compment = value.Value.TryGetTarget(out actor);
            //    if (actor != null)
            //    {
            //        EngineNS.LooseOctree.OctreeVolumeComponent com = actor.GetComponent<EngineNS.LooseOctree.OctreeVolumeComponent>();
            //        if (com != null)
            //        {
            //            EngineNS.BoundingBox box = new EngineNS.BoundingBox();
            //            actor.GetAABB(ref box);
            //            BuildWalkables(box);
            //            HollowMakerAgent.BuildGeomScene(geomscene);
            //        }
            //    }
            //}

            // var test = geomscene.CreateRenderInfos(VP1.World);

            geomscene.SaveXND(scene.SceneFilename.Address + "/geoscene.dat");
            //EngineNS.Bricks.HollowMaker.GeomScene temp = await EngineNS.Bricks.HollowMaker.GeomScene.CreateGeomScene(scene.SceneFilename.Address + "/geoscene.dat");
            //int xx = 0;
        }