-
Notifications
You must be signed in to change notification settings - Fork 1
/
extrude.html
196 lines (125 loc) · 5.87 KB
/
extrude.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!-- http://threejs.org/examples/#webgl_geometry_extrude_shapes -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - geometry - extrude shapes</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
font-family: Monospace;
background-color: #222;
margin: 0px;
overflow: hidden;
}
a {
color: #f80;
}
</style>
</head>
<body>
<script src="js/third-party/threejs/three.js"></script>
<script src="js/controls/TrackballControls.js"></script>
<script>
var container;
var camera, scene, renderer, controls;
init();
animate();
function init() {
var info = document.createElement( 'div' );
info.style.position = 'absolute';
info.style.top = '10px';
info.style.width = '100%';
info.style.textAlign = 'center';
info.style.color = '#fff';
info.style.link = '#f80';
info.innerHTML = '<a href="http://threejs.org" target="_blank">three.js</a> webgl - geometry extrude shapes';
document.body.appendChild( info );
renderer = new THREE.WebGLRenderer();
renderer.setClearColor( 0x222222 );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( 0, 0, 500 );
controls = new THREE.TrackballControls( camera, renderer.domElement );
controls.minDistance = 200;
controls.maxDistance = 500;
scene.add( new THREE.AmbientLight( 0x222222 ) );
var light = new THREE.PointLight( 0xffffff );
light.position.copy( camera.position );
scene.add( light );
//
// var closedSpline = new THREE.CatmullRomCurve3( [
// new THREE.Vector3( -60, -100, 60 ),
// new THREE.Vector3( -60, 20, 60 ),
// new THREE.Vector3( -60, 120, 60 ),
// new THREE.Vector3( 60, 20, -60 ),
// new THREE.Vector3( 60, -100, -60 )
// ] );
// closedSpline.type = 'catmullrom';
// closedSpline.closed = true;
// var extrudeSettings = {
// steps : 100,
// bevelEnabled : false,
// extrudePath : closedSpline
// };
// var pts = [], count = 3;
// for ( var i = 0; i < count; i ++ ) {
// var l = 20;
// var a = 2 * i / count * Math.PI;
// pts.push( new THREE.Vector2 ( Math.cos( a ) * l, Math.sin( a ) * l ) );
// }
// var shape = new THREE.Shape( pts );
// var geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );
var material = new THREE.MeshLambertMaterial( { color: 0xb00000, wireframe: false } );
// var mesh = new THREE.Mesh( geometry, material );
// scene.add( mesh );
//
var randomPoints = [];
for ( var i = 0; i < 10; i ++ ) {
randomPoints.push( new THREE.Vector3( ( i - 4.5 ) * 50, THREE.Math.randFloat( - 50, 50 ), THREE.Math.randFloat( - 50, 50 ) ) );
}
var randomSpline = new THREE.CatmullRomCurve3( randomPoints );
var extrudeSettings = {
steps : 200,
bevelEnabled : false,
extrudePath : randomSpline
};
var pts = [], numPts = 5;
for ( var i = 0; i < numPts * 2; i ++ ) {
var l = i % 2 == 1 ? 10 : 20;
var a = i / numPts * Math.PI;
pts.push( new THREE.Vector2 ( Math.cos( a ) * l, Math.sin( a ) * l ) );
}
var shape = new THREE.Shape( pts );
var geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );
var material2 = new THREE.MeshLambertMaterial( { color: 0xff8000, wireframe: false } );
var mesh = new THREE.Mesh( geometry, material2 );
scene.add( mesh );
//
// var materials = [ material, material2 ];
// var extrudeSettings = {
// amount : 20,
// steps : 1,
// material : 1,
// extrudeMaterial : 0,
// bevelEnabled : true,
// bevelThickness : 2,
// bevelSize : 4,
// bevelSegments : 1,
// };
// var geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );
// var mesh = new THREE.Mesh( geometry, new THREE.MultiMaterial( materials ) );
// mesh.position.set( 50, 100, 50 );
// scene.add( mesh );
}
function animate() {
requestAnimationFrame( animate );
controls.update();
renderer.render( scene, camera );
}
</script>
</body>
</html>