Javascript, A-Frame




CS185c

Chris Pollett

Feb 4, 2019

Outline

Introduction

The id Attribute

Other Common Attributes

User-Defined Attributes and Elements

Javascript

We now want to talk about Javascript in detail. It will be the language used to script action in WebVR. It is also the language used to add the functionality of tags in A-Frame.

Different Ways of Running Javascript

Server Side Javascript - How to test our WebVR Web pages

Quiz

Which of the following statements is true?

  1. VR Systems can only be used with people.
  2. Teleoperation refers to a telepresense system where the user is actually able to control some aspect of the remote setting.
  3. VR Sickness occurs when someone pays too much for a VR system.

Client-Side Javascript

Javascript Syntax

Variables, Assignments and Operators

Arrays and Objects

Control Statements

Functions

Function Example

function swap(i, j, a)
{
	var tmp=a[i]; /* explicitly defined variables 
                         have scope within the function
                         if I had declared the variable 
                         implicitly it would have global scope */
	a[i] = a[j]; a[j] = tmp;
}

DOM

A-Frame

A-Frame Example

[My First A-Frame Example Link]

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>My First A-Frame Page</title>
    <script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
</head>
<body>
<a-scene background="color: #ECECEC">
    <a-assets>
        <img id="my-photo" src="images/myphoto.jpg" />
    </a-assets>
    <a-box position="-1 0.5 -3" rotation="0 45 0" src="#my-photo"
        shadow></a-box>
    <a-sphere position="0 1.25 -5" radius="1.25" color="green"
        shadow></a-sphere>
    <a-cone position="1 0.75 -3" radius="0.3" height="1.3" color="blue"
        shadow></a-cone>
    <a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4"
        color="#FF5566" shadow></a-plane>
</a-scene>
</body>
</html>

Remarks on Example 1

A-Frame Primitives

Entity Components