我找不到具有紋理座標的THREE.BufferGeometry示例。它應該用於紋理網格嗎?我無法讓它工作。這裏是我的測試代碼:three.js:具有紋理座標的BufferGeometry
var quad_vertices =
[
-30.0, 30.0, 0.0,
30.0, 30.0, 0.0,
30.0, -30.0, 0.0,
-30.0, -30.0, 0.0
];
var quad_uvs =
[
0.0, 0.0,
1.0, 0.0,
1.0, 1.0,
0.0, 1.0
];
var quad_indices =
[
0, 2, 1, 0, 3, 2
];
var geometry = new THREE.BufferGeometry();
geometry.attributes =
{
position:
{
itemSize: 3,
array: new Float32Array(3 * 4)
},
uv:
{
itemSize: 2,
array: new Float32Array(2 * 4)
},
index:
{
itemSize: 1,
array: new Uint16Array(6)
}
};
var positions = geometry.attributes.position.array;
var uvs = geometry.attributes.uv.array;
var indices = geometry.attributes.index.array;
var i;
for(i = 0; i < positions.length; i += 3)
{
positions[i] = quad_vertices[i];
positions[i + 1] = quad_vertices[i + 1];
positions[i + 2] = quad_vertices[i + 2];
}
for(i = 0; i < uvs.length; i += 2)
{
uvs[i] = quad_uvs[i];
uvs[i + 1] = quad_uvs[i + 1];
}
for(i = 0; i < indices.length; i++)
indices[i] = quad_indices[i];
var texture = THREE.ImageUtils.loadTexture('./assets/texture.png');
texture.anisotropy = renderer.getMaxAnisotropy();
var material = new THREE.MeshBasicMaterial({ map: texture });
var mesh = new THREE.Mesh(geometry, material);
mesh.position.z = -100;
scene.add(mesh);
只是用THREE.Geometry創建網格是好的,所以我不知道這段代碼可能會出現什麼問題。有什麼想法嗎?
看'THREE.BufferGeometryUtils.fromGeometry(幾何形狀,設置)'。另外,quad.js不再支持四邊形。更新至r.61。 – WestLangley
我不必從Geometry創建BufferGeometry,對吧?所以這只不過是一種解決方法。另外我不使用three.js四邊形。 – user2904567
你不這樣做,但是如果你使用了這個函數一次,你至少會看到'BufferGeometry'是如何創建的。 – WestLangley