如何在 `THREE.js` 当前版本中转换 `geometry.faceVertexUvs`?
How to convert `geometry.faceVertexUvs` in `THREE.js` current version?
const geometry = new THREE.SphereGeometry(100, 64, 64, Math.PI / 2, Math.PI, 0, Math.PI);
const uvs = geometry.faceVertexUvs[0];
const axis = 'x';
for (let i = 0; i < uvs.length; i += 1) {
for (let j = 0; j < 3; j += 1) {
uvs[i][j][axis] *= 0.5;
}
}
geometry.faceVertexUvs 已折旧。
如何将此引用转换为 THREE.js
当前版本?
新方法使用 BufferGeometry
而不是 Geometry
。这将每个顶点属性(位置、法线、uv)存储在数组中,因此您可以使用 BufferGeometry.getAttribute("uv");
.
获取 UV
检索属性后,您将得到一个 BufferAttribute
,您可以在其中访问每个单独组件的 .array
属性:
const geometry = new THREE.SphereGeometry(100, 64, 64, Math.PI / 2, Math.PI, 0, Math.PI);
const uvAttribute = geometry.getAttribute("uv");
const uvArray = uvAttribute.array;
// Loop through all UVs
// UVs have 2 components, so we jump by 2 on each iteration
for (let i = 0; i < uvAttribute.length; i += 2) {
uvArray[i + 0] = uvX;
uvArray[i + 1] = uvY;
}
// Now we set the update flag to true so the GPU gets the new values
uvAttribute.needsUpdate = true;
const geometry = new THREE.SphereGeometry(100, 64, 64, Math.PI / 2, Math.PI, 0, Math.PI);
const uvs = geometry.faceVertexUvs[0];
const axis = 'x';
for (let i = 0; i < uvs.length; i += 1) {
for (let j = 0; j < 3; j += 1) {
uvs[i][j][axis] *= 0.5;
}
}
geometry.faceVertexUvs 已折旧。
如何将此引用转换为 THREE.js
当前版本?
新方法使用 BufferGeometry
而不是 Geometry
。这将每个顶点属性(位置、法线、uv)存储在数组中,因此您可以使用 BufferGeometry.getAttribute("uv");
.
检索属性后,您将得到一个 BufferAttribute
,您可以在其中访问每个单独组件的 .array
属性:
const geometry = new THREE.SphereGeometry(100, 64, 64, Math.PI / 2, Math.PI, 0, Math.PI);
const uvAttribute = geometry.getAttribute("uv");
const uvArray = uvAttribute.array;
// Loop through all UVs
// UVs have 2 components, so we jump by 2 on each iteration
for (let i = 0; i < uvAttribute.length; i += 2) {
uvArray[i + 0] = uvX;
uvArray[i + 1] = uvY;
}
// Now we set the update flag to true so the GPU gets the new values
uvAttribute.needsUpdate = true;