@@ -74,380 +74,7 @@ <h2>  Menu</h2>
7474
7575 < script src ="js/visCommon.js "> </ script >
7676 < script src ="js/BootSideMenu.js "> </ script >
77- < script src ="js/d3.v3.min.js "> </ script >
78- < script src ="js/three.min.js "> </ script >
77+ < script src ="js/visIdeal3d.js "> </ script >
7978
80- < script >
81-
82- $ ( '#side' ) . BootSideMenu ( { side :"right" , closeOnClick : false , width : "230px" } ) ;
83-
84- $ ( document ) . ready ( function ( ) {
85-
86- // show the ideal generators when clicked
87- $ ( "#idealGens" ) . on ( "click" , function ( ) {
88- $ ( this ) . html ( "Ideal Generators: " + labels ) ;
89- } ) ;
90- } ) ;
91-
92- var makeXYZstring = function ( x , y , z ) {
93- if ( x === 0 ) { xstr = "" ; }
94- else if ( x === 1 ) { xstr = "x" ; }
95- else { xstr = "x<sup>" + x . toString ( ) + "</sup>" ; }
96- if ( y === 0 ) { ystr = "" ; }
97- else if ( y === 1 ) { ystr = "y" ; }
98- else { ystr = "y<sup>" + y . toString ( ) + "</sup>" ; }
99- if ( z === 0 ) { zstr = "" ; }
100- else if ( z === 1 ) { zstr = "z" ; }
101- else { zstr = "z<sup>" + z . toString ( ) + "</sup>" ; }
102- xyzstr = xstr + ystr + zstr ;
103- return xyzstr ;
104- }
105-
106-
107-
108- var labels = [ ]
109- for ( i = 0 ; i < dataGenz . length ; i ++ ) {
110- labels . push ( makeXYZstring ( dataGenz [ i ] [ 0 ] , dataGenz [ i ] [ 1 ] , dataGenz [ i ] [ 2 ] ) ) ;
111- }
112- </ script >
113-
114- < script type ="x-shader/x-vertex " id ="vertexShader ">
115-
116- attribute vec4 center ;
117- varying vec4 vCenter ;
118-
119- void main ( ) {
120-
121- vCenter = center ;
122- gl_Position = projectionMatrix * modelViewMatrix * vec4 ( position , 1.0 ) ;
123-
124- }
125-
126- </ script >
127-
128- < script type ="x-shader/x-fragment " id ="fragmentShader ">
129-
130- #extension GL_OES_standard_derivatives : enable
131-
132- varying vec4 vCenter ;
133-
134- float edgeFactorTri ( ) {
135-
136- vec3 d = fwidth ( vCenter . xyz ) ;
137- vec3 a3 = smoothstep ( vec3 ( 0.0 ) , d * 1.5 , vCenter . xyz ) ;
138- return min ( min ( a3 . x , a3 . y ) , a3 . z ) ;
139-
140- }
141-
142- float edgeFactorQuad1 ( ) {
143-
144- vec2 d = fwidth ( vCenter . xy ) ;
145- vec2 a2 = smoothstep ( vec2 ( 0.0 ) , d * 1.5 , vCenter . xy ) ;
146-
147- return min ( a2 . x , a2 . y ) ;
148-
149- }
150-
151- float edgeFactorQuad2 ( ) {
152-
153- vec2 d = fwidth ( 1.0 - vCenter . xy ) ;
154- vec2 a2 = smoothstep ( vec2 ( 0.0 ) , d * 1.5 , 1.0 - vCenter . xy ) ;
155-
156- return min ( a2 . x , a2 . y ) ;
157- }
158-
159- void main ( ) {
160-
161- if ( vCenter . w == 0.0 ) {
162-
163- gl_FragColor . rgb = mix ( vec3 ( 1.0 ) , vec3 ( 0.2 ) , edgeFactorTri ( ) ) ;
164-
165- } else {
166-
167- gl_FragColor . rgb = mix ( vec3 ( 1.0 ) , vec3 ( 0.2 ) , min ( edgeFactorQuad1 ( ) , edgeFactorQuad2 ( ) ) ) ;
168-
169- }
170-
171- gl_FragColor . a = 1.0 ;
172-
173- }
174-
175-
176-
177-
178- </ script >
179-
180- < script >
181- var camera , scene , renderer ;
182- var geometry , material , mesh , ideal ;
183- var group ;
184-
185- var targetYRotation = targetXRotation = 0 ;
186- var targetYRotationOnMouseDown = targetXRotationOnMouseDown = 0 ;
187-
188- var mouseX = 0 , mouseY = 0 ;
189- var mouseXOnMouseDown = 0 ;
190- var zoomFactor = 1 ;
191-
192- var windowHalfX = window . innerWidth / 2 ;
193- var windowHalfY = window . innerHeight / 2 ;
194-
195- // var data = [[4, 0, 0], [0, 6, 0], [0, 0, 4]];
196- // var data = [[4,0,0],[2,3,0],[1,6,1],[0,0,4],[0,8,0]];
197- // var data = [[0, 0, 0], [1, 0, 0], [2, 0, 0], [3, 0, 0], [3, 1, 0], [3, 2, 0], [3, 3, 0], [3, 4, 0], [3, 4, 1], [3, 3, 1], [3, 2, 1], [3, 1, 1], [3, 0, 1], [3, 0, 2], [2, 1, 0], [2, 2, 0], [2, 3, 0], [2, 4, 0], [2, 4, 1], [2, 3, 1], [2, 2, 1], [2, 1, 1], [2, 0, 1], [2, 0, 2], [1, 1, 0], [1, 2, 0], [1, 3, 0], [1, 4, 0], [1, 4, 1], [1, 3, 1], [1, 2, 1], [1, 1, 1], [1, 0, 1], [1, 0, 2], [0, 1, 0], [0, 2, 0], [0, 3, 0], [0, 4, 0], [0, 4, 1], [0, 3, 1], [0, 2, 1], [0, 1, 1], [0, 0, 1], [0, 0, 2], [0, 0, 3], [0, 0, 4], [0, 0, 5]];
198-
199- var maxX = Math . max ( ...data . map ( d => d [ 0 ] ) ) ;
200- maxX = maxX == 0 ? 1 : maxX ;
201-
202- var maxY = Math . max ( ...data . map ( d => d [ 1 ] ) ) ;
203- maxY = maxY == 0 ? 1 : maxY ;
204-
205- var maxZ = Math . max ( ...data . map ( d => d [ 2 ] ) ) ;
206- maxZ = maxZ == 0 ? 1 : maxZ ;
207-
208- var maxExponent = Math . max ( maxX , maxY , maxZ ) ;
209-
210- function newMesh ( point , geometry , materials ) {
211- var mesh ;
212- if ( geometry . type == "BoxGeometry" ) {
213- mesh = new THREE . Mesh ( geometry , materials ) ;
214- } else {
215- mesh = new THREE . LineSegments ( geometry , materials ) ;
216- }
217- mesh . position . x = point [ 0 ] - 1 / 2 ;
218- mesh . position . y = point [ 1 ] - 1 / 2 ;
219- mesh . position . z = point [ 2 ] - 1 / 2 ;
220- mesh . updateMatrix ( ) ;
221- return mesh ;
222- }
223-
224- function processCubes ( data ) {
225- var cubes = [ ] ;
226- data . forEach ( function ( d ) {
227- cubes . push ( [ d [ 1 ] , d [ 2 ] , d [ 0 ] ] ) ;
228- } )
229- return cubes ;
230- }
231-
232- function init ( ) {
233- scene = new THREE . Scene ( ) ;
234- scene . background = new THREE . Color ( 0xffffff ) ;
235- camera = new THREE . PerspectiveCamera ( 45 , window . innerWidth / window . innerHeight , 0.1 , 1000 ) ;
236- // camera.position.set(7,10,15);
237- camera . position . set ( maxExponent * 2 , 10 , 15 ) ;
238- camera . lookAt ( new THREE . Vector3 ( 0 , 2 , 0 ) ) ;
239-
240- renderer = new THREE . WebGLRenderer ( { antialias : true } ) ;
241- // renderer = new THREE.CanvasRenderer();
242- renderer . setSize ( window . innerWidth , window . innerHeight ) ;
243-
244- document . body . appendChild ( renderer . domElement ) ;
245-
246- line_material = new THREE . LineBasicMaterial ( { linewidth : 3 } ) ;
247- material = new THREE . MeshBasicMaterial ( { color : 0x333333 } ) ;
248- group = new THREE . Object3D ( ) ;
249- geometry = new THREE . Geometry ( ) ;
250- geometry . vertices . push ( new THREE . Vector3 ( 0 , 0 , 0 ) ) ;
251- var s = 1
252- var cube = new THREE . CubeGeometry ( s , s , s ) ;
253- var edges = new THREE . EdgesGeometry ( cube ) ;
254- var vertexShader = document . getElementById ( 'vertexShader' ) . textContent ;
255- var fragmentShader = document . getElementById ( 'fragmentShader' ) . textContent ;
256-
257- // wireframe using gl.TRIANGLES (interpreted as quads)
258-
259- var attributesQuads = { center : { type : 'v4' , boundTo : 'faceVertices' , value : [ ] } } ;
260- var valuesQuads = attributesQuads . center . value ;
261-
262- setupAttributes ( cube , valuesQuads ) ;
263- cubes_data = processCubes ( data ) ;
264-
265- cubes_data . forEach ( function ( cube_data ) {
266- var mesh = newMesh ( cube_data , cube , material ) ;
267- group . add ( mesh ) ;
268- mesh = newMesh ( cube_data , edges , line_material ) ;
269- group . add ( mesh ) ;
270- } ) ;
271-
272-
273- /* var shape = new THREE.Shape(points); */
274-
275- ideal = new THREE . Line ( geometry , line_material ) ;
276- group . add ( ideal ) ;
277- /* geometry = new THREE.CubeGeometry(1,1,1); */
278- /* cube = new THREE.Mesh(geometry, material); */
279-
280- maxX = Math . max ( ...cubes_data . map ( d => d [ 2 ] ) ) ;
281- maxY = Math . max ( ...cubes_data . map ( d => d [ 0 ] ) ) ;
282- maxZ = Math . max ( ...cubes_data . map ( d => d [ 1 ] ) ) ;
283-
284- var lwidth = 3 ;
285- var lineMaterial = new THREE . LineBasicMaterial ( { color : 0x044000 , opacity : 0.8 , linewidth : lwidth } ) ;
286-
287- var lineGeometry = new THREE . Geometry ( ) ;
288- lineGeometry . vertices . push ( new THREE . Vector3 ( - 1 , - 1 , - 1 ) ) ;
289- lineGeometry . vertices . push ( new THREE . Vector3 ( - 1 , - 1 , maxX + 3 ) ) ;
290- var line = new THREE . Line ( lineGeometry , lineMaterial ) ;
291- group . add ( line ) ;
292- lineMaterial = new THREE . LineBasicMaterial ( { color : 0xAA0000 , opacity : 0.8 , linewidth : lwidth } ) ;
293- lineGeometry = new THREE . Geometry ( ) ;
294- lineGeometry . vertices . push ( new THREE . Vector3 ( - 1 , - 1 , - 1 ) ) ;
295- lineGeometry . vertices . push ( new THREE . Vector3 ( maxY + 3 , - 1 , - 1 ) ) ;
296- line = new THREE . Line ( lineGeometry , lineMaterial ) ;
297- group . add ( line ) ;
298- lineMaterial = new THREE . LineBasicMaterial ( { color : 0x0000DD , opacity : 0.8 , linewidth : lwidth } ) ;
299- lineGeometry = new THREE . Geometry ( ) ;
300- lineGeometry . vertices . push ( new THREE . Vector3 ( - 1 , - 1 , - 1 ) ) ;
301- lineGeometry . vertices . push ( new THREE . Vector3 ( - 1 , maxZ + 3 , - 1 ) ) ;
302- line = new THREE . Line ( lineGeometry , lineMaterial ) ;
303- group . add ( line ) ;
304- /* lineGeometry.vertices.push(new THREE.Vector3(10, 0, 0)); */
305-
306- var line = new THREE . Line ( lineGeometry , lineMaterial ) ;
307- group . add ( line ) ;
308- scene . add ( group ) ;
309- /* camera.position.z = 5; */
310-
311- document . addEventListener ( 'mousedown' , onDocumentMouseDown , false ) ;
312- document . addEventListener ( 'touchstart' , onDocumentTouchStart , false ) ;
313- document . addEventListener ( 'touchmove' , onDocumentTouchMove , false ) ;
314- document . addEventListener ( 'mousewheel' , onMouseWheel , false ) ;
315-
316- //
317-
318- window . addEventListener ( 'resize' , onWindowResize , false ) ;
319- }
320-
321- function setupAttributes ( geometry , values ) {
322-
323- for ( var f = 0 ; f < geometry . faces . length ; f ++ ) {
324-
325- var face = geometry . faces [ f ] ;
326-
327- if ( face instanceof THREE . Face3 ) {
328-
329- values [ f ] = [ new THREE . Vector4 ( 1 , 0 , 0 , 0 ) , new THREE . Vector4 ( 0 , 1 , 0 , 0 ) , new THREE . Vector4 ( 0 , 0 , 1 , 0 ) ] ;
330-
331- } else {
332-
333- values [ f ] = [ new THREE . Vector4 ( 1 , 0 , 0 , 1 ) , new THREE . Vector4 ( 1 , 1 , 0 , 1 ) , new THREE . Vector4 ( 0 , 1 , 0 , 1 ) , new THREE . Vector4 ( 0 , 0 , 0 , 1 ) ] ;
334-
335- }
336-
337- }
338-
339- }
340-
341-
342- function animate ( ) {
343- requestAnimationFrame ( animate ) ;
344-
345- render ( ) ;
346- }
347-
348- function render ( ) {
349-
350- group . rotation . x = group . rotation . x += ( targetXRotation - group . rotation . x ) * 0.05 ;
351- group . rotation . y = group . rotation . y += ( targetYRotation - group . rotation . y ) * 0.05 ;
352-
353- renderer . render ( scene , camera ) ;
354-
355- }
356-
357- init ( ) ;
358- animate ( ) ;
359- function onWindowResize ( ) {
360-
361- windowHalfX = window . innerWidth / 2 ;
362- windowHalfY = window . innerHeight / 2 ;
363-
364- camera . aspect = window . innerWidth / window . innerHeight ;
365- camera . updateProjectionMatrix ( ) ;
366-
367- renderer . setSize ( window . innerWidth , window . innerHeight ) ;
368-
369- }
370-
371- //
372-
373- function onDocumentMouseDown ( event ) {
374-
375- //event.preventDefault();
376-
377- document . addEventListener ( 'mousemove' , onDocumentMouseMove , false ) ;
378- document . addEventListener ( 'mouseup' , onDocumentMouseUp , false ) ;
379- document . addEventListener ( 'mouseout' , onDocumentMouseOut , false ) ;
380-
381- mouseXOnMouseDown = event . clientX - windowHalfX ;
382- mouseYOnMouseDown = event . clientY - windowHalfY ;
383- targetYRotationOnMouseDown = targetYRotation ;
384- targetXRotationOnMouseDown = targetXRotation ;
385-
386- }
387-
388- function onDocumentMouseMove ( event ) {
389-
390- mouseX = event . clientX - windowHalfX ;
391- mouseY = event . clientY - windowHalfY ;
392-
393- targetYRotation = targetYRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.02 ;
394- targetXRotation = targetXRotationOnMouseDown + ( mouseY - mouseYOnMouseDown ) * 0.02 ;
395-
396- }
397-
398- function onDocumentMouseUp ( event ) {
399-
400- document . removeEventListener ( 'mousemove' , onDocumentMouseMove , false ) ;
401- document . removeEventListener ( 'mouseup' , onDocumentMouseUp , false ) ;
402- document . removeEventListener ( 'mouseout' , onDocumentMouseOut , false ) ;
403- }
404-
405- function onDocumentMouseOut ( event ) {
406-
407- document . removeEventListener ( 'mousemove' , onDocumentMouseMove , false ) ;
408- document . removeEventListener ( 'mouseup' , onDocumentMouseUp , false ) ;
409- document . removeEventListener ( 'mouseout' , onDocumentMouseOut , false ) ;
410- }
411-
412- function onDocumentTouchStart ( event ) {
413-
414- if ( event . touches . length == 1 ) {
415-
416- event . preventDefault ( ) ;
417-
418- mouseXOnMouseDown = event . touches [ 0 ] . pageX - windowHalfX ;
419- targetRotationOnMouseDown = targetRotation ;
420-
421- }
422- }
423-
424- function onDocumentTouchMove ( event ) {
425-
426- if ( event . touches . length == 1 ) {
427-
428- event . preventDefault ( ) ;
429-
430- mouseX = event . touches [ 0 ] . pageX - windowHalfX ;
431- targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.05 ;
432-
433- }
434- }
435-
436- function onMouseWheel ( event ) {
437- event = event ? event : window . event ;
438- var wheelData = event . detail ? event . detail : event . wheelDelta ;
439- console . log ( event ) ;
440-
441- /* if ( event.touches.length == 1 ) { */
442-
443- /* event.preventDefault(); */
444-
445- /* mouseX = event.touches[ 0 ].pageX - windowHalfX; */
446- /* targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.05; */
447-
448- /* } */
449- }
450-
451- </ script >
45279</ body >
45380</ html >
0 commit comments