コード例 #1
0
ファイル: GraphLines.cs プロジェクト: huangdonghai/titan3d
 public override void NextStartPoint(out Vector3 target)
 {
     unsafe
     {
         target = *((Vector3 *)Points.UnsafeAddressAt(Step).ToPointer());
     }
 }
コード例 #2
0
ファイル: TrailData.cs プロジェクト: huangdonghai/titan3d
        public void BindBuffs(CRenderContext rc, CGfxMeshPrimitives result)
        {
            if (Positions.Count < 4)
            {
                return;
            }

            CCommandList cmd = rc.ImmCommandList;

            var dpDesc = new CDrawPrimitiveDesc();

            dpDesc.SetDefault();
            dpDesc.NumPrimitives = (uint)Positions.Count - (ComposeCount * 2);
            result.SetAtom(0, 0, ref dpDesc);

            bool needcreate = Positions.Count > PrePositionCount || VertexIndexes.Count > PreIndexesCount;

            if (needcreate)
            {
                PrePositionCount = Positions.Count;
            }

            UInt32 resourceSize = 0;

            if (needcreate == false)
            {
                var    mesh      = result.GeometryMesh;
                UInt32 ByteWidth = 0;
                //mesh.Cleanup();
                {
                    var vb = mesh.GetVertexBuffer(EVertexSteamType.VST_Position);

                    unsafe
                    {
                        ByteWidth = (UInt32)(sizeof(Vector3) * Positions.Count);
                        vb.UpdateBuffData(cmd, Positions.UnsafeAddressAt(0), ByteWidth);
                        resourceSize += ByteWidth;
                    }
                }

                {
                    var vb = mesh.GetVertexBuffer(EVertexSteamType.VST_Tangent);

                    unsafe
                    {
                        ByteWidth = (UInt32)(sizeof(Vector4) * Tangents.Count);
                        vb.UpdateBuffData(cmd, Tangents.UnsafeAddressAt(0), ByteWidth);
                        resourceSize += ByteWidth;
                    }
                }

                {
                    var vb = mesh.GetVertexBuffer(EVertexSteamType.VST_Normal);

                    unsafe
                    {
                        ByteWidth = (UInt32)(sizeof(Vector3) * Normals.Count);
                        vb.UpdateBuffData(cmd, Normals.UnsafeAddressAt(0), ByteWidth);
                        resourceSize += ByteWidth;
                    }
                }

                {
                    var vb = mesh.GetVertexBuffer(EVertexSteamType.VST_UV);

                    unsafe
                    {
                        ByteWidth = (UInt32)(sizeof(Vector2) * UVs.Count);
                        vb.UpdateBuffData(cmd, UVs.UnsafeAddressAt(0), ByteWidth);
                        resourceSize += ByteWidth;
                    }
                }

                {
                    var vb = mesh.GetVertexBuffer(EVertexSteamType.VST_Color);

                    unsafe
                    {
                        ByteWidth = (UInt32)(sizeof(Byte4) * Colors.Count);
                        vb.UpdateBuffData(cmd, Colors.UnsafeAddressAt(0), ByteWidth);
                        resourceSize += ByteWidth;
                    }
                }

                {
                    //if (VertexIndexes.Count == PreIndexesCount)
                    //{
                    var ib = mesh.GetIndexBuffer();

                    unsafe
                    {
                        ByteWidth = (UInt32)(sizeof(UInt32) * VertexIndexes.Count);
                        ib.UpdateBuffData(cmd, VertexIndexes.UnsafeAddressAt(0), ByteWidth);
                        resourceSize += ByteWidth;
                    }
                    //}
                    //else
                    //{
                    //    var ibDesc = new CIndexBufferDesc();
                    //    ibDesc.CPUAccess = (UInt32)ECpuAccess.CAS_WRITE;
                    //    ibDesc.InitData = VertexIndexes.UnsafeAddressAt(0);
                    //    ibDesc.Type = EIndexBufferType.IBT_Int32;
                    //    ibDesc.ByteWidth = (UInt32)(sizeof(UInt32) * VertexIndexes.Count);
                    //    var ib = rc.CreateIndexBuffer(ibDesc);
                    //    mesh.BindIndexBuffer(ib);
                    //    resourceSize += ibDesc.ByteWidth;

                    //    PreIndexesCount = VertexIndexes.Count;
                    //}
                }

                result.ResourceState.ResourceSize = (UInt32)(resourceSize);
                result.ResourceState.StreamState  = EStreamingState.SS_Valid;
                result.ResourceState.KeepValid    = true;
                result.GeometryMesh.Dirty         = true;
                return;
            }

            //result.GeometryMesh.Cleanup();
            unsafe
            {
                var vbDesc = new CVertexBufferDesc();
                vbDesc.CPUAccess = (UInt32)ECpuAccess.CAS_WRITE;
                var mesh = result.GeometryMesh;
                //mesh.Cleanup();
                {
                    vbDesc.InitData  = Positions.UnsafeAddressAt(0);
                    vbDesc.Stride    = (UInt32)sizeof(Vector3);
                    vbDesc.ByteWidth = (UInt32)(sizeof(Vector3) * Positions.Count);
                    var vb = rc.CreateVertexBuffer(vbDesc);
                    mesh.BindVertexBuffer(EVertexSteamType.VST_Position, vb);
                    resourceSize += vbDesc.ByteWidth;
                }

                {
                    vbDesc.InitData  = Tangents.UnsafeAddressAt(0);
                    vbDesc.Stride    = (UInt32)sizeof(Vector4);
                    vbDesc.ByteWidth = (UInt32)(sizeof(Vector4) * Tangents.Count);
                    var vb = rc.CreateVertexBuffer(vbDesc);
                    mesh.BindVertexBuffer(EVertexSteamType.VST_Tangent, vb);
                    resourceSize += vbDesc.ByteWidth;
                }

                {
                    vbDesc.InitData  = Normals.UnsafeAddressAt(0);
                    vbDesc.Stride    = (UInt32)sizeof(Vector3);
                    vbDesc.ByteWidth = (UInt32)(sizeof(Vector3) * Normals.Count);
                    var vb = rc.CreateVertexBuffer(vbDesc);
                    mesh.BindVertexBuffer(EVertexSteamType.VST_Normal, vb);
                    resourceSize += vbDesc.ByteWidth;
                }

                {
                    vbDesc.InitData  = UVs.UnsafeAddressAt(0);
                    vbDesc.Stride    = (UInt32)sizeof(Vector2);
                    vbDesc.ByteWidth = (UInt32)(sizeof(Vector2) * UVs.Count);
                    var vb = rc.CreateVertexBuffer(vbDesc);
                    mesh.BindVertexBuffer(EVertexSteamType.VST_UV, vb);
                    resourceSize += vbDesc.ByteWidth;
                }

                {
                    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;
                }

                {
                    var ibDesc = new CIndexBufferDesc();
                    ibDesc.CPUAccess = (UInt32)ECpuAccess.CAS_WRITE;
                    ibDesc.InitData  = VertexIndexes.UnsafeAddressAt(0);
                    ibDesc.Type      = EIndexBufferType.IBT_Int32;
                    ibDesc.ByteWidth = (UInt32)(sizeof(UInt32) * VertexIndexes.Count);
                    var ib = rc.CreateIndexBuffer(ibDesc);
                    mesh.BindIndexBuffer(ib);
                    resourceSize   += ibDesc.ByteWidth;
                    PreIndexesCount = VertexIndexes.Count;
                }
                result.ResourceState.ResourceSize = (UInt32)(resourceSize);
                mesh.Dirty = true;
            }
            result.ResourceState.StreamState = EStreamingState.SS_Valid;
            result.ResourceState.KeepValid   = true;
        }
