Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/textures/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,28 @@ class Source {

}

getSize( target ) {

const data = this.data;

if ( data instanceof HTMLVideoElement ) {

target.set( data.videoWidth, data.videoHeight );

} else if ( data !== null ) {

target.set( data.width, data.height, data.depth || 0 );

} else {

target.set( 0, 0, 0 );

}

return target;

}

/**
* When the property is set to `true`, the engine allocates the memory
* for the texture (if necessary) and triggers the actual texture upload
Expand Down
30 changes: 30 additions & 0 deletions src/textures/Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import {
} from '../constants.js';
import { generateUUID } from '../math/MathUtils.js';
import { Vector2 } from '../math/Vector2.js';
import { Vector3 } from '../math/Vector3.js';
import { Matrix3 } from '../math/Matrix3.js';
import { Source } from './Source.js';

let _textureId = 0;

const _tempVec3 = /*@__PURE__*/ new Vector3();

/**
* Base class for all textures.
*
Expand Down Expand Up @@ -358,6 +361,33 @@ class Texture extends EventDispatcher {

}

/**
* The width of the texture in pixels.
*/
get width() {

return this.source.getSize( _tempVec3 ).x;

}

/**
* The height of the texture in pixels.
*/
get height() {

return this.source.getSize( _tempVec3 ).y;

}

/**
* The depth of the texture in pixels.
*/
get depth() {

return this.source.getSize( _tempVec3 ).z;

}

/**
* The image object holding the texture data.
*
Expand Down