首页 > 解决方案 > PIXI JS - 如何更新网格 UV?

问题描述

我想知道如何更新网格 UV。

初始化时,UV 似乎应用得很好。但如果这是动态修改的,UV 不会反映它。这是 PIXI JS 中的错误吗?还是我的错?

...
uvs: Float32Array = new Float32Array([ 0, 0, 1, 0, 1, 1, 0, 1 ]);
mesh: PIXI.mesh.Mesh = new PIXI.mesh.Mesh(texture, vertices, uvs, indices);

在运行时

this.mesh.uvs[2] += this.offset;
this.mesh.uvs[4] += this.offset;

不行。

标签: typescriptopengl-esmeshpixi.js

解决方案


PixiJS 提供给您的数据位于 CPU 上,但 GPU 渲染的网格使用 GPU 中的数据。

您只更新了 CPU 数据,为了使其对 GPU 可用,您必须增加 YourMesh.dirty 以便 PixiJS 知道数据已更改并且他需要更新 GPU 数据。

你应该有这样的东西:

this.mesh.uvs[2] += this.offset;
this.mesh.uvs[4] += this.offset;
this.mesh.dirty ++;

推荐阅读