Three.js - проблема с наложением текстуры на пользовательскую геометрию
Здравствуйте. С наложением текстуры на стандартную геометрию проблем нет, например:
var texture = THREE.ImageUtils.loadTexture('wood.jpg');
var cube = new THREE.Mesh(
new THREE.CubeGeometry(100, 100, 100),
new THREE.MeshLambertMaterial( {map: texture} )
);
scene.add(cube);
Но не работает с геометрией, которую сам написал:
var mesh = new THREE.Mesh(
new lxRingGeometry(200, 100, 20, Math.PI, 10),
new THREE.MeshLambertMaterial( {map: texture} )
);
scene.add(mesh);
Код геометрии, на всякий случай:
function lxRingGeometry(r, width, height, angle, sectors) {
var step = angle / sectors;
var innerR = r - width;
var vertices = [];
for (var i=0; i<sectors+1; i++) {
vertices.push( new THREE.Vector3(innerR * Math.cos(i * step), height/2, innerR * Math.sin(i * step)) );
vertices.push( new THREE.Vector3(innerR * Math.cos(i * step), -height/2, innerR * Math.sin(i * step)) );
vertices.push( new THREE.Vector3(r * Math.cos(i * step), height/2, r * Math.sin(i * step)) );
vertices.push( new THREE.Vector3(r * Math.cos(i * step), -height/2, r * Math.sin(i * step)) );
}
var faces = [];
for (var i=0; i<sectors*4; i+=4) {
faces.push( new THREE.Face3(i, i+1, i+5) );
faces.push( new THREE.Face3(i, i+5, i+4) );
faces.push( new THREE.Face3(i+2, i+7, i+3) );
faces.push( new THREE.Face3(i+2, i+6, i+7) );
faces.push( new THREE.Face3(i, i+6, i+2) );
faces.push( new THREE.Face3(i, i+4, i+6) );
faces.push( new THREE.Face3(i+1, i+3, i+7) );
faces.push( new THREE.Face3(i+1, i+7, i+5) );
}
var geom = new THREE.Geometry();
geom.vertices = vertices;
geom.faces = faces;
geom.mergeVertices();
geom.computeFaceNormals();
return geom;
}
|