MyWebAR Knowledge Base
Language Eng
Language Eng
  • Knowledge base for MyWebAR developers
  • GETTING STARTED
    • Signing Up
    • Dashboard Overview
    • Editor Overview
  • PLANS AND SUBSCRIPTIONS
    • Free 14-Day Trial
    • Upgrading Your Plan
    • Commercial Plans
    • Plans for Education
  • CREATING WEBAR PROJECTS
    • Project Types
    • Multi-Image Projects (Books)
    • Adding Objects
    • How to add a 3D model from the library of 3D models
    • How to add 3D models from Sketchfab
    • Object Properties
    • Buttons and Actions
    • Video Playback
    • 3D Animations
    • Project Analytics
    • How to make a good trackable image for augmented reality
    • Optimizing And Preparing 3D Models For Loading
    • How to work with plugins
    • How to make AR portal in MyWebAR
    • Video Tutorials
  • WEBAR CUSTOMIZATION
    • Custom WebAR Domain
    • Using External File Server
    • WebAR Embedding
  • PRO EDITOR
    • How the Pro Editor works
      • Interface Description
      • Basic features
    • Current restrictions
      • An Example Of Integration Of A Ready-Made Script
      • Particle Creation In The Pro Editor
      • Working With Video
      • Working With 3D Object Animations
    • Code placement requirements
      • Working With The Camera
      • UI Creation
      • Loading objects using the basic class - loader
    • The Cases
      • Adding Images
      • Lens Flare Effect
Powered by GitBook
On this page
  • Creating a script
  • Working with code
  1. PRO EDITOR
  2. Current restrictions

Working With Video

PreviousParticle Creation In The Pro EditorNextWorking With 3D Object Animations

Last updated 3 years ago

The pipeline for adding a video file to the advanced editor will be described below.

Creating a script

First of all, you need to add a new script.

Next, you need to enter the code editing mode by clicking Edit.

Working with code

First you need to create a new HTML-element video (string 1).

let videoElem = document.createElement('video');

Next, we need to create a texture from the videoElem element, this is done using THREE.VideoTexture (string 2).

let videoElem = document.createElement('video');
let videoTexture = new THREE.VideoTexture(videoElem);

Now you need to add a plane to the scene, on which the video will be added (strings 3-6).

let videoElem = document.createElement('video');
let videoTexture = new THREE.VideoTexture(videoElem);
let videoPlane = new THREE.Mesh(
    new THREE.PlaneGeometry(2, 1),
    new THREE.MeshBasicMaterial({ map: videoTexture })
);

In this case, videoPlane is created, with a height of 2 and a width of 1, and the videoTexture, created earlier, is used as the material.

After creating a plane with video texture, you can add it to the scene (string 7).

let videoElem = document.createElement('video');
let videoTexture = new THREE.VideoTexture(videoElem);
let videoPlane = new THREE.Mesh(
    new THREE.PlaneGeometry(2, 1),
    new THREE.MeshBasicMaterial({ map: videoTexture })
);
scene.add( videoPlane );

If this script is linked to the scene, then adding an object to the scene will be recorded not as scene.add(), but as this.add().This is necessary for the correct importing of a scene into a simple editor.

Now we need to configure the added videoPlane.

The first step is to add a source. Best of all, if it is a CDN or a cloud that supports Access-Control-Allow-Origin (string 8).

let videoElem = document.createElement('video');
let videoTexture = new THREE.VideoTexture(videoElem);
let videoPlane = new THREE.Mesh(
    new THREE.PlaneGeometry(2, 1),
    new THREE.MeshBasicMaterial({ map: videoTexture })
);
this.add( videoPlane );
videoElem.src = "https://365508.selcdn.ru/examples/small.mp4";

Next, a very important moment. You need to add the following string videoElem.src = "https://365508.selcdn.ru/examples/small.mp4"; (string 9):

let videoElem = document.createElement('video');
let videoTexture = new THREE.VideoTexture(videoElem);
let videoPlane = new THREE.Mesh(
    new THREE.PlaneGeometry(2, 1),
    new THREE.MeshBasicMaterial({ map: videoTexture })
);
scene.add( videoPlane );
videoElem.src = "https://365508.selcdn.ru/examples/small.mp4";
videoElem.crossOrigin = "anonymous";

If this is not done, the video will not appear when starting the scene, and the following error will return in the console:

This is related with the work of an HTML-attribute crossorigin. Read more about this here.

The final steps are to enable/disable video looping and audio presence (strings 10-11).

let videoElem = document.createElement('video');
let videoTexture = new THREE.VideoTexture(videoElem);
let videoPlane = new THREE.Mesh(
    new THREE.PlaneGeometry(2, 1),
    new THREE.MeshBasicMaterial({ map: videoTexture })
);
scene.add( videoPlane );
videoElem.src = "https://365508.selcdn.ru/examples/small.mp4";
videoElem.crossOrigin = "anonymous";
videoElem.loop = false;
videoElem.muted = false;

And, most importantly, you need to start playing the video file (string 12).

let videoElem = document.createElement('video');
let videoTexture = new THREE.VideoTexture(videoElem);
let videoPlane = new THREE.Mesh(
    new THREE.PlaneGeometry(2, 1),
    new THREE.MeshBasicMaterial({ map: videoTexture })
);
scene.add( videoPlane );
videoElem.src = "https://365508.selcdn.ru/examples/small.mp4";
videoElem.crossOrigin = "anonymous";
videoElem.loop = false;
videoElem.muted = false;
videoElem.play();

This way, any video can be added to the scene.