JsARtoolkit Alpha视频

时间:2017-03-02 14:33:06

标签: javascript video html5-video artoolkit jsartoolkit

我试着添加标记alpha视频o只是带有threejs和JSARtoolkit的视频,对象工作正常但是当我尝试使用.mov时,相机停止并且在控制台上没有错误。

我正在按照本教程添加视频 https://makc3d.wordpress.com/2014/04/01/transparent-video-texture-in-three-js/

脚本 - JS三。

meshes = [];
mixers = []; 
var hemisphereLight; 
var pointLight; 
var camera; var controls;
var clock = new THREE.Clock;
window.ARThreeOnLoad = function() {
ARController.getUserMediaThreeScene({maxARVideoSize: 320, cameraParam: 'Data/camera_para-iPhone 5 rear 640x480 1.0m.dat', 
onSuccess: function(arScene, arController, arCamera) {

    _arsc   = arScene;
    _arcon  = arController;
    _arcam  = arCamera;

    document.body.className = arController.orientation;

    var renderer = new THREE.WebGLRenderer({antialias: true});
    if (arController.orientation === 'portrait') {
        var w = (window.innerWidth / arController.videoHeight) * arController.videoWidth;
        var h = window.innerWidth + 100;
        renderer.setSize(w, h);
        renderer.domElement.style.paddingBottom = (w-h) + 'px';
    } else {
        if (/Android|mobile|iPad|iPhone/i.test(navigator.userAgent)) {
            renderer.setSize(window.innerWidth, (window.innerWidth / arController.videoWidth) * arController.videoHeight);
        } else {
            renderer.setSize(arController.videoWidth, arController.videoHeight);
            document.body.className += ' desktop';
        }
    }

    document.body.insertBefore(renderer.domElement, document.body.firstChild);

    var tick = function() {
        arScene.process();
        arScene.renderOn(renderer);
        requestAnimationFrame(tick);
    };
    tick();


ChromaKeyMaterial = function (url, width, height, keyColor) {
THREE.ShaderMaterial.call(this);

video = document.createElement('video');
video.loop = true;
video.src = url;
video.load();
video.play();

var videoImage = document.createElement('canvas');
if (window["webkitURL"]) document.body.appendChild(videoImage);
videoImage.width = width;
videoImage.height = height;

var keyColorObject = new THREE.Color(keyColor);

var videoImageContext = videoImage.getContext('2d');
// background color if no video present
videoImageContext.fillStyle = '#' + keyColorObject.getHexString();
videoImageContext.fillRect(0, 0, videoImage.width, videoImage.height);

var videoTexture = new THREE.Texture(videoImage);
videoTexture.minFilter = THREE.LinearFilter;
videoTexture.magFilter = THREE.LinearFilter;

this.update = function () {
    if (video.readyState === video.HAVE_ENOUGH_DATA) {
        videoImageContext.drawImage(video, 0, 0);
        if (videoTexture) {
            videoTexture.needsUpdate = true;
        }
    }
}

this.setValues({

    uniforms: {
        texture: {
            type: "t",
            value: videoTexture
        },
        color: {
            type: "c",
            value: keyColorObject
        }
    },
    vertexShader: document.getElementById('vertexShader').textContent,
    fragmentShader: document.getElementById('fragmentShader').textContent,

    transparent: true
});
}

ChromaKeyMaterial.prototype = Object.create(THREE.ShaderMaterial.prototype);



// var camera = new THREE.PerspectiveCamera();
// camera.position.set(0, 150, 900);
// camera.lookAt(scene.position);
// scene.add(camera);

renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setClearColor(0xffffff);
// document.getElementById('demo').appendChild(renderer.domElement);

// var controls = new THREE.OrbitControls(camera, renderer.domElement);



var movieMaterial = new ChromaKeyMaterial('video_video.mov', 242, 421, 0xd400);
var movieGeometry = new THREE.PlaneGeometry(60, 105, 4, 4);

var girls = []
for (var i = 0; i < 5; i++)
    for (var j = 0; j < 5; j++)
        if ((i + j) % 2 == 0) {
            var movie = new THREE.Mesh(movieGeometry, movieMaterial);
            movie.position.set(0, 53, 0);

            var girl = new THREE.Object3D();
            girl.position.set(150 * (i - 2), 0, 150 * (j - 2));

            girl.add(movie);
            arController.loadMarker('Data/patt.hiro', function(markerId) {
                markerRoot = arController.createThreeMarker(markerId);
                markerRoot.add(girl);
                // arScene.scene.add(camera);
                arScene.scene.add(markerRoot);
            });

            girls.push(girl);
        }


// animate
var animate = function () {
    // controls.update();

    movieMaterial.update();

    requestAnimationFrame(animate);
}

animate();
}});

delete window.ARThreeOnLoad;

};

if (window.ARController && ARController.getUserMediaThreeScene) {
ARThreeOnLoad();
}

1 个答案:

答案 0 :(得分:0)

.mov文件不允许用于Android设备,请使用mp4。透明度我使用Unity和Vuforia为移动设备制作了AR,资产是一个“特殊视频”和一个使用“亮度切割”的着色器。 Vuforia: it is possible play a Movie texture with alpha in iOS? 我也做了这个并在这篇文章中解释了它的处理:Video with alpha channel in Processing 希望它足够清楚,祝你好运!