コード例 #3
0
ファイル: GraphLines.cs プロジェクト: huangdonghai/titan3d
        public void UpdateGeomMesh(CRenderContext rc, float halfWidth = 0.1F)
        {
            if (GeomMesh == null)
            {
                return;
            }

            CDrawPrimitiveDesc dpDesc = new CDrawPrimitiveDesc();

            dpDesc.SetDefault();

            if (UseGeometry)
            {
                mTempPosition.Clear();
                mTempUV.Clear();
                LinesGen.BuildGraph(mTempPosition, mTempUV, halfWidth);

                mTempNormal.Clear();
                mTempNormal.SetGrowStep(mTempPosition.Count);
                for (int i = 0; i < mTempPosition.Count; i++)
                {
                    //mTempNormal.Add(mTempPosition[i].CalcNormals());
                    unsafe
                    {
                        LinePosition tempNorm = new LinePosition();
                        var          ptr      = (LinePosition *)mTempPosition.UnsafeAddressAt(i).ToPointer();
                        ptr->CalcNormals(ref tempNorm);
                        mTempNormal.Add(tempNorm);
                    }
                }

                dpDesc.StartIndex = 0xFFFFFFFF;
                if (halfWidth == 0)
                {
                    dpDesc.PrimitiveType = EPrimitiveType.EPT_LineList;
                    dpDesc.NumPrimitives = (UInt32)(mTempPosition.Count * 3 * 3);
                }
                else
                {
                    dpDesc.NumPrimitives = (UInt32)(mTempPosition.Count * 3 * 2);
                }
                GeomMesh.SetAtom(0, 0, ref dpDesc);

                unsafe
                {
                    GeomMesh.SetGeomtryMeshStream(rc, EVertexSteamType.VST_Position, mTempPosition.GetBufferPtr(),
                                                  (UInt32)(sizeof(LinePosition) * mTempPosition.Count), (UInt32)sizeof(Vector3), 0);
                    GeomMesh.SetGeomtryMeshStream(rc, EVertexSteamType.VST_Normal, mTempNormal.GetBufferPtr(),
                                                  (UInt32)(sizeof(LinePosition) * mTempNormal.Count), (UInt32)sizeof(Vector3), 0);
                    GeomMesh.SetGeomtryMeshStream(rc, EVertexSteamType.VST_UV, mTempUV.GetBufferPtr(),
                                                  (UInt32)(sizeof(LineUV) * mTempUV.Count), (UInt32)sizeof(Vector2), 0);
                }
            }
            else
            {
                mTempPosition.Clear();
                mTempUV.Clear();
                LinesGen.BuildGraph(mTempPosition, mTempUV, halfWidth);

                mTempNormal.Clear();
                mTempNormal.SetGrowStep(mTempPosition.Count);
                for (int i = 0; i < mTempPosition.Count; i++)
                {
                    //mTempNormal.Add(mTempPosition[i].CalcNormals());
                    unsafe
                    {
                        LinePosition tempNorm = new LinePosition();
                        var          ptr      = (LinePosition *)mTempPosition.UnsafeAddressAt(i).ToPointer();
                        ptr->CalcNormals(ref tempNorm);
                        mTempNormal.Add(tempNorm);
                    }
                }

                dpDesc.StartIndex = 0xFFFFFFFF;
                if (halfWidth == 0)
                {
                    dpDesc.PrimitiveType = EPrimitiveType.EPT_LineList;
                    dpDesc.NumPrimitives = (UInt32)(mTempPosition.Count * 3);
                }
                else
                {
                    dpDesc.NumPrimitives = (UInt32)(mTempPosition.Count * 2);
                }
                GeomMesh.SetAtom(0, 0, ref dpDesc);

                unsafe
                {
                    GeomMesh.SetGeomtryMeshStream(rc, EVertexSteamType.VST_Position, mTempPosition.GetBufferPtr(),
                                                  (UInt32)(sizeof(LinePosition) * mTempPosition.Count), (UInt32)sizeof(Vector3), 0);
                    GeomMesh.SetGeomtryMeshStream(rc, EVertexSteamType.VST_Normal, mTempNormal.GetBufferPtr(),
                                                  (UInt32)(sizeof(LinePosition) * mTempNormal.Count), (UInt32)sizeof(Vector3), 0);
                    GeomMesh.SetGeomtryMeshStream(rc, EVertexSteamType.VST_UV, mTempUV.GetBufferPtr(),
                                                  (UInt32)(sizeof(LineUV) * mTempUV.Count), (UInt32)sizeof(Vector2), 0);
                }
            }

            GeomMesh.AABB = LinesGen.AABB;
            GeomMesh.GeometryMesh.Dirty = true;
        }
コード例 #4
0
        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;
        }