public bool FindStraightPath(Vector3 start, Vector3 end, Support.CBlobObject blob) { unsafe { return(SDK_RcNavQuery_FindStraightPath(mCoreObject, &start, &end, blob.CoreObject)); } }
public bool Write(Support.CBlobObject blob) { System.Diagnostics.Debug.Assert(Writing); if (CoreObject.Pointer == IntPtr.Zero) { return(false); } Support.CBlobObject.SDK_IBlobObject_Write2Xnd(blob.CoreObject, CoreObject); return(true); }
public bool Read(out Support.CBlobObject blob) { blob = null; System.Diagnostics.Debug.Assert(Reading); if (CoreObject.Pointer == IntPtr.Zero) { return(false); } blob = new Support.CBlobObject(); Support.CBlobObject.SDK_IBlobObject_ReadFromXnd(blob.CoreObject, CoreObject); return(true); }
public bool Init(UInt32 streams, EIndexBufferType ibType, int atom) { if (false == SDK_GfxMeshDataProvider_Init(CoreObject, streams, ibType, atom)) { return(false); } var ptr = SDK_GfxMeshDataProvider_GetIndices(CoreObject); IndexBuffer = new Support.CBlobObject(ptr); for (int i = 0; i < (int)EVertexSteamType.VST_Number; i++) { ptr = SDK_GfxMeshDataProvider_GetStream(CoreObject, (EVertexSteamType)i); if (ptr.GetPointer() == IntPtr.Zero) { continue; } VertexBuffers[i] = new Support.CBlobObject(ptr); } return(true); }
public bool InitFromMesh(CRenderContext rc, CGfxMeshPrimitives mesh) { mesh.PreUse(true); if (false == SDK_GfxMeshDataProvider_InitFromMesh(CoreObject, rc.CoreObject, mesh.CoreObject)) { return(false); } var ptr = SDK_GfxMeshDataProvider_GetIndices(CoreObject); IndexBuffer = new Support.CBlobObject(ptr); for (int i = 0; i < (int)EVertexSteamType.VST_Number; i++) { ptr = SDK_GfxMeshDataProvider_GetStream(CoreObject, (EVertexSteamType)i); if (ptr.GetPointer() == IntPtr.Zero) { continue; } VertexBuffers[i] = new Support.CBlobObject(ptr); } return(true); }
public bool CookTriMesh(CRenderContext rc, CGeometryMesh mesh, Support.CBlobObject blob, Support.CBlobObject uvblob, Support.CBlobObject faceblob, Support.CBlobObject posblob) { return(SDK_PhyContext_CookTriMesh(CoreObject, rc.CoreObject, mesh.CoreObject, blob.CoreObject, uvblob.CoreObject, faceblob.CoreObject, posblob.CoreObject)); }
public bool CookConvexMesh(CRenderContext rc, CGeometryMesh mesh, Support.CBlobObject blob) { return(SDK_PhyContext_CookConvexMesh(CoreObject, rc.CoreObject, mesh.CoreObject, blob.CoreObject)); }
public static async System.Threading.Tasks.Task <CGfxVertexCloud> CookFromMesh(CRenderContext rc, CGfxMeshPrimitives mesh, float density = 1.0f) { mesh.PreUse(true); var result = new CGfxVertexCloud(); var posVB = mesh.GeometryMesh.GetVertexBuffer(EVertexSteamType.VST_Position); if (posVB == null) { return(null); } var uvVB = mesh.GeometryMesh.GetVertexBuffer(EVertexSteamType.VST_UV); if (uvVB == null) { return(null); } var indexBuff = mesh.GeometryMesh.GetIndexBuffer(); if (indexBuff == null) { return(null); } var posBlob = new Support.CBlobObject(); var uvBlob = new Support.CBlobObject(); var indexBlob = new Support.CBlobObject(); await CEngine.Instance.EventPoster.Post(() => { posVB.GetBufferData(rc, posBlob); uvVB.GetBufferData(rc, uvBlob); if (density != 1.0f) { indexBuff.GetBufferData(rc, indexBlob); } return(true); }, Thread.Async.EAsyncTarget.Render); //await posVB.GetBufferData(rc, posBlob); //await uvVB.GetBufferData(rc, uvBlob); if (density == 1.0f) { unsafe { UInt32 num = posBlob.Size / (UInt32)sizeof(Vector3); result.Positions = new Vector3[num]; Vector3 *src = (Vector3 *)posBlob.Data.ToPointer(); fixed(Vector3 *dst = &result.Positions[0]) { for (UInt32 i = 0; i < num; i++) { dst[i] = src[i]; } } num = uvBlob.Size / (UInt32)sizeof(Vector2); result.Datas = new Vector4[num]; Vector2 *src2 = (Vector2 *)uvBlob.Data.ToPointer(); fixed(Vector4 *dst = &result.Datas[0]) { for (UInt32 i = 0; i < num; i++) { dst[i].X = src2[i].X; dst[i].Y = src2[i].Y; } } } } else { List <TSurface> surfaces = new List <TSurface>(); unsafe { UInt32 num = posBlob.Size / (UInt32)sizeof(Vector3); UInt32 numindex = 0; Vector3 *src = (Vector3 *)posBlob.Data.ToPointer(); if (indexBuff.Desc.Type == EIndexBufferType.IBT_Int16) { numindex = indexBlob.Size / sizeof(UInt16); UInt16 *indices = (UInt16 *)indexBlob.Data.ToPointer(); for (int i = 0; i < numindex; i += 3) { surfaces.Add(CreateSurface(ref src[indices[i]], ref src[indices[i + 1]], ref src[indices[i + 2]])); } } else { numindex = indexBlob.Size / sizeof(UInt32); UInt32 *indices = (UInt32 *)indexBlob.Data.ToPointer(); for (int i = 0; i < numindex; i += 3) { surfaces.Add(CreateSurface(ref src[indices[i]], ref src[indices[i + 1]], ref src[indices[i + 2]])); } } //根据面积排序 surfaces.Sort((a, b) => { if (a.S > b.S) { return(1); } else if (a.S < b.S) { return(-1); } return(0); }); //填充点 List <Vector3> Positions = new List <Vector3>(); for (UInt32 i = 0; i < num; i++) { Positions.Add(src[i]); } int count = (int)((density - 1f) / 0.5f); for (int n = 0; n < count; n++) { int surfacecount = surfaces.Count / 2; for (int i = surfaces.Count - 1; i >= surfacecount; i--) { Positions.Add((surfaces[i].Point1 + surfaces[i].Point2 + surfaces[i].Point3) / 3); var p1 = (surfaces[i].Point1 + surfaces[i].Point2) / 2; var p2 = (surfaces[i].Point2 + surfaces[i].Point3) / 2; var p3 = (surfaces[i].Point3 + surfaces[i].Point1) / 2; var ss = surfaces[i].S; var sss = surfaces[surfaces.Count - 1 - i].S; Positions.Add(p1); Positions.Add(p2); Positions.Add(p3); surfaces.RemoveAt(surfaces.Count - 1); surfaces.Add(CreateSurface(ref p1, ref p2, ref p3)); } if (n != count - 1) { surfaces.Sort((a, b) => { if (a.S > b.S) { return(1); } else if (a.S < b.S) { return(-1); } return(0); }); } } result.Positions = new Vector3[Positions.Count]; fixed(Vector3 *dst = &result.Positions[0]) { for (int i = 0; i < Positions.Count; i++) { dst[i] = Positions[i]; } } result.Datas = new Vector4[1]; } } return(result); }
public void CreateConvexVolumes(RecastRuntime.NavMeshBoundVolumeComponent.AreaType areatype, Support.CBlobObject blob, ref Vector3 min, ref Vector3 max) { SDK_InputGeom_CreateConvexVolumes(CoreObject, areatype, blob.CoreObject, min, max); }
public bool InitMesh(CRenderContext rc, Graphics.Mesh.CGfxMeshPrimitives mesh) { mMesh = mesh; mesh.PreUse(); EnablePosition = false; EnableNormal = false; EnableTangent = false; EnableColor = false; EnableUV = false; EnableLightMapUV = false; EnableSkinIndex = false; EnableSkinWeight = false; EnableTerrainIndex = false; EnableTerrainGradient = false; AABB = mesh.AABB; int vertNum = 0; Vertices.Clear(); #region Position var vb = mesh.GeometryMesh.GetVertexBuffer(EVertexSteamType.VST_Position); if (vb != null) { EnablePosition = true; var blob = new Support.CBlobObject(); vb.GetBufferData(rc, blob); unsafe { vertNum = (int)blob.Size / sizeof(Vector3); var ptr = (Vector3 *)blob.Data.ToPointer(); for (int i = 0; i < vertNum; i++) { var vert = new Vertex(); vert.Position = ptr[i]; Vertices.Add(vert); } } } else { return(false); } #endregion #region Normal vb = mesh.GeometryMesh.GetVertexBuffer(EVertexSteamType.VST_Normal); if (vb != null) { EnableNormal = true; var blob = new Support.CBlobObject(); vb.GetBufferData(rc, blob); unsafe { var ptr = (Vector3 *)blob.Data.ToPointer(); for (int i = 0; i < vertNum; i++) { Vertices[i].Normal = ptr[i]; } } } #endregion #region Tangent vb = mesh.GeometryMesh.GetVertexBuffer(EVertexSteamType.VST_Tangent); if (vb != null) { EnableTangent = true; var blob = new Support.CBlobObject(); vb.GetBufferData(rc, blob); unsafe { var ptr = (Vector4 *)blob.Data.ToPointer(); for (int i = 0; i < vertNum; i++) { Vertices[i].Tangent = ptr[i]; } } } #endregion #region Color vb = mesh.GeometryMesh.GetVertexBuffer(EVertexSteamType.VST_Color); if (vb != null) { EnableColor = true; var blob = new Support.CBlobObject(); vb.GetBufferData(rc, blob); unsafe { var ptr = (Byte4 *)blob.Data.ToPointer(); for (int i = 0; i < vertNum; i++) { Vertices[i].Color = ptr[i]; } } } #endregion #region UV vb = mesh.GeometryMesh.GetVertexBuffer(EVertexSteamType.VST_UV); if (vb != null) { EnableUV = true; var blob = new Support.CBlobObject(); vb.GetBufferData(rc, blob); unsafe { var ptr = (Vector2 *)blob.Data.ToPointer(); for (int i = 0; i < vertNum; i++) { Vertices[i].UV = ptr[i]; } } } #endregion #region LightMapUV vb = mesh.GeometryMesh.GetVertexBuffer(EVertexSteamType.VST_LightMap); if (vb != null) { EnableLightMapUV = true; var blob = new Support.CBlobObject(); vb.GetBufferData(rc, blob); unsafe { var ptr = (Vector2 *)blob.Data.ToPointer(); for (int i = 0; i < vertNum; i++) { Vertices[i].LightMapUV = ptr[i]; } } } #endregion #region SkinIndex vb = mesh.GeometryMesh.GetVertexBuffer(EVertexSteamType.VST_SkinIndex); if (vb != null) { EnableSkinIndex = true; var blob = new Support.CBlobObject(); vb.GetBufferData(rc, blob); unsafe { var ptr = (Byte4 *)blob.Data.ToPointer(); for (int i = 0; i < vertNum; i++) { Vertices[i].SkinIndex = ptr[i]; } } } #endregion #region SkinWeight vb = mesh.GeometryMesh.GetVertexBuffer(EVertexSteamType.VST_SkinWeight); if (vb != null) { EnableSkinWeight = true; var blob = new Support.CBlobObject(); vb.GetBufferData(rc, blob); unsafe { var ptr = (Vector4 *)blob.Data.ToPointer(); for (int i = 0; i < vertNum; i++) { Vertices[i].SkinWeight = ptr[i]; } } } #endregion #region TerrainIndex vb = mesh.GeometryMesh.GetVertexBuffer(EVertexSteamType.VST_TerrainIndex); if (vb != null) { EnableTerrainIndex = true; var blob = new Support.CBlobObject(); vb.GetBufferData(rc, blob); unsafe { var ptr = (Byte4 *)blob.Data.ToPointer(); for (int i = 0; i < vertNum; i++) { Vertices[i].TerrainIndex = ptr[i]; } } } #endregion #region TerrainGradient vb = mesh.GeometryMesh.GetVertexBuffer(EVertexSteamType.VST_TerrainGradient); if (vb != null) { EnableTerrainGradient = true; var blob = new Support.CBlobObject(); vb.GetBufferData(rc, blob); unsafe { var ptr = (Byte4 *)blob.Data.ToPointer(); for (int i = 0; i < vertNum; i++) { Vertices[i].TerrainGradient = ptr[i]; } } } #endregion List <int> OriIndices = new List <int>(); #region Face var ib = mesh.GeometryMesh.GetIndexBuffer(); if (ib != null) { var blob = new Support.CBlobObject(); ib.GetBufferData(rc, blob); unsafe { if (ib.Desc.Type == EIndexBufferType.IBT_Int16) { int indexNum = (int)blob.Size / (sizeof(UInt16)); var ptr = (UInt16 *)blob.Data.ToPointer(); for (int i = 0; i < indexNum; i++) { OriIndices.Add(ptr[i]); } } else { int indexNum = (int)blob.Size / (sizeof(int)); var ptr = (int *)blob.Data.ToPointer(); for (int i = 0; i < indexNum; i++) { OriIndices.Add(ptr[i]); } } } } #endregion #region Mtl Faces.Clear(); Atoms = new List <MeshAtom>(); for (UInt32 i = 0; i < mesh.AtomNumber; i++) { var atom = new MeshAtom(); atom.Mtl = (int)i; mesh.GetAtom(i, 0, ref atom.OriginDesc); Atoms.Add(atom); int index = (int)atom.OriginDesc.StartIndex / 3; for (int j = 0; j < atom.OriginDesc.NumPrimitives; j++) { var f = new Face(); f.A = OriIndices[(int)atom.OriginDesc.StartIndex + j * 3 + 0]; f.B = OriIndices[(int)atom.OriginDesc.StartIndex + j * 3 + 1]; f.C = OriIndices[(int)atom.OriginDesc.StartIndex + j * 3 + 2]; f.Mtl = (int)i; atom.Faces.Add(Faces.Count); Faces.Add(f); } } #endregion BuildFixedVertices(0.000001f); BuildFaces(); BuildEdges(); BuildLinkers(); for (int i = 0; i < Atoms.Count; i++) { Atoms[i].FaceLods.Clear(); Atoms[i].FaceLods.Add(Atoms[i].Faces); } return(true); }
public override async Task <bool> Init(CRenderContext RHICtx, uint width, uint height, CGfxCamera camera, IntPtr WinHandle) { await Thread.AsyncDummyClass.DummyFunc(); mViewWidth = width; mViewHeight = height; var viewInfo = new View.CGfxSceneViewInfo(); viewInfo.mUseDSV = true; viewInfo.Width = width; viewInfo.Height = height; viewInfo.mDSVDesc.Init(); viewInfo.mDSVDesc.Format = EPixelFormat.PXF_D24_UNORM_S8_UINT; viewInfo.mDSVDesc.Width = width; viewInfo.mDSVDesc.Height = height; var rtDesc = new CRenderTargetViewDesc(); rtDesc.Init(); rtDesc.Format = EPixelFormat.PXF_R8G8B8A8_UNORM;// .PXF_R32_UINT; rtDesc.Width = width; rtDesc.Height = height; viewInfo.mRTVDescArray.Add(rtDesc); viewInfo.mRTVDescArray.Add(rtDesc); mCaptureSV = new View.CGfxSceneView(); if (false == mCaptureSV.Init(RHICtx, null, viewInfo)) { return(false); } mRenderPassDesc_SceneCapture = new CRenderPassDesc(); FrameBufferClearColor TempClearColor0 = new FrameBufferClearColor(); TempClearColor0.r = 1.0f; TempClearColor0.g = 1.0f; TempClearColor0.b = 1.0f; TempClearColor0.a = 1.0f; FrameBufferClearColor TempClearColor1 = new FrameBufferClearColor(); TempClearColor1.r = 0.0f; TempClearColor1.g = 0.0f; TempClearColor1.b = 0.0f; TempClearColor1.a = 0.0f; mRenderPassDesc_SceneCapture.mFBLoadAction_Color = FrameBufferLoadAction.LoadActionClear; mRenderPassDesc_SceneCapture.mFBStoreAction_Color = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_SceneCapture.mFBClearColorRT0 = TempClearColor0; mRenderPassDesc_SceneCapture.mFBClearColorRT1 = TempClearColor1; mRenderPassDesc_SceneCapture.mFBLoadAction_Depth = FrameBufferLoadAction.LoadActionClear; mRenderPassDesc_SceneCapture.mFBStoreAction_Depth = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_SceneCapture.mDepthClearValue = 1.0f; mRenderPassDesc_SceneCapture.mFBLoadAction_Stencil = FrameBufferLoadAction.LoadActionClear; mRenderPassDesc_SceneCapture.mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_SceneCapture.mStencilClearValue = 0u; Camera = camera; if (mCaptureSE == null) { mCaptureSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <EnvShader.CGfxSceneCaptureSE>(); } mTexData0 = new Support.CBlobObject(); mTexData1 = new Support.CBlobObject(); return(true); }
public void LoadTexture(string name, Support.CBlobObject blob) { SDK_ImageImport_LoadTexture(CoreObject, name, blob.CoreObject); }
public void AddDefaultColorBuff(CRenderContext rc, CGfxMeshPrimitives result) { if (result == null) { return; } var mesh = result.GeometryMesh; if (mesh == null) { return; } CVertexBuffer colorbuff = mesh.GetVertexBuffer(EVertexSteamType.VST_Color); if (colorbuff != null) { return; } CVertexBuffer posbuff = mesh.GetVertexBuffer(EVertexSteamType.VST_Position); if (posbuff == null) { return; } var blob = new Support.CBlobObject(); posbuff.GetBufferData(rc, blob); int vertNum = 0; unsafe { vertNum = (int)blob.Size / sizeof(Vector3); } if (vertNum == 0) { return; } Support.NativeList <Byte4> Colors = new Support.NativeList <Byte4>(); var color = new Byte4(); color.X = 255; color.Y = 255; color.Z = 255; color.W = 255; for (int i = 0; i < vertNum; i++) { Colors.Add(color); } var dpDesc = new CDrawPrimitiveDesc(); dpDesc.SetDefault(); dpDesc.NumPrimitives = (UInt32)vertNum; result.SetAtom(0, 0, ref dpDesc); UInt32 resourceSize = 0; unsafe { var vbDesc = new CVertexBufferDesc(); vbDesc.CPUAccess = (UInt32)ECpuAccess.CAS_WRITE; { vbDesc.InitData = Colors.UnsafeAddressAt(0); vbDesc.Stride = (UInt32)sizeof(Byte4); vbDesc.ByteWidth = (UInt32)(sizeof(Byte4) * Colors.Count); var vb = rc.CreateVertexBuffer(vbDesc); mesh.BindVertexBuffer(EVertexSteamType.VST_Color, vb); resourceSize += vbDesc.ByteWidth; } result.ResourceState.ResourceSize = (UInt32)(resourceSize); mesh.Dirty = true; } result.ResourceState.StreamState = EStreamingState.SS_Valid; result.ResourceState.KeepValid = true; }