public void Update(DX11RenderContext context)
        {
            if (this.FInvalidate || this.FEmpty)
            {
                for (int i = 0; i < this.scenes.Count; i++)
                {
                    if (scenes[i] != null)
                    {
                        AssimpScene scene = scenes[i];

                        for (int j = 0; j < scene.MeshCount; j++)
                        {
                            AssimpMesh assimpmesh = scene.Meshes[j];


                            DataStream vS = assimpmesh.Vertices;
                            vS.Position = 0;

                            List <int> inds = assimpmesh.Indices;

                            if (inds.Count > 0 && assimpmesh.VerticesCount > 0)
                            {
                                var vertices = 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
                                });

                                var indexstream = new DataStream(inds.Count * 4, true, true);
                                indexstream.WriteRange(inds.ToArray());
                                indexstream.Position = 0;


                                DX11IndexedGeometry geom = new DX11IndexedGeometry(context);
                                geom.VertexBuffer   = vertices;
                                geom.IndexBuffer    = new DX11IndexBuffer(context, indexstream, false, true);
                                geom.InputLayout    = assimpmesh.GetInputElements().ToArray();
                                geom.Topology       = PrimitiveTopology.TriangleList;
                                geom.VerticesCount  = assimpmesh.VerticesCount;
                                geom.VertexSize     = assimpmesh.CalculateVertexSize();
                                geom.HasBoundingBox = true;
                                geom.BoundingBox    = assimpmesh.BoundingBox;

                                this.FOutGeom[i][j][context] = geom;
                            }
                        }
                    }
                }
                this.FEmpty      = false;
                this.FInvalidate = false;
            }
        }
        private int GetUVChannelCount(AssimpMesh assimpmesh, int slot)
        {
            var texcd = assimpmesh.GetInputElements().Where(ie => ie.SemanticName == "TEXCOORD" && ie.SemanticIndex == slot).FirstOrDefault();
            int cnt   = 2;

            if (texcd != null)
            {
                if (texcd.Format == SlimDX.DXGI.Format.R32G32B32_Float)
                {
                    cnt = 3;
                }
            }
            return(cnt);
        }
        private int GetChannelCount(AssimpMesh mesh, int slot)
        {
            var fmt = mesh.GetInputElements().Where(ie => ie.SemanticName == "TEXCOORD" && ie.SemanticIndex == slot).First();

            switch (fmt.Format)
            {
            case SlimDX.DXGI.Format.R32_Float:
                return(1);

            case SlimDX.DXGI.Format.R32G32_Float:
                return(2);

            case SlimDX.DXGI.Format.R32G32B32_Float:
                return(3);

            case SlimDX.DXGI.Format.R32G32B32A32_Float:
                return(4);

            default:
                return(0);
            }
        }
        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;
            }
        }
        private int GetChannelCount(AssimpMesh mesh, int slot)
        {
            var fmt = mesh.GetInputElements().Where(ie => ie.SemanticName == "TEXCOORD" && ie.SemanticIndex == slot).First();

            switch(fmt.Format)
            {
                case SlimDX.DXGI.Format.R32_Float:
                    return 1;
                case SlimDX.DXGI.Format.R32G32_Float:
                    return 2;
                case SlimDX.DXGI.Format.R32G32B32_Float:
                    return 3;
                case SlimDX.DXGI.Format.R32G32B32A32_Float:
                    return 4;
                default :
                    return 0;
            }
        }
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            if (this.FInvalidate || this.FEmpty)
            {
                for (int i = 0; i < this.scenes.Count; i++)
                {
                    if (scenes[i] != null)
                    {
                        AssimpScene scene = scenes[i];

                        for (int j = 0; j < scene.MeshCount; j++)
                        {
                            AssimpMesh assimpmesh = scene.Meshes[j];

                            List <int> inds = assimpmesh.Indices;

                            if (inds.Count > 0 && assimpmesh.VerticesCount > 0)
                            {
                                var indexstream = new DataStream(inds.Count * 4, true, true);
                                indexstream.WriteRange(inds.ToArray());
                                indexstream.Position = 0;


                                DX11IndexOnlyGeometry geom = new DX11IndexOnlyGeometry(context);
                                geom.IndexBuffer    = new DX11IndexBuffer(context, indexstream, false, true);
                                geom.InputLayout    = assimpmesh.GetInputElements().ToArray();
                                geom.Topology       = PrimitiveTopology.TriangleList;
                                geom.HasBoundingBox = true;
                                geom.BoundingBox    = assimpmesh.BoundingBox;


                                DX11DynamicStructuredBuffer <Vector3> p =
                                    new DX11DynamicStructuredBuffer <Vector3>(context, assimpmesh.PositionPointer, assimpmesh.VerticesCount);

                                DX11DynamicStructuredBuffer <Vector3> n =
                                    new DX11DynamicStructuredBuffer <Vector3>(context, assimpmesh.NormalsPointer, assimpmesh.VerticesCount);

                                if (assimpmesh.UvChannelCount > 0)
                                {
                                    DX11DynamicStructuredBuffer <Vector3> u =
                                        new DX11DynamicStructuredBuffer <Vector3>(context, assimpmesh.GetUvPointer(0), assimpmesh.VerticesCount);


                                    this.FOutUvs[i][j][context] = u;
                                }



                                DX11RawBuffer rb = new DX11RawBuffer(context, geom.IndexBuffer.Buffer);

                                this.FOutPosition[i][j][context] = p;
                                this.FOutNormals[i][j][context]  = n;
                                this.FOutGeom[i][j][context]     = geom;
                                this.FOutIndices[i][j][context]  = rb;
                            }
                        }
                    }
                }
                this.FInvalidate = false;
                this.FEmpty      = false;
            }
        }
 private int GetUVChannelCount(AssimpMesh assimpmesh, int slot)
 {
     var texcd = assimpmesh.GetInputElements().Where(ie => ie.SemanticName == "TEXCOORD" && ie.SemanticIndex == slot).FirstOrDefault();
     int cnt = 2;
     if (texcd != null)
     {
         if (texcd.Format == SlimDX.DXGI.Format.R32G32B32_Float)
         {
             cnt = 3;
         }
     }
     return cnt;
 }