
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
screen-projected-lines
Advanced tools
draw wireframes using triangles in screen-projected coordinates
draw wireframes using triangles in screen-projected coordinates
This module triangulates edges from a simplicial complex and returns arrays you can use as attributes in a vertex shader.
This module does not currently support miter joins, but that would be nice to have.
In this demo, we will draw a wireframe sphere with an exaggerated sense of
depth by dividing the offset vector by p.z.
var regl = require('regl')()
var camera = require('regl-camera')(regl, { distance: 1.7 })
var icosphere = require('icosphere')
var glsl = require('glslify')
var wireframe = require('screen-projected-lines')
var draw = sphere(regl)
regl.frame(function () {
regl.clear({ color: [0,0,0,1], depth: true })
camera(function () { draw() })
})
function sphere (regl) {
var mesh = wireframe(icosphere(2))
return regl({
frag: `
precision mediump float;
void main () {
gl_FragColor = vec4(0,1,1,1);
}
`,
vert: glsl`
#pragma glslify: linevoffset = require('screen-projected-lines')
precision mediump float;
uniform mat4 projection, view;
uniform float aspect;
attribute vec3 position, nextpos;
attribute float direction;
void main () {
mat4 proj = projection * view;
vec4 p = proj*vec4(position,1);
vec4 n = proj*vec4(nextpos,1);
vec4 offset = linevoffset(p, n, direction, aspect);
gl_Position = p + offset*0.02/p.z;
}
`,
attributes: {
position: mesh.positions,
nextpos: mesh.nextPositions,
direction: mesh.directions
},
elements: mesh.cells,
uniforms: {
aspect: function (context) {
return context.viewportWidth / context.viewportHeight
}
}
})
}
To compile this code, use browserify with the glslify transform:
browserify sphere.js -t glslify > bundle.js
var wireframe = require('screen-projected-lines')
#pragma glslify: linevoffset = require('screen-projected-lines')
Create a wireframe mesh given an existing triangular mesh.
The wireframe mesh has these properties:
wmesh.positions - array of vertex [x,y,z] arrayswmesh.cells - array of triangle indiceswmesh.nextPositions - array of the next vertex coordinateswmesh.directions - array of values to use for which side of each vertexwmesh.attributes - extra attributes declared alongside verticeswmesh.angles - array of angles betwen the triangles that share an edgeThe normals are not computed on the CPU here so that you can apply additional displacements in your vertex shader.
Optionally provide opts.attributes to declare attributes alongside the
original vertices. For example, if you want to use computed surface normals to
displace your wireframe mesh, you could do:
var anormals = require('angle-normals')
var wmesh = wireframe(mesh, {
attributes: {
normals: anormals(mesh.cells, mesh.positions)
}
})
and then you can use wmesh.attributes.normals alongside wmesh.positions as
an attribute.
Return the screen offset to apply to pos given the current vertex screen
position pos, the screen position of the next vertex in the edge nextpos,
the direction of the vertex (-1.0 or 1.0), and the aspect ratio.
The offset vector is normalized, so multiply by a constant to adjust thickness.
To have the thinkness vary with depth like everything else:
vec4 offset = linevoffset(p, n, direction, aspect);
gl_Position = p + offset*0.02;
To have the thinkness have an exaggerated sense of depth:
vec4 offset = linevoffset(p, n, direction, aspect);
gl_Position = p + offset*0.02/p.z;
To have the thinkness not vary with depth:
vec4 offset = linevoffset(p, n, direction, aspect);
gl_Position = p + offset*0.02*p.z;
npm install screen-projected-lines
BSD
FAQs
draw wireframes using triangles in screen-projected coordinates
We found that screen-projected-lines demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.