-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdemo.1.html
246 lines (202 loc) · 13.6 KB
/
demo.1.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!DOCTYPE html>
<!-- This file is from the Three.JS source Git repository taken in March 2018 -->
<!-- saved from url=(0067)https://threejs.org/docs/scenes/geometry-browser.html#TorusGeometry -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Heron Geometry Creation Demo</title>
<style>
body {
margin:0;
font-size: 15px;
line-height: 18px;
overflow: hidden;
}
canvas { width: 100%; height: 100% }
#newWindow {
display: block;
position: absolute;
bottom: 0.3em;
left: 0.5em;
color: #fff;
}
</style>
<style type="text/css">.dg ul{list-style:none;margin:0;padding:0;width:100%;clear:both}.dg.ac{position:fixed;top:0;left:0;right:0;height:0;z-index:0}.dg:not(.ac) .main{overflow:hidden}.dg.main{-webkit-transition:opacity .1s linear;transition:opacity .1s linear}.dg.main.taller-than-window{overflow-y:auto}.dg.main.taller-than-window .close-button{opacity:1;margin-top:-1px;border-top:1px solid #2c2c2c}.dg.main ul.closed .close-button{opacity:1!important}.dg.main .close-button.drag,.dg.main:hover .close-button{opacity:1}.dg.main .close-button{-webkit-transition:opacity .1s linear;transition:opacity .1s linear;border:0;position:absolute;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-x:hidden}.dg.a.has-save>ul{margin-top:27px}.dg.a.has-save>ul.closed{margin-top:0}.dg.a .save-row{position:fixed;top:0;z-index:1002}.dg li{-webkit-transition:height .1s ease-out;transition:height .1s ease-out}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;overflow:hidden;padding:0 4px 0 5px}.dg li.folder{padding:0;border-left:4px solid transparent}.dg li.title{cursor:pointer;margin-left:-4px}.dg .closed li:not(.title),.dg .closed ul li,.dg .closed ul li>*{height:0;overflow:hidden;border:0}.dg .cr{clear:both;padding-left:3px;height:27px}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%}.dg .c input[type=text]{border:0;margin-top:4px;padding:3px;width:100%;float:right}.dg .has-slider input[type=text]{width:30%;margin-left:0}.dg .slider{float:left;width:66%;margin-left:-5px;margin-right:0;height:19px;margin-top:4px}.dg .slider-fg{height:100%}.dg .c input[type=checkbox]{margin-top:9px}.dg .c select{margin-top:5px}.dg .cr.boolean,.dg .cr.boolean *,.dg .cr.function,.dg .cr.function *,.dg .cr.function .property-name{cursor:pointer}.dg .selector{display:none;position:absolute;margin-left:-9px;margin-top:23px;z-index:10}.dg .c:hover .selector,.dg .selector.drag{display:block}.dg li.save-row{padding:0}.dg li.save-row .button{display:inline-block;padding:0 6px}.dg.dialogue{background-color:#222;width:460px;padding:15px;font-size:13px;line-height:15px}#dg-new-constructor{padding:10px;color:#222;font-family:Monaco,monospace;font-size:10px;border:0;resize:none;box-shadow:inset 1px 1px 1px #888;word-wrap:break-word;margin:12px 0;display:block;width:440px;overflow-y:scroll;height:100px;position:relative}#dg-local-explain{display:none;font-size:11px;line-height:17px;border-radius:3px;background-color:#333;padding:8px;margin-top:10px}#dg-local-explain code{font-size:10px}#dat-gui-save-locally{display:none}.dg{color:#eee;font:11px Lucida Grande,sans-serif;text-shadow:0 -1px 0 #111}.dg.main::-webkit-scrollbar{width:5px;background:#1a1a1a}.dg.main::-webkit-scrollbar-corner{height:0;display:none}.dg.main::-webkit-scrollbar-thumb{border-radius:5px;background:#676767}.dg li:not(.folder){background:#1a1a1a;border-bottom:1px solid #2c2c2c}.dg li.save-row{line-height:25px;background:#dad5cb;border:0}.dg li.save-row select{margin-left:5px;width:108px}.dg li.save-row .button{margin-left:5px;margin-top:1px;border-radius:2px;font-size:9px;line-height:7px;padding:4px 4px 5px;background:#c5bdad;color:#fff;text-shadow:0 1px 0 #b0a58f;box-shadow:0 -1px 0 #b0a58f;cursor:pointer}.dg li.save-row .button.gears{background:#c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;height:7px;width:8px}.dg li.save-row .button:hover{background-color:#bab19e;box-shadow:0 -1px 0 #b0a58f}.dg li.folder{border-bottom:0}.dg li.title{padding-left:16px;background:#000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;cursor:pointer;border-bottom:1px solid hsla(0,0%,100%,.2)}.dg .closed li.title{background-image:url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==)}.dg .cr.boolean{border-left:3px solid #806787}.dg .cr.color{border-left:3px solid}.dg .cr.function{border-left:3px solid #e61d5f}.dg .cr.number{border-left:3px solid #2fa1d6}.dg .cr.number input[type=text]{color:#2fa1d6}.dg .cr.string{border-left:3px solid #1ed36f}.dg .cr.string input[type=text]{color:#1ed36f}.dg .cr.boolean:hover,.dg .cr.function:hover{background:#111}.dg .c input[type=text]{background:#303030;outline:none}.dg .c input[type=text]:hover{background:#3c3c3c}.dg .c input[type=text]:focus{background:#494949;color:#fff}.dg .c .slider{background:#303030;cursor:ew-resize}.dg .c .slider-fg{background:#2fa1d6;max-width:100%}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}</style>
</head>
<body>
<script id="vertexShader" type="x-shader/x-vertex">
precision highp float;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
attribute vec3 position;
attribute vec3 offset;
attribute vec3 color;
varying vec3 vColor;
void main() {
gl_Position = projectionMatrix * modelViewMatrix * vec4( offset + position, 1.0 );
vColor = color;
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
precision highp float;
varying vec3 vColor;
void main() {
gl_FragColor = vec4( vColor, 1.0 );
}
</script>
<script src="./js/three.min.js.download"></script>
<script src="./js/dat.gui.min.js.download"></script>
<script src="./js/OrbitControls.js.download"></script>
<script src="./js/ParametricGeometries.js.download"></script>
<script src="./js/geometry.js.download"></script>
<script src="./output.js"></script>
<script>
// Used for controlling which geometry is show in the UI
const heronData = {
geometryIndex: 0,
offset: {
x: 0,
y: 0,
z: 0,
},
scale: 3,
};
function vectorsToJavaScript(xs) {
const r = [];
for (const v of xs)
r.push(v.x, v.y, v.z);
return r;
}
// A list of the geometris created
const heronGeometries = heronMain();
// Used to create a heron geometry and associate it with a ThreeJS scene object
function makeHeronGeometry( sceneObject )
{
function heronGeometryToThreeJsGeometry(heronMesh) {
const r = new THREE.BufferGeometry();
const vertexBuffer = vectorsToJavaScript(heronMesh.vertexBuffer);
const colorBuffer = vectorsToJavaScript(heronMesh.colorBuffer);
//const normalBuffer = heronArrayToJavaScript(heronMesh.normalBuffer);
//const uvBuffer = heronArrayToJavaScript(heronMesh.uvBuffer);
r.setIndex( heronMesh.indexBuffer );
//https://threejs.org/docs/#api/core/BufferGeometry
r.addAttribute( 'position', new THREE.Float32BufferAttribute( vertexBuffer, 3 ) );
r.addAttribute( 'color', new THREE.Float32BufferAttribute( colorBuffer, 3 ) );
// TODO: add normals
//r.addAttribute( 'normal', new THREE.Float32BufferAttribute( normalBuffer, 3 ) );
const geometry = new THREE.InstancedBufferGeometry();
geometry.index = r.index;
geometry.attributes.position = r.attributes.position;
geometry.attributes.color = r.attributes.position;
const instances = 10000;
const offsets = [];
const len = 50;
for ( var i = 0; i < instances; i ++ ) {
// offsets
x = Math.random() * len - len/2;
y = Math.random() * len - len/2;
z = Math.random() * len - len/2;
offsets.push( x, y, z );
}
// This is the magic
const offsetAttribute = new THREE.InstancedBufferAttribute( new Float32Array( offsets ), 3 );
geometry.addAttribute( 'offset', offsetAttribute );
return geometry;
}
function generateGeometry() {
const f = heronGeometries[heronData.geometryIndex];
const hg = f(heronData.offset.x / 10, heronData.offset.y / 10, heronData.offset.z / 10, heronData.scale);
const g = heronGeometryToThreeJsGeometry(hg);
updateGroupGeometry( sceneObject, g );
}
const geometryIndices = {
'sphere':0,
'cylinder':1,
'torus': 2,
'klein': 3,
'plane': 4,
'mobius': 5,
};
gui.add(heronData, 'geometryIndex', geometryIndices).onChange( generateGeometry );
const f = gui.addFolder('translation');
f.add(heronData.offset, 'x').onChange( generateGeometry );
f.add(heronData.offset, 'y').onChange( generateGeometry );
f.add(heronData.offset, 'z').onChange( generateGeometry );
gui.add(heronData, 'scale').onChange( generateGeometry );
generateGeometry();
return { };
}
//document.getElementById( 'newWindow' ).href += window.location.hash;
var gui = new dat.GUI();
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 50 );
camera.position.z = 20;
var renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( 0x000000, 1 );
document.body.appendChild( renderer.domElement );
var orbit = new THREE.OrbitControls( camera, renderer.domElement );
orbit.enableZoom = false;
var lights = [];
lights[ 0 ] = new THREE.PointLight( 0xffffff, 1, 0 );
lights[ 1 ] = new THREE.PointLight( 0xffffff, 1, 0 );
lights[ 2 ] = new THREE.PointLight( 0xffffff, 1, 0 );
lights[ 0 ].position.set( 0, 200, 0 );
lights[ 1 ].position.set( 100, 200, 100 );
lights[ 2 ].position.set( - 100, - 200, - 100 );
scene.add( lights[ 0 ] );
scene.add( lights[ 1 ] );
scene.add( lights[ 2 ] );
const mesh = new THREE.Object3D();
const lineMaterial = new THREE.LineBasicMaterial( {
color: 0xffffff,
transparent: true,
opacity: 0.5
});
const vertexColorMaterial = new THREE.MeshBasicMaterial( {
vertexColors: THREE.VertexColors,
side: THREE.DoubleSide,
flatShading: true
});
const phongMaterial = new THREE.MeshPhongMaterial( {
color: 0x156289,
emissive: 0x072534,
side: THREE.DoubleSide,
flatShading: true
});
const shaderMaterial = new THREE.RawShaderMaterial( {
uniforms: {},
vertexShader: document.getElementById( 'vertexShader' ).textContent,
fragmentShader: document.getElementById( 'fragmentShader' ).textContent,
vertexColors: true,
side: THREE.DoubleSide,
} );
mesh.add( new THREE.LineSegments(
new THREE.Geometry(),
lineMaterial
));
mesh.add( new THREE.Mesh(
new THREE.Geometry(),
shaderMaterial, // vertexColorMaterial, or [ shaderMaterial, vertexColorMaterial ]
));
var options = makeHeronGeometry( mesh );
scene.add( mesh );
var prevFog = false;
var render = function () {
requestAnimationFrame( render );
if ( !options.fixed ) {
mesh.rotation.x += 0.005;
mesh.rotation.y += 0.005;
}
renderer.render( scene, camera );
};
window.addEventListener( 'resize', function () {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}, false );
render();
</script>
<!--
<div class="dg ac"><div class="dg main a" style="width: 245px;"><div style="width: 6px; margin-left: -3px; height: 168px; cursor: ew-resize; position: absolute;"></div><ul style="height: auto;"><li class="folder"><div class="dg"><ul><li class="title">THREE.TorusGeometry</li><li class="cr number has-slider"><div><span class="property-name">radius</span><div class="c"><div><input type="text"></div><div class="slider"><div class="slider-fg" style="width: 47.3684%;"></div></div></div></div></li><li class="cr number has-slider"><div><span class="property-name">tube</span><div class="c"><div><input type="text"></div><div class="slider"><div class="slider-fg" style="width: 33.5344%;"></div></div></div></div></li><li class="cr number has-slider"><div><span class="property-name">radialSegments</span><div class="c"><div><input type="text"></div><div class="slider"><div class="slider-fg" style="width: 50%;"></div></div></div></div></li><li class="cr number has-slider"><div><span class="property-name">tubularSegments</span><div class="c"><div><input type="text"></div><div class="slider"><div class="slider-fg" style="width: 49.2386%;"></div></div></div></div></li><li class="cr number has-slider"><div><span class="property-name">arc</span><div class="c"><div><input type="text"></div><div class="slider"><div class="slider-fg" style="width: 100%;"></div></div></div></div></li></ul></div></li></ul><div class="close-button" style="width: 245px;">Close Controls</div></div></div><canvas width="1366" height="588" style="width: 1366px; height: 588px;"></canvas>
-->
</body></html>