我正在尝试使用实时相机将THREE.ImageUtils.loadTextureCube()
应用到旋转立方体上。
到目前为止,我设法使用我的视频将简单纹理应用到MeshLambertMaterial
:
var geometry = new THREE.CubeGeometry(100, 100, 100, 10, 10, 10);
videoTexture = new THREE.Texture( Video ); // var "Video" is my <video> element
var material = new THREE.MeshLambertMaterial({ map: videoTexture });
Cube = new THREE.Mesh(geometry, material);
Scene.add( Cube );
没关系,你可以在http://jmpp.fr/three-camera
看到结果现在我想使用这个视频流来获得拉丝金属质感,所以我尝试创建另一种材质:
var videoSource = decodeURIComponent(Video.src);
var environment = THREE.ImageUtils.loadTextureCube([videoSource, // left
videoSource, // right
videoSource, // top
videoSource, // bottom
videoSource, // front
videoSource]); // back
var material = new THREE.MeshPhongMaterial({ envMap: environment });
...但它会引发以下错误:
blob:http://localhost/dad58cd1-1557-41dd-beed-dbfea4c340db 404 (Not Found)
我想loadTextureCube()正试图将6个数组参数作为图像,但似乎并不喜欢视频源。
我从三开始,想知道是否有办法做到这一点?
THX, JMPP
答案 0 :(得分:4)
我可以通过两种方式看到。首先,如果你只想要相同的图像,但有一些镜面高光/光泽,那么只需改变
var material = new THREE.MeshLambertMaterial({ map:texture});
到
var material = new THREE.MeshPhongMaterial({
map: texture ,
ambient: 0x030303,
specular: 0xffffff,
shininess: 90
});
并使用环境,镜面,光泽设置来查找您喜欢的内容。
其次,如果您真的想要为视频图像本身添加效果,可以将图像绘制到画布上,操纵像素,然后将纹理图像设置为该新图像。这也可以使用自定义着色器完成,避免画布步骤,但是已经存在用于将图像过滤器应用于元素的库,所以我坚持使用它。这将是这样的:
您需要使用画布绘制到<canvas id='testCanvas' width=256 height=256></canvas>
然后使用javascript
var ctx = document.getElementById('testCanvas').getContext('2d');
texture = new THREE.Texture();
// in the render loop
ctx.drawImage(Video,0,0);
var img = ctx.getImageData(0,0,c.width,c.height);
// do something with the img.data pixels, see
// this article http://www.html5rocks.com/en/tutorials/canvas/imagefilters/
// then write it back to the texture
texture.image = img;
texture.needsUpdate = true
实际上,您可以将其作为envMap来实现,您只需要强制视频为2的相同宽度/高度。视频以160x480的形式传输到chrome,因此您仍然需要绘制画布,但只能裁剪/调整图像。所以我得到了这个工作:
// In the access camera part
var canvas = document.createElement('canvas')
canvas.width = 512;
canvas.height = 512;
ctx = canvas.getContext('2d');
// In render loop
ctx.drawImage(Video,0,0, 512, 512);
img = ctx.getImageData(0,0,512,512);
// This part is a little different, but env maps have an array
// of images instead of just one
cubeVideo.image = [img,img,img,img,img,img];
if (Video.readyState === Video.HAVE_ENOUGH_DATA)
cubeVideo.needsUpdate = true;
答案 1 :(得分:1)
试试这个:
var environment = new THREE.Texture( [ Video, Video, Video, Video, Video, Video ] );
var material = new THREE.MeshPhongMaterial({ envMap: environment });
// in animate()
environment.needsUpdate = true;
答案 2 :(得分:0)
好的,现在我设法使用Phong材料在立方体上获得了闪亮的效果:
videoTexture = new THREE.Texture( Video );
var material = new THREE.MeshPhongMaterial({
map: videoTexture,
ambient: 0x030303,
specular: 0xc0c0c0,
shininess: 25
});
这看起来并不那么糟糕。
但似乎THREE.Texture([Video,Video,Video,Video,Video,Video]);
不能用作envMap。我仍然得到一个黑色的立方体。