|
@@ -57,8 +57,9 @@
|
|
|
|
|
|
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
|
|
|
|
|
|
- var line, wireframe, renderer, scene, camera, controls;
|
|
|
- var line1, wireframe1;
|
|
|
+ var line, renderer, scene, camera, controls;
|
|
|
+ var line1;
|
|
|
+ var matLine, matLineBasic, matLineDashed;
|
|
|
var stats;
|
|
|
var gui;
|
|
|
|
|
@@ -80,7 +81,7 @@
|
|
|
scene = new THREE.Scene();
|
|
|
|
|
|
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 1000 );
|
|
|
- camera.position.set( -40, 0, 60 );
|
|
|
+ camera.position.set( - 40, 0, 60 );
|
|
|
|
|
|
controls = new THREE.OrbitControls( camera, renderer.domElement );
|
|
|
controls.minDistance = 10;
|
|
@@ -115,16 +116,18 @@
|
|
|
geometry.setPositions( positions );
|
|
|
geometry.setColors( colors );
|
|
|
|
|
|
- var material = new THREE.LineMaterial( {
|
|
|
+ matLine = new THREE.LineMaterial( {
|
|
|
|
|
|
color: 0xffffff,
|
|
|
- linewidth: 10, // in pixels
|
|
|
+ linewidth: 5, // in pixels
|
|
|
vertexColors: THREE.VertexColors,
|
|
|
//resolution: // to be set by renderer, eventually
|
|
|
+ dashed: false
|
|
|
|
|
|
} );
|
|
|
|
|
|
- line = new THREE.Line2( geometry, material );
|
|
|
+ line = new THREE.Line2( geometry, matLine );
|
|
|
+ line.computeLineDistances();
|
|
|
line.scale.set( 1, 1, 1 );
|
|
|
scene.add( line );
|
|
|
|
|
@@ -135,44 +138,14 @@
|
|
|
geo.addAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) );
|
|
|
geo.addAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) );
|
|
|
|
|
|
- var mat = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
|
|
|
+ matLineBasic = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
|
|
|
+ matLineDashed = new THREE.LineDashedMaterial( { vertexColors: THREE.VertexColors, scale: 2, dashSize: 1, gapSize: 1 } );
|
|
|
|
|
|
- line1 = new THREE.Line( geo, mat );
|
|
|
+ line1 = new THREE.Line( geo, matLineBasic );
|
|
|
+ line1.computeLineDistances();
|
|
|
line1.visible = false;
|
|
|
scene.add( line1 );
|
|
|
|
|
|
-
|
|
|
- // THREE.Wireframe ( WireframeGeometry2, LineMaterial )
|
|
|
-
|
|
|
- //var geo = new THREE.BoxBufferGeometry( 16, 16, 4, 2, 2, 1 );
|
|
|
- //var geo = new THREE.IcosahedronBufferGeometry( 8, 0 );
|
|
|
- var geo = new THREE.PlaneBufferGeometry( 16, 16, 2, 2 );
|
|
|
-
|
|
|
- var geometry = new THREE.WireframeGeometry2( geo );
|
|
|
-
|
|
|
- var material = new THREE.LineMaterial( {
|
|
|
-
|
|
|
- color: 0x4080ff,
|
|
|
- linewidth: 10, // in pixels
|
|
|
- //resolution: // to be set by renderer, eventually
|
|
|
-
|
|
|
- } );
|
|
|
-
|
|
|
- wireframe = new THREE.Wireframe( geometry, material );
|
|
|
- wireframe.scale.set( 1, 1, 1 );
|
|
|
- scene.add( wireframe );
|
|
|
-
|
|
|
-
|
|
|
- // THREE.Line ( WireframeGeometry, LineBasicMaterial ) - rendered with gl.LINE
|
|
|
-
|
|
|
- geo = new THREE.WireframeGeometry( geo );
|
|
|
-
|
|
|
- var mat = new THREE.LineBasicMaterial( { color: 0x4080ff } );
|
|
|
-
|
|
|
- wireframe1 = new THREE.LineSegments( geo, mat );
|
|
|
- wireframe1.visible = false;
|
|
|
- scene.add( wireframe1 );
|
|
|
-
|
|
|
//
|
|
|
|
|
|
window.addEventListener( 'resize', onWindowResize, false );
|
|
@@ -203,13 +176,10 @@
|
|
|
|
|
|
stats.update();
|
|
|
|
|
|
- wireframe.geometry.maxInstancedCount = Math.floor( Date.now() / 1000 ) % wireframe.geometry.index.count - 1; // why - 1 needed ?
|
|
|
-
|
|
|
// main scene
|
|
|
|
|
|
// renderer will set this eventually
|
|
|
- line.material.resolution.set( window.innerWidth, window.innerHeight );
|
|
|
- wireframe.material.resolution.set( window.innerWidth, window.innerHeight );
|
|
|
+ matLine.resolution.set( window.innerWidth, window.innerHeight );
|
|
|
|
|
|
renderer.setViewport( 0, 0, window.innerWidth, window.innerHeight );
|
|
|
|
|
@@ -218,8 +188,7 @@
|
|
|
// inset scene
|
|
|
|
|
|
// renderer will set this eventually
|
|
|
- //line.material.resolution.set( insetWidth, insetHeight );
|
|
|
- //wireframe.material.resolution.set( insetWidth, insetHeight );
|
|
|
+ //matLine.resolution.set( insetWidth, insetHeight ); // not sure what behavior we want here...
|
|
|
|
|
|
renderer.clearDepth(); // important!
|
|
|
|
|
@@ -243,7 +212,10 @@
|
|
|
|
|
|
var param = {
|
|
|
'line type': 0,
|
|
|
- 'line width': 10
|
|
|
+ 'width (px)': 5,
|
|
|
+ 'dashed': false,
|
|
|
+ 'dash scale': 1,
|
|
|
+ 'dash / gap': 1
|
|
|
};
|
|
|
|
|
|
|
|
@@ -253,19 +225,15 @@
|
|
|
|
|
|
case '0':
|
|
|
line.visible = true;
|
|
|
- wireframe.visible = true;
|
|
|
|
|
|
line1.visible = false;
|
|
|
- wireframe1.visible = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case '1':
|
|
|
line.visible = false;
|
|
|
- wireframe.visible = false;
|
|
|
|
|
|
line1.visible = true;
|
|
|
- wireframe1.visible = true;
|
|
|
|
|
|
break;
|
|
|
|
|
@@ -273,10 +241,65 @@
|
|
|
|
|
|
} );
|
|
|
|
|
|
- gui.add( param, 'line width', 1, 40, 1 ).onChange( function ( val ) {
|
|
|
+ gui.add( param, 'width (px)', 1, 10, 1 ).onChange( function ( val ) {
|
|
|
+
|
|
|
+ matLine.linewidth = val;
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ gui.add( param, 'dashed' ).onChange( function ( val ) {
|
|
|
+
|
|
|
+ matLine.dashed = val;
|
|
|
|
|
|
- line.material.linewidth = val;
|
|
|
- wireframe.material.linewidth = val;
|
|
|
+ // dashed is implemented as a defines -- not as a uniform. this could be changed.
|
|
|
+ // ... or LineDashedMaterial could be implemented as a separate material
|
|
|
+ // temporary hack - renderer should do this eventually
|
|
|
+ if ( val ) matLine.defines.USE_DASH = ""; else delete matLine.defines.USE_DASH;
|
|
|
+ matLine.needsUpdate = true;
|
|
|
+
|
|
|
+ line1.material = val ? matLineDashed : matLineBasic;
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ gui.add( param, 'dash scale', 0.5, 2, 0.1 ).onChange( function ( val ) {
|
|
|
+
|
|
|
+ matLine.dashScale = val;
|
|
|
+ matLineDashed.scale = val;
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ gui.add( param, 'dash / gap', { '2 : 1': 0, '1 : 1': 1, '1 : 2': 2 } ).onChange( function ( val ) {
|
|
|
+
|
|
|
+ switch ( val ) {
|
|
|
+
|
|
|
+ case '0':
|
|
|
+ matLine.dashSize = 2;
|
|
|
+ matLine.gapSize = 1;
|
|
|
+
|
|
|
+ matLineDashed.dashSize = 2;
|
|
|
+ matLineDashed.gapSize = 1;
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case '1':
|
|
|
+ matLine.dashSize = 1;
|
|
|
+ matLine.gapSize = 1;
|
|
|
+
|
|
|
+ matLineDashed.dashSize = 1;
|
|
|
+ matLineDashed.gapSize = 1;
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case '2':
|
|
|
+ matLine.dashSize = 1;
|
|
|
+ matLine.gapSize = 2;
|
|
|
+
|
|
|
+ matLineDashed.dashSize = 1;
|
|
|
+ matLineDashed.gapSize = 2;
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
} );
|
|
|
|