Babylonjs-mesh-video-texture

提供:Dev Guides
移動先:案内検索

BabylonJS-ビデオテクスチャ

シーンにビデオを表示するために、babylonjsにはビデオテクスチャ機能があります。 videotextureは、ビデオの配列を入力として受け取ります。

ビデオテクスチャには、mp4ファイルを使用します。 選択したmp4をダウンロードして、以下のデモで使用してください。

構文

video.material.diffuseTexture = new BABYLON.VideoTexture("video",
["mp4 file", "webm file"], scene, true);

Demo

<!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>

出力

上記のコード行は、次の出力を生成します-

ビデオテクスチャ