three1.html 1.69 KB
Newer Older
Alfakhori's avatar
Alfakhori committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!doctype html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>Cube Demo</title>

  <!-- three.js -->
  <script src="https://unpkg.com/three@0.126.0/build/three.js"></script>
</head>
<body>

<!-- Starting an immersive WebXR session requires user interaction.
    We start this one with a simple button. -->
<script>
Alfakhori's avatar
Alfakhori committed
17
18
19
  // ------------------------------------------------
// BASIC SETUP
// ------------------------------------------------
Alfakhori's avatar
Alfakhori committed
20

Alfakhori's avatar
Alfakhori committed
21
22
// Create an empty scene
var scene = new THREE.Scene();
Alfakhori's avatar
Alfakhori committed
23

Alfakhori's avatar
Alfakhori committed
24
25
26
// Create a basic perspective camera
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
camera.position.z = 4;
Alfakhori's avatar
Alfakhori committed
27

Alfakhori's avatar
Alfakhori committed
28
29
// Create a renderer with Antialiasing
var renderer = new THREE.WebGLRenderer({antialias:true});
Alfakhori's avatar
Alfakhori committed
30

Alfakhori's avatar
Alfakhori committed
31
32
// Configure renderer clear color
renderer.setClearColor("#000000");
Alfakhori's avatar
Alfakhori committed
33

Alfakhori's avatar
Alfakhori committed
34
35
// Configure renderer size
renderer.setSize( window.innerWidth, window.innerHeight );
Alfakhori's avatar
Alfakhori committed
36

Alfakhori's avatar
Alfakhori committed
37
38
// Append Renderer to DOM
document.body.appendChild( renderer.domElement );
Alfakhori's avatar
Alfakhori committed
39

Alfakhori's avatar
Alfakhori committed
40
41
42
// ------------------------------------------------
// FUN STARTS HERE
// ------------------------------------------------
Alfakhori's avatar
Alfakhori committed
43

Alfakhori's avatar
Alfakhori committed
44
45
46
47
// Create a Cube Mesh with basic material
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( { color: "#433F81" } );
var cube = new THREE.Mesh( geometry, material );
Alfakhori's avatar
Alfakhori committed
48

Alfakhori's avatar
Alfakhori committed
49
50
// Add cube to Scene
scene.add( cube );
Alfakhori's avatar
Alfakhori committed
51

Alfakhori's avatar
Alfakhori committed
52
53
54
// Render Loop
var render = function () {
  requestAnimationFrame( render );
Alfakhori's avatar
Alfakhori committed
55

Alfakhori's avatar
Alfakhori committed
56
57
  cube.rotation.x += 0.01;
  cube.rotation.y += 0.01;
Alfakhori's avatar
Alfakhori committed
58

Alfakhori's avatar
Alfakhori committed
59
60
61
  // Render the scene
  renderer.render(scene, camera);
};
Alfakhori's avatar
Alfakhori committed
62

Alfakhori's avatar
Alfakhori committed
63
render();
Alfakhori's avatar
Alfakhori committed
64
65
66
67

</script>
</body>
</html>