Sizes from a 1 channel array

18 views
Skip to first unread message

Blake La Pierre

unread,
Jul 28, 2017, 3:27:31 PM7/28/17
to MathBox
I have the following scene:

const universe = [[], []],
      positions
= [[0, 0, 0], [1, 1, 0]],
      colors
= [[2, 2, 2, 1], [2, 0, 2, 1]],
      sizes
= [[1], [5]];


render
(<root>
     
<camera proxy={true}
              position
={[0, 5, 0]}
              lookAt
={[0, 0, 0]}
              fov
={120}
              up
={[0, 1, 0]} />
     
<cartesian range={[[-1, 1], [-1, 1], [-1, 1]]}
                 scale
={[1, 1, 1]}>
       
<array id="positions"
               width
={positions.length}
               channels
={3}
               history
={1}
               data
={positions} />
       
<array id="colors"
               width
={colors.length}
               channels
={4}
               data
={colors} />
       
<array id="sizes"
               width
={sizes.length}
               channels
={1}
               data
={sizes} />
       
<point points="<<<" colors="<<" sizes="<" shape="circle" blending="mult" opacity={0.9}/>
     
</cartesian>
    </
root>);


requestAnimationFrame
(animate);


function animate() {
  sizes
[0][0] += 0.25;


  positions
[1][0] += 0.01;


  requestAnimationFrame
(animate);
}

The size of both points are the same (and both grow), while only the position of the second point is affected.

If 
sizes = [1, 5]

Then:
sizes[0] += 0.25;
works as expected (only the first point grows).

I would like to be able to pass an array of arrays as a data source for points (just as positions and colors come from arrays of arrays) so that I don't have to continually update my sizes array (only the array containers, which can be updated without touching the `sizes` array). That way all my point sizes can be tracked in the global array, but I can edit them directly from my data objects. For example,
const obj = {
  position
: [0, 0, 0],
  color
: [2, 0, 2, 1],
  size
: [1]
};

positions
.push(obj.position);
colors
.push(obj.colors);
sizes
.push(obj.size);

obj
.size[0] = 5;

Does anyone know why there is this apparent discrepancy between point positions, colors and sizes and the number of channels on a data source?


Reply all
Reply to author
Forward
0 new messages