Giter Site home page Giter Site logo

openvidu-vr's Introduction

OpenVidu Virtual Reality

OpenVidu team has started to inlcude openvidu in the world of virtual reality.

The technologies used to develop these applications will be WebGL, Three.js and JavaScript.

WebGL

WebGL is a cross-platform, royalty-free API used to create 3D graphics in a Web browser. Based on OpenGL ES 2.0, WebGL uses the OpenGL shading language, GLSL, and offers the familiarity of the standard OpenGL API. Because it runs in the HTML5 Canvas element, WebGL has full integration with all Document Object Model (DOM) interfaces.

Three.js is a cross-browser JavaScript library and Application Programming Interface (API) used to create and display animated 3D computer graphics in a web browser. Three.js uses WebGL. The source code is hosted in a repository on GitHub.

Our applications examples are based on Three.js examples and we have inlcuded openvidu.

First of all, to get an 3D object, we have to take account a few steps:

  1. Create a scene: To actually be able to display anything with three.js, we need three things: scene, camera and renderer, so that we can render the scene with camera.
    scene = new THREE.Scene();

    camera = new THREE.PerspectiveCamera(30, window.innerWidth / window.innerHeight, 1, 10000);
    camera.position.set(1000, 50, 1500);

    renderer = new THREE.WebGLRenderer({ antialias: true });

    var light = new THREE.DirectionalLight(0xdfebff, 1);
    scene.add(light);

Besides, we can add some extra things to create a complete example: These things could be light and object texture.

   // light
   var light = new THREE.DirectionalLight(0xdfebff, 1);
   light.position.set(50, 200, 100);
   light.position.multiplyScalar(1.3);
   light.castShadow = true;
   light.shadow.mapSize.width = 1024;
   light.shadow.mapSize.height = 1024;
   var d = 300;
   light.shadow.camera.left = -d;
   light.shadow.camera.right = d;
   light.shadow.camera.top = d;
   light.shadow.camera.bottom = -d;
   light.shadow.camera.far = 1000;
   scene.add(light);

   // object texture
   var video = document.getElementById('video');
   var videoTexture = new THREE.VideoTexture(video);    
   var clothMaterial = new THREE.MeshLambertMaterial({
       map: videoTexture,
       side: THREE.DoubleSide,
       alphaTest: 0.5,
   });
   // object geometry
   clothGeometry = new THREE.ParametricBufferGeometry(clothFunction, cloth.w, cloth.h);
   object = new THREE.Mesh(clothGeometry, clothMaterial);
   object.position.set(0, 0, 0);
   object.castShadow = true;
   scene.add(object);
  1. Rendering the scene: This will create a loop that causes the renderer to draw the scene every time the screen is refreshed (on a typical screen this means 60 times per second).
    requestAnimationFrame(animate);
    renderer.render(scene, camera);
  1. Animate the object: This will be run every frame (normally 60 times per second). Basically, anything you want to move or change while the app is running has to go through the animate loop. You can of course call other functions from there, so that you don't end up with a animate function that's hundreds of lines.

Finally, OpenVidu comes on stage. We start from openvidu-hello-world tutorial, we initialize a publisher and we use the ov-video generated to assign that video like our object texture (step 1.2). This is how we integrate openvidu with a virtual reality environment.

openvidu-vr's People

Contributors

csantosm avatar dependabot[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.