public void Update(DX11RenderContext context)
        {
            if (this.FInvalidate || !this.FOutGeom[0].Contains(context))
            {
                int vertexoffset = 0;

                List <Pos3Norm3Tex2InstanceVertex> vertices = new List <Pos3Norm3Tex2InstanceVertex>();
                List <int>     indices = new List <int>();
                List <Vector2> uvs     = new List <Vector2>();

                int cnt = this.FinUseName[0] ? idsort.Count : this.FInScene[0].MeshCount;

                for (int i = 0; i < cnt; i++)
                {
                    AssimpMesh assimpmesh = this.FinUseName[0] == false ? this.FInScene[0].Meshes[i] : this.FInScene[0].Meshes[idsort[i]];

                    List <int> inds = assimpmesh.Indices;



                    if (inds.Count > 0 && assimpmesh.VerticesCount > 0)
                    {
                        var  texcd = assimpmesh.GetInputElements().Where(ie => ie.SemanticName == "TEXCOORD").FirstOrDefault();
                        bool zuv   = false;
                        if (texcd != null)
                        {
                            zuv = texcd.Format == SlimDX.DXGI.Format.R32G32B32_Float;
                        }
                        for (int j = 0; j < inds.Count; j++)
                        {
                            indices.Add(inds[j] + vertexoffset);
                        }

                        DataStream posbuffer  = new DataStream(assimpmesh.PositionPointer, assimpmesh.VerticesCount * 12, true, true);
                        DataStream normbuffer = new DataStream(assimpmesh.NormalsPointer, assimpmesh.VerticesCount * 12, true, true);
                        DataStream uvbuffer   = null;

                        List <DataStream> uvbuffers  = new List <DataStream>();
                        List <int>        uvcounters = new List <int>();

                        for (int uvc = 0; uvc < assimpmesh.UvChannelCount; uvc++)
                        {
                            uvbuffers.Add(new DataStream(assimpmesh.GetUvPointer(uvc), assimpmesh.VerticesCount * 12, true, true));
                            uvcounters.Add(this.GetUVChannelCount(assimpmesh, uvc));
                        }

                        if (assimpmesh.UvChannelCount > 0)
                        {
                            uvbuffer = new DataStream(assimpmesh.GetUvPointer(0), assimpmesh.VerticesCount * 12, true, true);
                        }

                        Vector3 *pos   = (Vector3 *)posbuffer.DataPointer.ToPointer();
                        Vector3  accum = Vector3.Zero;
                        for (int j = 0; j < assimpmesh.VerticesCount; j++)
                        {
                            accum += pos[j];
                        }
                        Vector3 center = accum / assimpmesh.VerticesCount;

                        for (int j = 0; j < assimpmesh.VerticesCount; j++)
                        {
                            Pos3Norm3Tex2InstanceVertex vert = new Pos3Norm3Tex2InstanceVertex()
                            {
                                InstanceID = i,
                                Normals    = normbuffer.Read <Vector3>(),
                                Position   = posbuffer.Read <Vector3>(),
                                Center     = center,
                                TexCoords  = uvbuffer != null?uvbuffer.Read <Vector2>() : Vector2.Zero
                            };
                            vertices.Add(vert);

                            for (int k = 0; k < assimpmesh.UvChannelCount; k++)
                            {
                                var b = uvbuffers[k];
                                uvs.Add(b.Read <Vector2>());

                                if (uvcounters[k] == 3)
                                {
                                    b.Read <float>();
                                }
                            }

                            if (uvbuffer != null && zuv)
                            {
                                uvbuffer.Read <float>();
                            }
                        }
                        vertexoffset += assimpmesh.VerticesCount;
                    }
                }

                DataStream vS = new DataStream(vertices.ToArray(), true, true);
                vS.Position = 0;

                DataStream iS = new DataStream(indices.ToArray(), true, true);
                iS.Position = 0;

                var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, vS, new BufferDescription()
                {
                    BindFlags      = BindFlags.VertexBuffer,
                    CpuAccessFlags = CpuAccessFlags.None,
                    OptionFlags    = ResourceOptionFlags.None,
                    SizeInBytes    = (int)vS.Length,
                    Usage          = ResourceUsage.Default
                });


                DX11IndexedGeometry geom = new DX11IndexedGeometry(context);
                geom.VertexBuffer   = vbuffer;
                geom.IndexBuffer    = new DX11IndexBuffer(context, iS, true, false);
                geom.InputLayout    = Pos3Norm3Tex2InstanceVertex.Layout;
                geom.Topology       = PrimitiveTopology.TriangleList;
                geom.VerticesCount  = vertices.Count;
                geom.VertexSize     = Pos3Norm3Tex2InstanceVertex.VertexSize;
                geom.HasBoundingBox = false;

                vS.Position = 0;

                DataStream uvS = new DataStream(uvs.ToArray(), true, true);
                uvS.Position = 0;

                this.FOutGeom[0][context]     = geom;
                this.FOutBuffer[0][context]   = new DX11ImmutableStructuredBuffer(context.Device, geom.VerticesCount, geom.VertexSize, vS);
                this.FOutIndices[0][context]  = new DX11RawBuffer(context, geom.IndexBuffer.Buffer);
                this.FOutUVBuffer[0][context] = new DX11ImmutableStructuredBuffer(context.Device, uvs.Count, 8, uvS);

                this.FInvalidate = false;
            }
        }
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            if (this.FInvalidate || !this.FOutGeom[0].Contains(context))
            {
                int vertexoffset = 0;

                List<Pos3Norm3Tex2InstanceVertex> vertices = new List<Pos3Norm3Tex2InstanceVertex>();
                List<int> indices = new List<int>();
                List<Vector2> uvs = new List<Vector2>();

                int cnt = this.FinUseName[0] ? idsort.Count : this.FInScene[0].MeshCount;

                for (int i = 0; i < cnt; i++)
                {
                    AssimpMesh assimpmesh = this.FinUseName[0] == false ? this.FInScene[0].Meshes[i] : this.FInScene[0].Meshes[idsort[i]];

                    List<int> inds = assimpmesh.Indices;

                    if (inds.Count > 0 && assimpmesh.VerticesCount > 0)
                    {
                        var texcd = assimpmesh.GetInputElements().Where( ie => ie.SemanticName == "TEXCOORD").FirstOrDefault();
                        bool zuv = false;
                        if (texcd != null)
                        {
                            zuv = texcd.Format == SlimDX.DXGI.Format.R32G32B32_Float;
                        }
                        for (int j = 0; j < inds.Count; j++)
                        {
                            indices.Add(inds[j] + vertexoffset);
                        }

                        DataStream posbuffer = new DataStream(assimpmesh.PositionPointer, assimpmesh.VerticesCount * 12, true, true);
                        DataStream normbuffer = new DataStream(assimpmesh.NormalsPointer, assimpmesh.VerticesCount * 12, true, true);
                        DataStream uvbuffer = null;

                        List<DataStream> uvbuffers = new List<DataStream>();
                        List<int> uvcounters = new List<int>();

                        for (int uvc = 0; uvc < assimpmesh.UvChannelCount;uvc++ )
                        {
                            uvbuffers.Add(new DataStream(assimpmesh.GetUvPointer(uvc), assimpmesh.VerticesCount * 12, true, true));
                            uvcounters.Add(this.GetUVChannelCount(assimpmesh, uvc));
                        }

                        if (assimpmesh.UvChannelCount > 0)
                        {
                            uvbuffer = new DataStream(assimpmesh.GetUvPointer(0), assimpmesh.VerticesCount * 12, true, true);
                        }

                        Vector3* pos = (Vector3*)posbuffer.DataPointer.ToPointer();
                        Vector3 accum = Vector3.Zero;
                        for (int j = 0; j < assimpmesh.VerticesCount; j++)
                        {
                            accum += pos[j];
                        }
                        Vector3 center = accum / assimpmesh.VerticesCount;

                        for (int j = 0; j < assimpmesh.VerticesCount; j++)
                        {
                            Pos3Norm3Tex2InstanceVertex vert = new Pos3Norm3Tex2InstanceVertex()
                            {
                                InstanceID = i,
                                Normals = normbuffer.Read<Vector3>(),
                                Position = posbuffer.Read<Vector3>(),
                                Center = center,
                                TexCoords = uvbuffer != null ? uvbuffer.Read<Vector2>() : Vector2.Zero
                            };
                            vertices.Add(vert);

                            for (int k = 0; k < assimpmesh.UvChannelCount; k++ )
                            {
                                var b = uvbuffers[k];
                                uvs.Add(b.Read<Vector2>());

                                if (uvcounters[k] == 3)
                                {
                                    b.Read<float>();
                                }

                            }

                            if (uvbuffer != null && zuv) { uvbuffer.Read<float>(); }
                        }
                        vertexoffset += assimpmesh.VerticesCount;
                    }
                }

                DataStream vS = new DataStream(vertices.ToArray(), true, true);
                vS.Position = 0;

                DataStream iS = new DataStream(indices.ToArray(), true, true);
                iS.Position = 0;

                var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, vS, new BufferDescription()
                {
                    BindFlags = BindFlags.VertexBuffer,
                    CpuAccessFlags = CpuAccessFlags.None,
                    OptionFlags = ResourceOptionFlags.None,
                    SizeInBytes = (int)vS.Length,
                    Usage = ResourceUsage.Default
                });

                DX11IndexedGeometry geom = new DX11IndexedGeometry(context);
                geom.VertexBuffer = vbuffer;
                geom.IndexBuffer = new DX11IndexBuffer(context, iS, true, false);
                geom.InputLayout = Pos3Norm3Tex2InstanceVertex.Layout;
                geom.Topology = PrimitiveTopology.TriangleList;
                geom.VerticesCount = vertices.Count;
                geom.VertexSize = Pos3Norm3Tex2InstanceVertex.VertexSize;
                geom.HasBoundingBox = false;

                vS.Position = 0;

                DataStream uvS = new DataStream(uvs.ToArray(), true, true);
                uvS.Position = 0;

                this.FOutGeom[0][context] = geom;
                this.FOutBuffer[0][context] = new DX11ImmutableStructuredBuffer(context.Device, geom.VerticesCount, geom.VertexSize, vS);
                this.FOutIndices[0][context] = new DX11RawBuffer(context, geom.IndexBuffer.Buffer);
                this.FOutUVBuffer[0][context] = new DX11ImmutableStructuredBuffer(context.Device,uvs.Count,8,uvS);

                this.FInvalidate = false;

            }
        }