我写了以下函数,目的是想创建面片,把图片作为面片的贴图放进场景里,现在想让面片能在图片加载成功后自动更新长宽,但是怎么都修改不了。我又不想异步创建面片...
function createPeace(img) {
var mesh,
geometry = new THREE.PlaneGeometry( 1, 1 );
var texture = new THREE.TextureLoader().load( "models/20nian.png" ,function (texture) {
//贴图加载成功后想修改之前创建的 geometry 的宽高,而不想修改
var i = texture.image;
geometry.parameters.width = i.naturalWidth/400;
geometry.parameters.height = 3;
console.log(geometry);
});
var material = new THREE.MeshBasicMaterial( {
color: 0xffff00,
side: THREE.DoubleSide,
map:texture
});
mesh = new THREE.Mesh( geometry, material );
mesh.lookAt(new THREE.Vector3(0,0,0));
return mesh;
}
忽然笑
相关分类