예제 #1
0
        public void UpdateResource(IPluginOut ForPin, Device OnDevice)
        {
            if (this.FInvalidate || !this.FMeshes.ContainsKey(OnDevice))
            {
                //Destroy old mesh
                DestroyResource(ForPin, OnDevice, false);

                if (this.FInScene[0] == null)
                {
                    return;
                }

                List <Mesh> meshes = new List <Mesh>();

                for (int i = 0; i < this.FInScene[0].MeshCount; i++)
                {
                    AssimpMesh assimpmesh = this.FInScene[0].Meshes[i];
                    Mesh       mesh       = new Mesh(OnDevice, assimpmesh.Indices.Count / 3, assimpmesh.VerticesCount, MeshFlags.Dynamic | MeshFlags.Use32Bit, assimpmesh.GetVertexBinding().ToArray());
                    DataStream vS         = mesh.LockVertexBuffer(LockFlags.Discard);
                    DataStream iS         = mesh.LockIndexBuffer(LockFlags.Discard);
                    assimpmesh.Write(vS);
                    iS.WriteRange(assimpmesh.Indices.ToArray());

                    mesh.UnlockVertexBuffer();
                    mesh.UnlockIndexBuffer();

                    meshes.Add(mesh);
                }


                try
                {
                    Mesh merge = null;
                    if (OnDevice is DeviceEx)
                    {
                        merge = Mesh.Concatenate(OnDevice, meshes.ToArray(), MeshFlags.Use32Bit);
                    }
                    else
                    {
                        merge = Mesh.Concatenate(OnDevice, meshes.ToArray(), MeshFlags.Use32Bit | MeshFlags.Managed);
                    }
                    this.FMeshes.Add(OnDevice, merge);
                }
                catch (Exception ex)
                {
                }
                foreach (Mesh m in meshes)
                {
                    m.Dispose();
                }
            }
        }