问题
I've been trying to replicate the results of Three.js's WireframeHelper using shaders. I want to display a wireframe using only geometry information. I am using the VTKLoader used in the examples, and have been basing my code off of a jsfiddle example.
I have created a jsfiddle example to highlight my problem.

The model loads correctly, but the shader only seems to draw the edges of select faces. I have not been able to figure out why some triangles are not drawn with edges.
Is this because I am loading my data from a .vtk file (missing data or just a bad loader)? I think my data is fine since the built in WireframeHelper is able to correctly draw the triangle edges, but otherwise I don't know why only some triangles are drawn but not others.
I am using a fairly common shader, so I don't think that is the problem.
<script type="x-shader/x-vertex" id="vertexShader">
attribute vec3 center;
varying vec3 vCenter;
void main() {
vCenter = center;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
</script>
<script type="x-shader/x-fragment" id="fragmentShader">
#extension GL_OES_standard_derivatives: enable
varying vec3 vCenter;
float edgeFactorTri() {
vec3 d = fwidth(vCenter.xyz);
vec3 a3 = smoothstep(vec3(0.0), d * 1.5, vCenter.xyz);
return min(min(a3.x, a3.y), a3.z);
}
void main() {
gl_FragColor.rgb = mix(vec3(1.0), vec3(0.2), edgeFactorTri());
gl_FragColor.a = 1.0;
}
</script>
My only guess is that something is weird with the VTKLoader, has anyone had problems with the example loaders from threejs.org?
来源:https://stackoverflow.com/questions/30632159/three-js-wireframe-model-from-vtk-file