Repository navigation
Expand file tree
/
Copy pathhelloworld2.html
More file actions
102 lines (84 loc) · 3.88 KB
/
Copy pathhelloworld2.html
File metadata and controls
102 lines (84 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<html>
<head>
<title>My first three.js app</title>
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script type="text/javascript" src="js/build/three.min.js"></script>
<script type="text/javascript" src="js/third-party/threejs/controls/OrbitControls.js"></script>
<script type="text/javascript" src="js/utils/helpers.js"></script>
<script>
/*
* setup the basic scene
* to see this visualized, go to https://threejs.org/examples/?q=camera#webgl_camera
*/
var scene; //scene is the stage we put things in
var camera; //camera defines how we look at the scene
var renderer; //render the scence for the camera
var controls; //help rotate the scene with mouse
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 0, 3);
camera.focalLength = camera.position.distanceTo(scene.position);
camera.lookAt(scene.position);
renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0)
document.body.appendChild(renderer.domElement);
controls = new THREE.OrbitControls(camera);
controls.autoRotate = true;
controls.enablePan = false;
//light up the scence
var light = new THREE.DirectionalLight(0xffffff);
light.position.set(-1, 1.5, 0.5);
scene.add(light);
/*
* add your own object to the scene here
*/
//geometry + material = viewable objects
var line = new THREE.Geometry();
// line.vertices.push(new THREE.Vector3(-1, 0, 1));
// line.vertices.push(new THREE.Vector3(0, 0, 0));
// line.vertices.push(new THREE.Vector3(1, 0, 1));
// create a circle with line segments
var r = 1;
var steps = 10;
var deltaTheta = 2*Math.PI/steps;
for (var i=0; i< steps; i++){
var theta = deltaTheta*i;
var x = r * Math.cos(theta);
var y = r * Math.sin(theta);
line.vertices.push(new THREE.Vector3(x,y,0));
}
var material = new THREE.LineBasicMaterial({ color: 0xffff00 });
var lineObject = new THREE.Line(line, material);
scene.add(lineObject);
// smooth the circle out with the Catmull-Rom spline (https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline)
var curve = new THREE.CatmullRomCurve3();
for (var i=0; i< steps; i++){
var theta = deltaTheta*i;
var x = r * Math.cos(theta);
var y = r * Math.sin(theta);
curve.points.push (new THREE.Vector3(x,y,0));
}
curve.closed = true;
var geometry = new THREE.Geometry();
geometry.vertices = curve.getPoints( 30 );
var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
var curveObject = new THREE.Line( geometry, material );
scene.add(curveObject);
/*
* animate and render the scene
*/
var render = function () {
requestAnimationFrame( render );
renderer.render(scene, camera);
};
render();
</script>
</body>
</html>