threex.videotexture
Version:
three.js helper to display video texture
178 lines (158 loc) • 4.88 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
var initVideotexture = __webpack_require__(1);
var initWebcamtexture = __webpack_require__(2);
module.exports = function(THREE, THREEx={}) {
initVideotexture(THREE, THREEx);
initWebcamtexture(THREE, THREEx);
return THREEx;
}
/***/ }),
/* 1 */
/***/ (function(module, exports) {
module.exports = function(THREE, THREEx) {
THREEx.VideoTexture = function(url){
// create the video element
var video = document.createElement('video');
video.width = 320;
video.height = 240;
video.autoplay = true;
video.loop = true;
video.src = url;
// expose video as this.video
this.video = video
// create the texture
var texture = new THREE.Texture( video );
// expose texture as this.texture
this.texture = texture
/**
* update the object
*/
this.update = function(){
if( video.readyState !== video.HAVE_ENOUGH_DATA ) return;
texture.needsUpdate = true;
}
/**
* destroy the object
*/
this.destroy = function(){
video.pause()
}
}
}
/***/ }),
/* 2 */
/***/ (function(module, exports) {
module.exports = function(THREE, THREEx) {
THREEx.WebcamTexture = function(){
console.assert(THREEx.WebcamTexture.available === true)
// create the video element
var video = document.createElement('video');
video.width = 320;
video.height = 240;
video.autoplay = true;
video.loop = true;
// expose video as this.video
this.video = video
if( navigator.webkitGetUserMedia ){
navigator.webkitGetUserMedia({video:true}, function(stream){
video.src = URL.createObjectURL(stream);
}, function(error){
alert('you got no WebRTC webcam');
});
}else if(navigator.mozGetUserMedia){
navigator.mozGetUserMedia({video:true}, function(stream){
video.src = URL.createObjectURL(stream);
}, function(error){
alert('you got no WebRTC webcam');
});
}else console.assert(false)
// create the texture
var texture = new THREE.Texture( video );
// expose texture as this.texture
this.texture = texture
/**
* update the object
*/
this.update = function(delta, now){
if( video.readyState !== video.HAVE_ENOUGH_DATA ) return;
texture.needsUpdate = true;
}
/**
* destroy the object
*/
this.destroy = function(){
video.pause()
}
}
THREEx.WebcamTexture.available = navigator.webkitGetUserMedia || navigator.mozGetUserMedia ? true : false;
}
/***/ })
/******/ ]);