From 7e86519872c6f46c8f1d85b1e16a369abe641de0 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 4 Feb 2015 13:17:31 -0500 Subject: [PATCH 1/7] Change graph visibility to a property --- support/client/lib/vwf/model/graphtool.js | 31 +++++++++---------- .../vwf.example.com/graphtool/graph.vwf.yaml | 9 +----- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/support/client/lib/vwf/model/graphtool.js b/support/client/lib/vwf/model/graphtool.js index 791c6348d..69a19418e 100644 --- a/support/client/lib/vwf/model/graphtool.js +++ b/support/client/lib/vwf/model/graphtool.js @@ -47,6 +47,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili "yAxisVisible": undefined, "zAxisVisible": undefined, "gridVisible": undefined, + "graphVisible": undefined, "axisOpacity": undefined, "gridOpacity": undefined, "renderTop": undefined @@ -209,7 +210,12 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili case "yAxisVisible": case "zAxisVisible": case "gridVisible": - setGraphVisibility( node, true ); + if ( propertyValue ) { + this.kernel.setProperty( nodeID, "graphVisible", true ); + } + break; + case "graphVisible": + setGraphVisibility( node, propertyValue ); break; case "graphScale": redrawGraph( node ); @@ -264,15 +270,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili callingMethod: function( nodeID, methodName, methodParameters, methodValue ) { var node; - if ( this.state.graphs[ nodeID ] ) { - node = this.state.graphs[ nodeID ]; - - if ( methodName === "setGraphVisibility" ) { - var visible = methodParameters[0]; - setGraphVisibility( node, visible ); - } - - } else if ( this.state.objects[ nodeID ] ) { + if ( this.state.objects[ nodeID ] ) { node = this.state.objects[ nodeID ]; if ( methodName === "setGroupItemProperty" ) { @@ -391,6 +389,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili props.yAxisVisible, props.zAxisVisible, props.gridVisible, + props.graphVisible, props.axisOpacity, props.gridOpacity, props.renderTop @@ -541,7 +540,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } function generateGraph( graphScale, gridInterval, gridLineInterval, gridLength, xAxisVisible, - yAxisVisible, zAxisVisible, gridVisible, axisOpacity, gridOpacity, renderTop ) { + yAxisVisible, zAxisVisible, gridVisible, graphVisible, axisOpacity, gridOpacity, renderTop ) { var xAxis, yAxis, zAxis, gridX, gridY, axisLine; var thickness = 0.1; @@ -552,15 +551,15 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili xAxis = generateLine( graphScale, [ 1, 0, 0 ], -gridLength, gridLength, [ 255, 0, 0 ], axisOpacity, thickness, renderTop ); xAxis.name = "xAxis"; - xAxis.visible = xAxisVisible; + xAxis.visible = xAxisVisible && graphVisible; yAxis = generateLine( graphScale, [ 0, 1, 0 ], -gridLength, gridLength, [ 0, 0, 255 ], axisOpacity, thickness, renderTop ); yAxis.name = "yAxis"; - yAxis.visible = yAxisVisible; + yAxis.visible = yAxisVisible && graphVisible; zAxis = generateLine( graphScale, [ 0, 0, 1 ], -gridLength, gridLength, [ 0, 255, 0 ], axisOpacity, thickness, renderTop ); zAxis.name = "zAxis"; - zAxis.visible = zAxisVisible; + zAxis.visible = zAxisVisible && graphVisible; if ( renderTop ) { xAxis.renderDepth = yAxis.renderDepth = zAxis.renderDepth = DEPTH_AXES; @@ -583,11 +582,11 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili gridX = generateLine( graphScale, [ 1, 0, 0 ], -gridLength, gridLength, [ 255, 255, 255 ], gridOpacity, thickness, renderTop ); gridX.position.set( 0, i, 0 ); - gridX.visible = gridVisible; + gridX.visible = gridVisible && graphVisible; gridY = generateLine( graphScale, [ 0, 1, 0 ], -gridLength, gridLength, [ 255, 255, 255 ], gridOpacity, thickness, renderTop ); gridY.position.set( i, 0, 0 ); - gridY.visible = gridVisible; + gridY.visible = gridVisible && graphVisible; if ( renderTop ) { gridX.renderDepth = gridY.renderDepth = DEPTH_GRID; diff --git a/support/proxy/vwf.example.com/graphtool/graph.vwf.yaml b/support/proxy/vwf.example.com/graphtool/graph.vwf.yaml index 2ba83d0b6..7612e91f5 100644 --- a/support/proxy/vwf.example.com/graphtool/graph.vwf.yaml +++ b/support/proxy/vwf.example.com/graphtool/graph.vwf.yaml @@ -9,18 +9,11 @@ properties: yAxisVisible: undefined zAxisVisible: undefined gridVisible: undefined + graphVisible: undefined axisOpacity: undefined gridOpacity: undefined renderTop: undefined - graphIsVisible$: true methods: - setGraphVisibility: - parameters: - - visible - body: | - this.graphIsVisible$ = visible; - toggleGraphVisibility: | - this.setGraphVisibility( !this.graphIsVisible$ ); graphLine: parameters: - axis From 99ce4c7026bff2f91f486a704f72cfb3e3273c9e Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 9 Sep 2015 16:48:24 -0400 Subject: [PATCH 2/7] Add pointline --- support/client/lib/vwf/model/graphtool.js | 89 ++++++++++++++++++- .../vwf.example.com/graphtool/graph.vwf.yaml | 28 ++++++ .../graphtool/graphpointline.vwf.yaml | 14 +++ 3 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 support/proxy/vwf.example.com/graphtool/graphpointline.vwf.yaml diff --git a/support/client/lib/vwf/model/graphtool.js b/support/client/lib/vwf/model/graphtool.js index 69a19418e..4a2267b25 100644 --- a/support/client/lib/vwf/model/graphtool.js +++ b/support/client/lib/vwf/model/graphtool.js @@ -86,6 +86,15 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili "renderTop": undefined }; break; + case "pointline": + node.objectProperties = { + "points": undefined, + "color": undefined, + "opacity": undefined, + "lineThickness": undefined, + "renderTop": undefined + }; + break; case "plane": node.objectProperties = { "origin": undefined, @@ -252,10 +261,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili // -- gettingProperty ---------------------------------------------------------------------- gettingProperty: function( nodeID, propertyName, propertyValue ) { - var node = this.state.objects[ nodeID ]; - - if ( node ) { - } }, // -- creatingMethod ----------------------------------------------------------------------- @@ -350,6 +355,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili for ( var i = 0; i < prototypes.length && !foundObject; i++ ) { foundObject = ( prototypes[i] == "http://vwf.example.com/graphtool/graphline.vwf" ) || ( prototypes[i] == "http://vwf.example.com/graphtool/graphlinefunction.vwf" ) || + ( prototypes[i] == "http://vwf.example.com/graphtool/graphpointline.vwf" ) || ( prototypes[i] == "http://vwf.example.com/graphtool/graphplane.vwf" ) || ( prototypes[i] == "http://vwf.example.com/graphtool/graphgroup.vwf" ); } @@ -366,6 +372,8 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili return "line"; } else if ( prototypes[i] == "http://vwf.example.com/graphtool/graphlinefunction.vwf" ) { return "function"; + } else if ( prototypes[i] == "http://vwf.example.com/graphtool/graphpointline.vwf" ) { + return "pointline"; } else if ( prototypes[i] == "http://vwf.example.com/graphtool/graphplane.vwf" ) { return "plane"; } else if ( prototypes[i] == "http://vwf.example.com/graphtool/graphgroup.vwf" ) { @@ -434,6 +442,17 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili ); break; + case "pointline": + obj = generatePointLine( + graphScale, + props.points, + props.color, + props.opacity, + props.lineThickness, + props.renderTop + ); + break; + case "plane": obj = generatePlane( graphScale, @@ -730,6 +749,68 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } + function generatePointLine( graphScale, linepoints, color, opacity, thickness, renderTop ) { + var geometry = new THREE.Geometry(); + var points = new Array(); + var point, direction, planePoints, i, j; + + for ( i = 0; i < linepoints.length; i++ ) { + point = new THREE.Vector3( + linepoints[ i ][ 0 ], + linepoints[ i ][ 1 ], + linepoints[ i ][ 2 ] + ); + if ( i === linepoints.length - 1 ) { + direction = point.clone(); + } else { + direction = new THREE.Vector3( + linepoints[ i + 1 ][ 0 ], + linepoints[ i + 1 ][ 1 ], + linepoints[ i + 1 ][ 2 ] + ); + } + if ( i === 0 ) { + direction.sub( point.clone() ); + } else { + direction.sub( new THREE.Vector3( + linepoints[ i - 1 ][ 0 ], + linepoints[ i - 1 ][ 1 ], + linepoints[ i - 1 ][ 2 ] + ) ); + } + var planePoints = generateLineVertices( direction, point, thickness / 2 ); + for ( j = 0; j < planePoints.length; j++ ) { + points.push( planePoints[ j ] ); + } + } + + geometry.vertices = points; + + for ( i = 0; i < points.length; i++ ) { + if ( points[ i + 4 ] !== undefined ) { + geometry.faces.push( new THREE.Face3( i, i + 4, i + 1 ) ); + geometry.faces.push( new THREE.Face3( i, i + 3, i + 4 ) ); + } + } + + var last = points.length - 1; + geometry.faces.push( new THREE.Face3( 0, 1, 2 ) ); + geometry.faces.push( new THREE.Face3( 0, 2, 3 ) ); + geometry.faces.push( new THREE.Face3( last, last - 1, last - 3 ) ); + geometry.faces.push( new THREE.Face3( last - 1, last - 2, last - 3 ) ); + + var transparent = renderTop || opacity < 1; + var vwfColor = new utility.color( color ); + color = vwfColor.getHex(); + var meshMaterial = new THREE.MeshBasicMaterial( + { "color": color, "transparent": transparent, "opacity": opacity, "depthTest": !renderTop } + ); + var mesh = new THREE.Mesh( geometry, meshMaterial ); + mesh.renderDepth = renderTop ? DEPTH_OBJECTS : null; + + return mesh; + } + function generatePlane( graphScale, origin, normal, rotationAngle, size, color, opacity, doubleSided, renderTop ) { var geometry = new THREE.Geometry(); diff --git a/support/proxy/vwf.example.com/graphtool/graph.vwf.yaml b/support/proxy/vwf.example.com/graphtool/graph.vwf.yaml index 7612e91f5..abe74a12e 100644 --- a/support/proxy/vwf.example.com/graphtool/graph.vwf.yaml +++ b/support/proxy/vwf.example.com/graphtool/graph.vwf.yaml @@ -78,6 +78,33 @@ methods: } name = name || "function" + this.functioncount++; this.children.create( name, functionDef ); + graphPointLine: + parameters: + - points + - color + - opacity + - lineThickness + - renderTop + - name + - optionalProperties + body: | + var pointLineDef = { + "extends": "http://vwf.example.com/graphtool/graphpointline.vwf", + "properties": { + "points": points, + "color": color, + "opacity": opacity, + "lineThickness": lineThickness, + "renderTop": renderTop + } + } + if ( optionalProperties ) { + for ( var key in optionalProperties ) { + pointLineDef.properties[ key ] = optionalProperties[ key ]; + } + } + name = name || "pointLine" + this.pointLineCount++; + this.children.create( name, pointLineDef ); graphPlane: parameters: - origin @@ -135,5 +162,6 @@ methods: scripts: | this.lineCount = 0; this.functioncount = 0; + this.pointLineCount = 0; this.planecount = 0; this.groupcount = 0; \ No newline at end of file diff --git a/support/proxy/vwf.example.com/graphtool/graphpointline.vwf.yaml b/support/proxy/vwf.example.com/graphtool/graphpointline.vwf.yaml new file mode 100644 index 000000000..9f8cf41cd --- /dev/null +++ b/support/proxy/vwf.example.com/graphtool/graphpointline.vwf.yaml @@ -0,0 +1,14 @@ +--- +extends: http://vwf.example.com/node3.vwf +properties: + points: undefined + color: undefined + opacity: undefined + lineThickness: undefined + renderTop: undefined +methods: + addPoint: + parameters: + - x + - y + - z From ff960c0e74e2f9947614748984241d87bf615aff Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Mon, 14 Sep 2015 15:24:12 -0400 Subject: [PATCH 3/7] Add body to add point method --- support/client/lib/vwf/model/graphtool.js | 35 +++++-------------- .../graphtool/graphpointline.vwf.yaml | 4 +++ 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/support/client/lib/vwf/model/graphtool.js b/support/client/lib/vwf/model/graphtool.js index 4a2267b25..91d401988 100644 --- a/support/client/lib/vwf/model/graphtool.js +++ b/support/client/lib/vwf/model/graphtool.js @@ -203,17 +203,11 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili settingProperty: function( nodeID, propertyName, propertyValue ) { var node; - if ( this.state.graphs[ nodeID ] ) { - node = this.state.graphs[ nodeID ]; - if ( node.graphProperties.hasOwnProperty( propertyName ) ) { - node.graphProperties[ propertyName ] = propertyValue; - if ( node.initialized ) { - switch ( propertyName ) { case "xAxisVisible": case "yAxisVisible": @@ -234,27 +228,16 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili redrawGraph( node ); break; } - } - } - } else if ( this.state.objects[ nodeID ] ) { - node = this.state.objects[ nodeID ]; - if ( node.objectProperties.hasOwnProperty( propertyName ) ) { - node.objectProperties[ propertyName ] = propertyValue; - if ( node.initialized ) { - redrawObject( node ); - } - } - } }, @@ -756,26 +739,26 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili for ( i = 0; i < linepoints.length; i++ ) { point = new THREE.Vector3( - linepoints[ i ][ 0 ], - linepoints[ i ][ 1 ], - linepoints[ i ][ 2 ] + linepoints[ i ][ 0 ] * graphScale, + linepoints[ i ][ 1 ] * graphScale, + linepoints[ i ][ 2 ] * graphScale ); if ( i === linepoints.length - 1 ) { direction = point.clone(); } else { direction = new THREE.Vector3( - linepoints[ i + 1 ][ 0 ], - linepoints[ i + 1 ][ 1 ], - linepoints[ i + 1 ][ 2 ] + linepoints[ i + 1 ][ 0 ] * graphScale, + linepoints[ i + 1 ][ 1 ] * graphScale, + linepoints[ i + 1 ][ 2 ] * graphScale ); } if ( i === 0 ) { direction.sub( point.clone() ); } else { direction.sub( new THREE.Vector3( - linepoints[ i - 1 ][ 0 ], - linepoints[ i - 1 ][ 1 ], - linepoints[ i - 1 ][ 2 ] + linepoints[ i - 1 ][ 0 ] * graphScale, + linepoints[ i - 1 ][ 1 ] * graphScale, + linepoints[ i - 1 ][ 2 ] * graphScale ) ); } var planePoints = generateLineVertices( direction, point, thickness / 2 ); diff --git a/support/proxy/vwf.example.com/graphtool/graphpointline.vwf.yaml b/support/proxy/vwf.example.com/graphtool/graphpointline.vwf.yaml index 9f8cf41cd..37f270ba0 100644 --- a/support/proxy/vwf.example.com/graphtool/graphpointline.vwf.yaml +++ b/support/proxy/vwf.example.com/graphtool/graphpointline.vwf.yaml @@ -12,3 +12,7 @@ methods: - x - y - z + body: | + var points = this.points.slice(); + points.push( [ x, y, z ] ); + this.points = points; From 8873f49e9deff006157b6ca4abe07b31ed8f4858 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Tue, 15 Sep 2015 16:33:04 -0400 Subject: [PATCH 4/7] Add looping property --- support/client/lib/vwf/model/graphtool.js | 23 ++++++++++++++----- .../graphtool/graphpointline.vwf.yaml | 3 ++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/support/client/lib/vwf/model/graphtool.js b/support/client/lib/vwf/model/graphtool.js index 91d401988..2d2b56fcc 100644 --- a/support/client/lib/vwf/model/graphtool.js +++ b/support/client/lib/vwf/model/graphtool.js @@ -92,6 +92,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili "color": undefined, "opacity": undefined, "lineThickness": undefined, + "isLoop": undefined, "renderTop": undefined }; break; @@ -432,6 +433,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili props.color, props.opacity, props.lineThickness, + props.isLoop, props.renderTop ); break; @@ -732,7 +734,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } - function generatePointLine( graphScale, linepoints, color, opacity, thickness, renderTop ) { + function generatePointLine( graphScale, linepoints, color, opacity, thickness, isLoop, renderTop ) { var geometry = new THREE.Geometry(); var points = new Array(); var point, direction, planePoints, i, j; @@ -773,14 +775,23 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili if ( points[ i + 4 ] !== undefined ) { geometry.faces.push( new THREE.Face3( i, i + 4, i + 1 ) ); geometry.faces.push( new THREE.Face3( i, i + 3, i + 4 ) ); + } else if ( isLoop ) { + var i4, i3, i1; + i4 = i + 4 >= points.length ? i + 4 - points.length : i + 4; + i3 = i + 3 >= points.length ? i + 3 - points.length : i + 3; + i1 = i + 1 >= points.length ? i + 1 - points.length : i + 1; + geometry.faces.push( new THREE.Face3( i, i4, i1 ) ); + geometry.faces.push( new THREE.Face3( i, i3, i4 ) ); } } - var last = points.length - 1; - geometry.faces.push( new THREE.Face3( 0, 1, 2 ) ); - geometry.faces.push( new THREE.Face3( 0, 2, 3 ) ); - geometry.faces.push( new THREE.Face3( last, last - 1, last - 3 ) ); - geometry.faces.push( new THREE.Face3( last - 1, last - 2, last - 3 ) ); + if ( !isLoop ) { + var last = points.length - 1; + geometry.faces.push( new THREE.Face3( 0, 1, 2 ) ); + geometry.faces.push( new THREE.Face3( 0, 2, 3 ) ); + geometry.faces.push( new THREE.Face3( last, last - 1, last - 3 ) ); + geometry.faces.push( new THREE.Face3( last - 1, last - 2, last - 3 ) ); + } var transparent = renderTop || opacity < 1; var vwfColor = new utility.color( color ); diff --git a/support/proxy/vwf.example.com/graphtool/graphpointline.vwf.yaml b/support/proxy/vwf.example.com/graphtool/graphpointline.vwf.yaml index 37f270ba0..507356960 100644 --- a/support/proxy/vwf.example.com/graphtool/graphpointline.vwf.yaml +++ b/support/proxy/vwf.example.com/graphtool/graphpointline.vwf.yaml @@ -5,6 +5,7 @@ properties: color: undefined opacity: undefined lineThickness: undefined + isLoop: undefined renderTop: undefined methods: addPoint: @@ -15,4 +16,4 @@ methods: body: | var points = this.points.slice(); points.push( [ x, y, z ] ); - this.points = points; + this.points = points; \ No newline at end of file From 32a76c0b6add032483e6d9a50ecf84b197bb9e8d Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Wed, 16 Sep 2015 14:51:56 -0400 Subject: [PATCH 5/7] Add loop logic for line tangents --- support/client/lib/vwf/model/graphtool.js | 26 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/support/client/lib/vwf/model/graphtool.js b/support/client/lib/vwf/model/graphtool.js index 2d2b56fcc..f7974f11d 100644 --- a/support/client/lib/vwf/model/graphtool.js +++ b/support/client/lib/vwf/model/graphtool.js @@ -737,16 +737,25 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili function generatePointLine( graphScale, linepoints, color, opacity, thickness, isLoop, renderTop ) { var geometry = new THREE.Geometry(); var points = new Array(); - var point, direction, planePoints, i, j; + var point, direction, planePoints, i, j, lng; + lng = linepoints.length; - for ( i = 0; i < linepoints.length; i++ ) { + for ( i = 0; i < lng; i++ ) { point = new THREE.Vector3( linepoints[ i ][ 0 ] * graphScale, linepoints[ i ][ 1 ] * graphScale, linepoints[ i ][ 2 ] * graphScale ); - if ( i === linepoints.length - 1 ) { - direction = point.clone(); + if ( i === lng - 1 ) { + if ( isLoop ) { + direction = new THREE.Vector3( + linepoints[ 0 ][ 0 ] * graphScale, + linepoints[ 0 ][ 1 ] * graphScale, + linepoints[ 0 ][ 2 ] * graphScale + ) + } else { + direction = point.clone(); + } } else { direction = new THREE.Vector3( linepoints[ i + 1 ][ 0 ] * graphScale, @@ -755,6 +764,13 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili ); } if ( i === 0 ) { + if ( isLoop ) { + direction.sub( new THREE.Vector3( + linepoints[ lng - 1 ][ 0 ] * graphScale, + linepoints[ lng - 1 ][ 1 ] * graphScale, + linepoints[ lng - 1 ][ 2 ] * graphScale + ) ); + } direction.sub( point.clone() ); } else { direction.sub( new THREE.Vector3( @@ -797,7 +813,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili var vwfColor = new utility.color( color ); color = vwfColor.getHex(); var meshMaterial = new THREE.MeshBasicMaterial( - { "color": color, "transparent": transparent, "opacity": opacity, "depthTest": !renderTop } + { "color": color, "transparent": transparent, "opacity": opacity, "depthTest": !renderTop, "wireframe": true } ); var mesh = new THREE.Mesh( geometry, meshMaterial ); mesh.renderDepth = renderTop ? DEPTH_OBJECTS : null; From 8830c03c69851e323f16cad20063bf685ec379d0 Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Sat, 26 Sep 2015 18:52:42 -0400 Subject: [PATCH 6/7] Calculate uvs on lines to allow shader materials --- support/client/lib/vwf/model/graphtool.js | 83 +++++++++++++++++++---- 1 file changed, 68 insertions(+), 15 deletions(-) diff --git a/support/client/lib/vwf/model/graphtool.js b/support/client/lib/vwf/model/graphtool.js index f7974f11d..82ec3224e 100644 --- a/support/client/lib/vwf/model/graphtool.js +++ b/support/client/lib/vwf/model/graphtool.js @@ -120,6 +120,9 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili node.initialized = false; + } else if ( protos && isMaterial( protos ) && this.state.objects[ nodeID ] ) { + var obj = this.state.objects[ nodeID ]; + obj.materialObject = getThreeJSModel().state.nodes[ childID ]; } }, @@ -129,19 +132,14 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili childSource, childType, childIndex, childName ) { var node; - if ( this.state.graphs[ childID ] ) { - node = this.state.graphs[ childID ]; createGraph( node ); node.initialized = true; - } else if ( this.state.objects[ childID ] ) { - node = this.state.objects[ childID ]; createObject( node ); node.initialized = true; - } }, @@ -149,7 +147,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili deletingNode: function( nodeID ) { - if( nodeID ) { + if ( nodeID ) { var childNode = this.state.objects[ nodeID ]; if( childNode ) { var threeObject = childNode.threeObject; @@ -234,7 +232,11 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } else if ( this.state.objects[ nodeID ] ) { node = this.state.objects[ nodeID ]; if ( node.objectProperties.hasOwnProperty( propertyName ) ) { - node.objectProperties[ propertyName ] = propertyValue; + switch ( propertyName ) { + default: + node.objectProperties[ propertyName ] = propertyValue; + break; + } if ( node.initialized ) { redrawObject( node ); } @@ -348,6 +350,18 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili return foundObject; } + function isMaterial( prototypes ) { + var foundMaterial = false; + if ( prototypes ) { + for ( var i = 0; i < prototypes.length && !foundMaterial; i++ ) { + foundMaterial = ( prototypes[i] == "http://vwf.example.com/material.vwf" ) || + ( prototypes[i] == "http://vwf.example.com/shaderMaterial.vwf" ); + } + } + + return foundMaterial; + } + function getObjectType( prototypes ) { if ( prototypes ) { @@ -434,6 +448,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili props.opacity, props.lineThickness, props.isLoop, + node.materialObject, props.renderTop ); break; @@ -485,6 +500,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili function redrawObject( obj ) { var oldObj = obj.threeObject.children[ 0 ]; + var material = oldObj.material; obj.threeObject.remove( oldObj ); if ( oldObj.children.length > 0 ) { disposeObject( oldObj ); @@ -660,6 +676,8 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili geometry.faces.push( new THREE.Face3( last, last - 1, last - 3 ) ); geometry.faces.push( new THREE.Face3( last - 1, last - 2, last - 3 ) ); + calcUVs( geometry ); + var transparent = renderTop || opacity < 1; var vwfColor = new utility.color( color ); color = vwfColor.getHex(); @@ -721,6 +739,8 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili geometry.faces.push( new THREE.Face3( last, last - 1, last - 3 ) ); geometry.faces.push( new THREE.Face3( last - 1, last - 2, last - 3 ) ); + calcUVs( geometry ); + var transparent = renderTop || opacity < 1; var vwfColor = new utility.color( color ); color = vwfColor.getHex(); @@ -734,7 +754,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } - function generatePointLine( graphScale, linepoints, color, opacity, thickness, isLoop, renderTop ) { + function generatePointLine( graphScale, linepoints, color, opacity, thickness, isLoop, material, renderTop ) { var geometry = new THREE.Geometry(); var points = new Array(); var point, direction, planePoints, i, j, lng; @@ -770,8 +790,9 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili linepoints[ lng - 1 ][ 1 ] * graphScale, linepoints[ lng - 1 ][ 2 ] * graphScale ) ); + } else { + direction.sub( point.clone() ); } - direction.sub( point.clone() ); } else { direction.sub( new THREE.Vector3( linepoints[ i - 1 ][ 0 ] * graphScale, @@ -809,13 +830,22 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili geometry.faces.push( new THREE.Face3( last - 1, last - 2, last - 3 ) ); } - var transparent = renderTop || opacity < 1; - var vwfColor = new utility.color( color ); - color = vwfColor.getHex(); - var meshMaterial = new THREE.MeshBasicMaterial( - { "color": color, "transparent": transparent, "opacity": opacity, "depthTest": !renderTop, "wireframe": true } + calcUVs( geometry ); + + var meshMaterial, vwfColor, transparent, mesh; + + if ( material && material.threeObject ) { + meshMaterial = material.threeObject.clone(); + } else { + transparent = renderTop || opacity < 1; + vwfColor = new utility.color( color ); + color = vwfColor.getHex(); + meshMaterial = new THREE.MeshBasicMaterial( + { "color": color, "transparent": transparent, "opacity": opacity, "depthTest": !renderTop } ); - var mesh = new THREE.Mesh( geometry, meshMaterial ); + } + + mesh = new THREE.Mesh( geometry, meshMaterial ); mesh.renderDepth = renderTop ? DEPTH_OBJECTS : null; return mesh; @@ -836,6 +866,8 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili geometry.faces.push( new THREE.Face3( 0, 1, 2 ) ); geometry.faces.push( new THREE.Face3( 0, 2, 3 ) ); + calcUVs( geometry ); + var transparent = renderTop || opacity < 1; var vwfColor = new utility.color( color ); color = vwfColor.getHex(); @@ -1090,4 +1122,25 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili } )(); } + function calcUVs( geometry ) { + geometry.computeBoundingBox(); + var max = geometry.boundingBox.max; + var min = geometry.boundingBox.min; + var offset = new THREE.Vector2( 0 - min.x, 0 - min.y ); + var range = new THREE.Vector2( max.x - min.x, max.y - min.y ); + geometry.faceVertexUvs[ 0 ] = []; + var faces = geometry.faces; + for ( var i = 0; i < geometry.faces.length ; i++ ) { + var v1 = geometry.vertices[ faces[ i ].a ]; + var v2 = geometry.vertices[ faces[ i ].b ]; + var v3 = geometry.vertices[ faces[ i ].c ]; + geometry.faceVertexUvs[0].push( [ + new THREE.Vector2( ( v1.x + offset.x ) / range.x , ( v1.y + offset.y ) / range.y ), + new THREE.Vector2( ( v2.x + offset.x ) / range.x , ( v2.y + offset.y ) / range.y ), + new THREE.Vector2( ( v3.x + offset.x ) / range.x , ( v3.y + offset.y ) / range.y ) + ] ); + } + geometry.uvsNeedUpdate = true; + } + } ); \ No newline at end of file From 87785f007c1380861c9dfb0acb4188303660c18b Mon Sep 17 00:00:00 2001 From: Brett Swift Date: Tue, 15 Dec 2015 17:06:34 -0500 Subject: [PATCH 7/7] Re-apply David's kernel changes --- support/client/lib/vwf/model/graphtool.js | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/support/client/lib/vwf/model/graphtool.js b/support/client/lib/vwf/model/graphtool.js index 82ec3224e..46add0f52 100644 --- a/support/client/lib/vwf/model/graphtool.js +++ b/support/client/lib/vwf/model/graphtool.js @@ -20,7 +20,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili self = this; this.state.graphs = {}; this.state.objects = {}; - this.state.kernel = this.kernel.kernel.kernel; }, // == Model API ============================================================================ @@ -31,8 +30,7 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili childSource, childType, childIndex, childName, callback /* ( ready ) */ ) { var node = undefined; - var kernel = this.state.kernel; - var protos = getPrototypes.call( this, kernel, childExtendsID ); + var protos = this.kernel.prototypes( childID ); if ( protos && isGraph( protos ) ) { @@ -307,18 +305,6 @@ define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utili return threejs; } - - function getPrototypes( kernel, extendsID ) { - var prototypes = []; - var id = extendsID; - - while ( id !== undefined ) { - prototypes.push( id ); - id = kernel.prototype( id ); - } - - return prototypes; - } function isGraph( prototypes ) {