     
     tube.addAttribute 'position', new THREE.BufferAttribute(vs, 3)
     tube.addAttribute 'index', new THREE.BufferAttribute(ixs, 1)
-
-    #tube.offsets.push {start: 0;index: 0; count: vs.length}
-
     tube.computeBoundingSphere()
     return  tube
     

    #Offset to put pattern to the center
    cx = ((simulator.width - patW)/2) & ~1
    cy = ((simulator.height - patH)/2) & ~1
    console.log "Putting pattern at #{cx}, #{cy}"
    simulator.put pattern, cx, cy #pattern roughly at the center
    
    order = 3

      idx_used: curIx
    return blueprint
    
  

class ChunkedFlyingCurves
  constructor: ->
    @tubing = tubing = new Tubing
    
    @scale = scale = 30

    @colors = (palette[i%palette.length] for i in [0...tubing.nCells] by 1)
    @group = new THREE.Object3D
    @chunks = []
    @materials = for color in @colors
      new THREE.MeshBasicMaterial color: color

    @zMin = -100
    @lastChunkZ = 0

    @group.scale.set scale, scale, scale
    simulator = @tubing.isim.simulator
    @group.position.set -0.5*simulator.width*scale, -0.5*simulator.height*scale, 0
    @group.updateMatrix()
    
        
  makeChunk: ->
    blueprint = @tubing.makeChunkBlueprint()

    #create lines
    chunk = new THREE.Object3D
    for tubeBp, i in blueprint
      tubeGeom = @createTube tubeBp
      tube = new THREE.Mesh tubeGeom, @materials[i]
      chunk.add tube
    return chunk


  createTube: (blueprint)->
    tube = new THREE.BufferGeometry()

    vs = blueprint.v.subarray 0, blueprint.v_used
