@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
61 lines (60 loc) • 1.66 kB
JavaScript
"use strict";
import { TypedContainer } from "./_Base";
import { isNumber } from "../../core/Type";
export class TextureContainer extends TypedContainer {
set_content(content) {
super.set_content(content);
}
texture() {
return this._content;
}
coreContent() {
return this._content;
}
coreContentCloned() {
var _a;
const texture = (_a = this._content) == null ? void 0 : _a.clone();
if (texture) {
texture.needsUpdate = true;
}
return texture;
}
object() {
return this.texture();
}
infos() {
if (this._content != null) {
return [this._content];
}
}
resolution() {
function _resolutionFromHTMLVideoElement(video) {
return [video.videoWidth, video.videoHeight];
}
if (this._content) {
const image = this._content.image;
if (image) {
if (image instanceof HTMLImageElement || image instanceof Image || image instanceof ImageData || image instanceof HTMLCanvasElement) {
return [image.width, image.height];
}
if (image instanceof HTMLVideoElement) {
return _resolutionFromHTMLVideoElement(image);
}
if (isNumber(image.width) && isNumber(image.height)) {
return [image.width, image.height];
}
}
const source = this._content.source;
if (source) {
if (source instanceof HTMLVideoElement) {
return _resolutionFromHTMLVideoElement(source);
}
const data = source.data;
if (data && isNumber(data.width) && isNumber(data.height)) {
return [data.width, data.height];
}
}
}
return [-1, -1];
}
}