|
@@ -4,8 +4,8 @@
|
|
|
|
|
|
private _autoLaunch = true;
|
|
|
private _lastUpdate: number;
|
|
|
- private _generateMipMaps: boolean
|
|
|
-
|
|
|
+ private _generateMipMaps: boolean
|
|
|
+ private _setTextureReady: () => void;
|
|
|
/**
|
|
|
* Creates a video texture.
|
|
|
* Sample : https://doc.babylonjs.com/tutorials/01._Advanced_Texturing
|
|
@@ -58,17 +58,20 @@
|
|
|
|
|
|
this._lastUpdate = Tools.Now;
|
|
|
}
|
|
|
-
|
|
|
- private _createTexture(): void {
|
|
|
+
|
|
|
+ private __setTextureReady(): void {
|
|
|
+ this._texture.isReady = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private _createTexture(): void {
|
|
|
this._texture = this.getScene().getEngine().createDynamicTexture(this.video.videoWidth, this.video.videoHeight, this._generateMipMaps, this._samplingMode);
|
|
|
|
|
|
if (this._autoLaunch) {
|
|
|
this._autoLaunch = false;
|
|
|
this.video.play();
|
|
|
}
|
|
|
- this.video.addEventListener("playing", () => {
|
|
|
- this._texture.isReady = true;
|
|
|
- });
|
|
|
+ this._setTextureReady = this.__setTextureReady.bind(this);
|
|
|
+ this.video.addEventListener("playing", this._setTextureReady);
|
|
|
}
|
|
|
|
|
|
public update(): boolean {
|
|
@@ -81,20 +84,25 @@
|
|
|
this._lastUpdate = now;
|
|
|
this.getScene().getEngine().updateVideoTexture(this._texture, this.video, this._invertY);
|
|
|
return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public dispose(): void {
|
|
|
+ super.dispose();
|
|
|
+ this.video.removeEventListener("playing", this._setTextureReady);
|
|
|
}
|
|
|
|
|
|
- public static CreateFromWebCam(scene: Scene, onReady: (videoTexture: VideoTexture) => void, constraints: {
|
|
|
- minWidth: number,
|
|
|
- maxWidth: number,
|
|
|
- minHeight: number,
|
|
|
+ public static CreateFromWebCam(scene: Scene, onReady: (videoTexture: VideoTexture) => void, constraints: {
|
|
|
+ minWidth: number,
|
|
|
+ maxWidth: number,
|
|
|
+ minHeight: number,
|
|
|
maxHeight: number,
|
|
|
deviceId: string
|
|
|
}): void {
|
|
|
var video = document.createElement("video");
|
|
|
var constraintsDeviceId;
|
|
|
if (constraints && constraints.deviceId){
|
|
|
- constraintsDeviceId = {
|
|
|
- exact: constraints.deviceId
|
|
|
+ constraintsDeviceId = {
|
|
|
+ exact: constraints.deviceId
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -102,7 +110,7 @@
|
|
|
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
|
|
|
|
|
|
if (navigator.getUserMedia) {
|
|
|
- navigator.getUserMedia({
|
|
|
+ navigator.getUserMedia({
|
|
|
video: {
|
|
|
deviceId: constraintsDeviceId,
|
|
|
width: {
|
|
@@ -121,16 +129,16 @@
|
|
|
} else {
|
|
|
video.src = (window.URL && window.URL.createObjectURL(stream)) || stream;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
video.play();
|
|
|
|
|
|
if (onReady) {
|
|
|
onReady(new BABYLON.VideoTexture("video", video, scene, true, true));
|
|
|
}
|
|
|
}, function (e) {
|
|
|
- Tools.Error(e.name);
|
|
|
+ Tools.Error(e.name);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|