Skip to content

Commit

Permalink
Add support for central line cutting and clipping.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-wu committed Mar 20, 2019
1 parent c398f23 commit ad66b62
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 122 deletions.
24 changes: 20 additions & 4 deletions src/modules/ScaffoldViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,27 @@ var ScaffoldViewer = function(typeAtStartUp) {
for (var i = 0; i < meshAllPartsDownloadedCallbacks.length;i++) {
meshAllPartsDownloadedCallbacks[i]();
}
if (csg) {
csg.allDownloadsCompletedCallback();
csg.updatePlane();

var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var data = JSON.parse(xmlhttp.responseText);
if (csg)
csg.enablePathCutting(data);
} else {
if (csg)
csg.enableStandardCutting();
}
if (csg) {
csg.allDownloadsCompletedCallback();
csg.updatePlane();
}
}
}
var finalURL = "./getCentralLine";
xmlhttp.open("GET", finalURL, true);
xmlhttp.send();
settingsChanged = false;
}
}
Expand All @@ -180,7 +197,6 @@ var ScaffoldViewer = function(typeAtStartUp) {
var argumentString = "meshtype=" + currentMeshType;
argumentString = addOptionsToURL(argumentString);
var finalURL = "./generator?" + argumentString;
console.log(argumentString);
_this.scene.loadMetadataURL(finalURL, itemDownloadCallback, allCompletedCallback);
meshChanged = true;
}
Expand Down
42 changes: 0 additions & 42 deletions src/shaders/cutHeart.vs

This file was deleted.

63 changes: 20 additions & 43 deletions src/shaders/cutHeart.fs → src/shaders/uvCutting.fs
Original file line number Diff line number Diff line change
@@ -1,56 +1,37 @@
varying vec3 colorValue;
varying vec3 vViewPosition;
varying vec3 vNormal;
uniform vec3 diffuse;
varying vec2 vUv;
uniform float progress;
uniform vec3 ambient;
uniform vec3 emissive;
uniform vec3 specular;
uniform vec3 diffuse;
uniform float shininess;
uniform vec3 ambientLightColor;
uniform vec3 directionalLightColor;
uniform vec3 directionalLightDirection;
uniform float surfaceAlpha;
uniform float min_x;
uniform float max_x;
uniform float min_y;
uniform float max_y;
uniform float min_z;
uniform float max_z;
varying vec3 modelPosition;
uniform int reverse;

void main(void) {
if (modelPosition.x > max_x)
{
discard;
}
if (modelPosition.x < min_x)
{
discard;
}
if (modelPosition.y > max_y)
{
discard;
}
if (modelPosition.y < min_y)
{
discard;
}
if (modelPosition.z > max_z)
{
discard;
}
if (modelPosition.z < min_z)
{
discard;
}

vec3 adjustDiffuse = diffuse;
#ifdef ALPHATEST
if ( gl_FragColor.a < ALPHATEST ) discard;
#endif
float pxielTimeStep = vUv.x;
if (reverse == 1)
{
if (pxielTimeStep > progress)
discard;
}
else
{
if (pxielTimeStep < progress)
discard;
}

vec3 normalScaling = vec3(1.0, 1.0, 1.0);
float specularStrength = 1.0;
vec3 normal = normalize( vNormal );


if (!gl_FrontFacing)
normal.z = -normal.z;
Expand All @@ -71,7 +52,7 @@ void main(void) {
#else
float dirDiffuseWeight = max( dotProduct, 0.0 );
#endif
dirDiffuse += adjustDiffuse * directionalLightColor * dirDiffuseWeight;
dirDiffuse += diffuse * directionalLightColor * dirDiffuseWeight;
vec3 dirHalfVector = normalize( dirVector + viewPosition );
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
float dirSpecularWeight = specularStrength * max( pow( dirDotNormalHalf, shininess ), 0.0 );
Expand All @@ -86,10 +67,6 @@ vec3 totalSpecular = vec3( 0.0 );
totalDiffuse += dirDiffuse;
totalSpecular += dirSpecular;
#endif
gl_FragColor = vec4(dirDiffuse, 1.0);
gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;
gl_FragColor.xyz = gl_FragColor.xyz;
if (gl_FragColor.y > gl_FragColor.x)
gl_FragColor.x = gl_FragColor.y;
gl_FragColor.a = surfaceAlpha;
gl_FragColor.xyz = totalDiffuse;
}

22 changes: 22 additions & 0 deletions src/shaders/uvCutting.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
varying vec3 colorValue;
varying vec3 vViewPosition;
varying vec3 vNormal;
varying vec2 vUv;


void main(void) {
vec4 mvPosition;
mvPosition = modelViewMatrix * vec4( position, 1.0 );
vViewPosition = -mvPosition.xyz;

vec3 objectNormal;
objectNormal = normal;
#ifdef FLIP_SIDED
objectNormal = -objectNormal;
#endif
colorValue = color;
vec3 transformedNormal = normalMatrix * objectNormal;
vNormal = normalize( transformedNormal );
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}

0 comments on commit ad66b62

Please sign in to comment.