我想知道是否有可能获得纹理的尺寸?我用这行来设置我的纹理:
const texture = THREE.ImageUtils.loadTexture(src)
也许有必要加载图像来获得它的尺寸(但是只有javascript,而不是html和它的div?)?
我想我之后创建的材质适合纹理尺寸。
首先,THREE.ImageUtils.loadTexture
在最新的THREE.js(r90)中被弃用。请看看THREE.TextureLoader
。
也就是说,您可以从加载的纹理中获取图像及其属性。
texture.image
根据图像格式,您应该能够访问width
/ height
属性,这将是纹理的尺寸。
请注意:加载纹理是异步的,因此您需要定义onLoad
回调。
var loader = new THREE.TextureLoader();
var texture = loader.load( "./img.png", function ( tex ) {
// tex and texture are the same in this example, but that might not always be the case
console.log( tex.image.width, tex.image.height );
console.log( texture.image.width, texture.image.height );
} );