Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.


So, this is basically the most compact form of three.js-boilerplate 
I could come up with. 

To write a demo, only a single function needs to be defined. This function will do all setup-work and return another function that 
will be called for every animationFrame rendererd.

              body { margin: 0; overflow: hidden; background-color: black; }
canvas { width: 100vw; height: 100vh; }
              function creatingLine() {
    const line = createLine({
          url: "",
          lineHeight: 0.2,
          repeatFactor: 1
    const fromX = 0
    const fromZ = 0
    const toX = 10
    const toZ = 5
    line.changePosition({ fromX, fromZ, toX, toZ })

    // axes
    const axesFrom = new THREE.AxesHelper(5)
    axesFrom.position.set(fromX, 0, fromZ)
    const axesTo = new THREE.AxesHelper(5)
    axesTo.position.set(toX, 0, toZ)

function createLine({ scene, url, repeatFactor, lineHeight, offsetX = 0.025, intervalMs=10 }) {
    const textureLoader = new THREE.TextureLoader()
    const texture = textureLoader.load(url)
    const width = 1
    const height = lineHeight
    const geometry = new THREE.PlaneBufferGeometry(width, height)
    const material = new THREE.MeshBasicMaterial({
      color: 0xffffff,
      map: texture,
      transparent: true
    const mesh = new THREE.Mesh(geometry, material)
    texture.wrapS = texture.wrapT = THREE.RepeatWrapping
    mesh.rotation.x = -Math.PI / 2
    mesh.position.x = width / 2
    const line = new THREE.Group()
    const tween = setInterval(() => {
      texture.offset.x -= offsetX
    }, intervalMs)

    return {
      changePosition: ({ fromX, fromZ, toX, toZ }) => {
        const fromVector = new THREE.Vector2(fromX, fromZ)
        const toVector = new THREE.Vector2(toX, toZ)
        const distance = fromVector.distanceTo(toVector)
        const scaleFactorX = distance / mesh.geometry.parameters.width
        line.position.x = fromX
        line.position.z = fromZ
        line.scale.set(scaleFactorX, 1, 1)
        texture.repeat.set(distance * repeatFactor, 1)
        line.rotation.y = -Math.atan2(toZ - fromZ, toX - fromX)
      destroy: () => {


const cameraPosition = 30
const scene = new THREE.Scene()
const renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true })
const camera = new THREE.PerspectiveCamera(
    20, // fov
    window.innerWidth / window.innerHeight, // aspect
    1, // near
    999999 // far
camera.position.set(cameraPosition, cameraPosition, cameraPosition)
camera.lookAt(new THREE.Vector3(0, 0, 0))
renderer.setSize(window.innerWidth, window.innerHeight)

// geometry
scene.add(new THREE.GridHelper(50, 100, 0xaaaaaa, 0x999999))

// lights
const dirLight = new THREE.DirectionalLight()
dirLight.position.set(1, 0.4, 0.2)
scene.add(dirLight, new THREE.AmbientLight(0x444444))

function animate(time) {
    renderer.render(scene, camera)

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.