- BabylonJS教程
- BabylonJS——主页
- BabylonJS——简介
- BabylonJS——环境设置
- BabylonJS——概述
- BabylonJS——基本元素
- BabylonJS——材质
- BabylonJS——动画
- BabylonJS——相机
- BabylonJS——灯光
- BabylonJS——参数化形状
- BabylonJS——网格
- 矢量位置和旋转
- BabylonJS——贴花
- BabylonJS——曲线3
- BabylonJS——动态纹理
- BabylonJS——视差映射
- BabylonJS——镜头光晕
- BabylonJS——创建屏幕截图
- BabylonJS——反射探头
- 标准渲染管道
- BabylonJS——着色器材质
- BabylonJS——骨骼和骨架
- BabylonJS——物理引擎
- BabylonJS——播放声音和音乐
- BabylonJS实用资源
- BabylonJS——快速指南
- BabylonJS——实用资源
- BabylonJS——讨论
BabylonJS——视频纹理
要在场景中显示视频,BabylonJS具有视频纹理功能。videotexture将视频数组作为输入。
对于视频纹理,我们将使用mp4文件。请下载您选择的mp4并将其用于下面的演示中。
语法
video.material.diffuseTexture = new BABYLON.VideoTexture("video", ["mp4 file", "webm file"], scene, true);
演示
<!doctype html> <html> <head> <meta charset = "utf-8"> <title>BabylonJs - Basic Element-Creating Scene</title> <script src = "babylon.js"></script> <style> canvas {width: 100%; height: 100%;} </style> </head> <body> <canvas id = "renderCanvas"></canvas> <script type = "text/javascript"> var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); var createScene = function() { var scene = new BABYLON.Scene(engine); //Adding an Arc Rotate Camera var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 100, BABYLON.Vector3.Zero(), scene); camera.attachControl(canvas, false); // This creates a light, aiming 0,1,0 - to the sky (non-mesh) var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene); // Default intensity is 1. Let's dim the light a small amount light.intensity = 0.7; // Our built-in 'sphere' shape. Params: name, subdivs, size, scene var ground = BABYLON.Mesh.CreateGround("ground1", 100, 50, 2, scene); // Move the sphere upward 1/2 its height ground.position.y = 1; var mat = new BABYLON.StandardMaterial("mat", scene); var videoTexture = new BABYLON.VideoTexture("video", ["sounds/video.mp4"], scene, true, true); mat.diffuseTexture = videoTexture; ground.material = mat; scene.onPointerUp = function () { videoTexture.video.play(); } return scene; }; var scene = createScene(); engine.runRenderLoop(function() { scene.render(); }); </script> </body> </html>
输出
以上代码行将生成以下输出 -
babylonjs_mesh.htm
广告