- 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
廣告