-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.html
168 lines (128 loc) · 6.07 KB
/
test.html
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<html>
<head>
<title>LDraw Visualizer: Playground</title>
<link href="./styles/ldraw-visualizer.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" class="dom_munger-ignore">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" class="dom_munger-ignore">
<link href='http://fonts.googleapis.com/css?family=Roboto+Condensed' rel='stylesheet' type='text/css' class="dom_munger-ignore">
<style>
html, body {
font-family: 'Roboto Condensed', sans-serif;
}
</style>
</head>
<body>
<div id="container"></div>
<script class="dom_munger-ignore dom_munger-remove" src="//localhost:35729/livereload.js"></script>
<script src="lib/jquery/jquery-2.1.4.min.js"></script>
<script src="lib/threejs/three.min.js"></script>
<script src="lib/threejs/Detector.js"></script>
<script src="lib/threejs/OrbitControls.js"></script>
<script src="compiled/scripts/utility.js"></script>
<script>
if (!Detector.webgl) Detector.addGetWebGLMessage();
var container;
var camera, controls, scene, renderer;
window.onload = function() {
init();
render();
}
function animate() {
requestAnimationFrame(animate);
controls.update();
}
function init() {
camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 5000);
camera.position.z = -500;
controls = new THREE.OrbitControls(camera);
controls.damping = 0.2;
controls.addEventListener('change', render);
scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x111111, 0.001);
scene.add(buildAxes(1000));
// var pointGeometry = new THREE.SphereGeometry( 2, 32, 32 );
// pointGeometry.applyMatrix(new THREE.Matrix4().makeTranslation(41.421356 / 2, 0, -50));
// var pointMaterial = new THREE.MeshPhongMaterial( {color: 0x00aa00} );
// var point = new THREE.Mesh( pointGeometry, pointMaterial );
// scene.add(point);
var mainGeometry = new THREE.Geometry();
var sideCount = 8;
for (var i = 0; i < sideCount; i++) {
var width = 41.42135623730950488016887242096980785696718753769480731766797;
var side = new THREE.PlaneGeometry(width, 200);
side.faces[0].vertexNormals[0] = new THREE.Vector3(-width / 2, 0, 50);
side.faces[0].vertexNormals[1] = new THREE.Vector3(-width / 2, 0, 50);
side.faces[0].vertexNormals[2] = new THREE.Vector3(width / 2, 0, 50);
side.faces[1].vertexNormals[0] = new THREE.Vector3(-width / 2, 0, 50);
side.faces[1].vertexNormals[1] = new THREE.Vector3(width / 2, 0, 50);
side.faces[1].vertexNormals[2] = new THREE.Vector3(width / 2, 0, 50);
side.applyMatrix(new THREE.Matrix4().makeTranslation(0, 0, 50));
side.applyMatrix(new THREE.Matrix4().makeRotationY(LdrawVisualizer.Utility.degreesToRadians(360 * (i / sideCount))));
THREE.GeometryUtils.merge(mainGeometry, side);
}
console.log(mainGeometry.faces[2]);
mainGeometry.mergeVertices();
console.log(mainGeometry.faces[2]);
// real cylinder
mainGeometry = new THREE.CylinderGeometry(50, 50, 200, 8, 1, true)
var material = new THREE.MeshPhongMaterial({ color: 0xffff00, shading: THREE.SmoothShading, side: THREE.DoubleSide });
var cylinder = new THREE.Mesh( mainGeometry, material );
scene.add(cylinder);
// lights
var directionalLight = new THREE.DirectionalLight(0xCCCCCC);
directionalLight.position.set(1, .6, -.2);
scene.add(directionalLight);
directionalLight = new THREE.DirectionalLight(0xCCCCCC);
directionalLight.position.set(-1, -1.5, 1.7);
scene.add(directionalLight);
directionalLight = new THREE.DirectionalLight(0xFFFFFF);
directionalLight.position.set(-20, 70, -60);
scene.add(directionalLight);
var ambientLight = new THREE.AmbientLight(0x333333);
scene.add(ambientLight);
// renderer
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setClearColor(scene.fog.color);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
container = document.getElementById('container');
container.appendChild(renderer.domElement);
window.addEventListener('resize', onWindowResize, false);
animate();
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
render();
}
function render() {
renderer.render(scene, camera);
}
function buildAxes(length) {
var axes = new THREE.Object3D();
axes.add(buildAxis(new THREE.Vector3(0, 0, 0), new THREE.Vector3(length, 0, 0), 0xFF0000, false)); // +X
axes.add(buildAxis(new THREE.Vector3(0, 0, 0), new THREE.Vector3(-length, 0, 0), 0xFF0000, true)); // -X
axes.add(buildAxis(new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, length, 0), 0x00FF00, false)); // +Y
axes.add(buildAxis(new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, -length, 0), 0x00FF00, true)); // -Y
axes.add(buildAxis(new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, 0, length), 0x0000FF, false)); // +Z
axes.add(buildAxis(new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, 0, -length), 0x0000FF, true)); // -Z
return axes;
}
function buildAxis(src, dst, colorHex, dashed) {
var geom = new THREE.Geometry(),
mat;
if (dashed) {
mat = new THREE.LineDashedMaterial({ linewidth: 3, color: colorHex, dashSize: 3, gapSize: 3 });
} else {
mat = new THREE.LineBasicMaterial({ linewidth: 3, color: colorHex });
}
geom.vertices.push(src.clone());
geom.vertices.push(dst.clone());
geom.computeLineDistances(); // This one is SUPER important, otherwise dashed lines will appear as simple plain lines
var axis = new THREE.Line(geom, mat, THREE.LinePieces);
return axis;
}
</script>
</body>
</html>