Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                body{
  overflow: hidden;
  margin: 0;
}
              
            
!

JS

              
                console.clear();
import * as THREE from "https://cdn.skypack.dev/three@0.131.3";
import {OrbitControls} from "https://cdn.skypack.dev/three@0.131.3/examples/jsm/controls/OrbitControls.js";

import { Line2 } from 'https://cdn.skypack.dev/three@0.131.3/examples/jsm/lines/Line2.js';
import { LineMaterial } from 'https://cdn.skypack.dev/three@0.131.3/examples/jsm/lines/LineMaterial.js';
import { LineGeometry } from 'https://cdn.skypack.dev/three@0.131.3/examples/jsm/lines/LineGeometry.js';
import { GeometryUtils } from 'https://cdn.skypack.dev/three@0.131.3/examples/jsm/utils/GeometryUtils.js';

let scene = new THREE.Scene();
let camera = new THREE.PerspectiveCamera(45, innerWidth / innerHeight, 1, 100);
camera.position.set(5, 8, 13);
let renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(innerWidth, innerHeight);
renderer.setClearColor(0x404040);
document.body.appendChild(renderer.domElement);

let controls = new OrbitControls(camera, renderer.domElement);

let grid = new THREE.GridHelper(10, 10, 0x303030, 0x202020);
scene.add(grid);

let pts = [];
let clr = [];
let wdth = [];
let counter = 10;
for(let i = 0; i < counter; i++){
  pts.push(
    THREE.MathUtils.randFloat(-5, 5),
    THREE.MathUtils.randFloat(-5, 5),
    THREE.MathUtils.randFloat(-5, 5)
  )
  clr.push(Math.random(), Math.random(), Math.random());
  if (i < counter - 1) wdth.push(THREE.MathUtils.randInt(2, 20));
}
console.log(pts.length, clr.length, wdth.length);

let geometry = new LineGeometry();
geometry.setPositions( pts );
geometry.setColors( clr );
geometry.setAttribute("linewidth", new THREE.InstancedBufferAttribute(new Float32Array(wdth), 1));

console.log(geometry);

let matLine = new LineMaterial( {

  color: 0xffffff,
  //linewidth: 5, // in pixels
  vertexColors: true,
  //resolution:  // to be set by renderer, eventually
  dashed: false,
  alphaToCoverage: true,
  onBeforeCompile: shader => {
    shader.vertexShader = `
      ${shader.vertexShader}
    `.replace(`uniform float linewidth;`, `attribute float linewidth;`);
    //console.log(shader.vertexShader)
  }

} );

let line = new Line2( geometry, matLine );
line.computeLineDistances();
line.scale.set( 1, 1, 1 );
scene.add( line );


renderer.setAnimationLoop( _ => {
  matLine.resolution.set( innerWidth, innerHeight );
  renderer.render(scene, camera);
});
              
            
!
999px

Console