class SceneGalaxy extends SceneObj {
constructor(name, coords, minRedshift, maxRedshift, size) {
super(name, coords, minRedshift, maxRedshift);
const nChunks = textures[name].length;
this.chunks = arange(nChunks + 1, {dtype:Int32Array}).map(n => Math.round(n*this.count/nChunks));
this.shuffle = RNG.shuffle(arange(this.count, {dtype:Int32Array}));
this.xyzs = [];
for(let j=0; j<nChunks; j++) {
const [lo,hi] = this.chunks.slice(j,j+2);
const material = new THREE.PointsMaterial({
size: size, map: textures[name][j], color: Number.parseInt(sourceColor[name]),
alphaTest:0.5, transparent: true});
const xyz = zeros(3*(hi-lo), {dtype:Float32Array});
this.xyzs.push(xyz);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.BufferAttribute(xyz, 3));
this.obj.add(new THREE.Points(geometry, material));
}
}
updateComoving(distanceGrid, transverseGrid) {
const z = interp(this.redshift, redshiftGrid, distanceGrid);
const zt = interp(this.redshift, redshiftGrid, transverseGrid);
for(let j=0; j<this.chunks.length-1; j++) {
const [lo,hi] = this.chunks.slice(j,j+2);
for(let i=lo; i<hi; i++) {
const k = this.shuffle[i];
const rperp = zt[k] * this.theta[k];
const xyz = this.xyzs[j];
const base=3*(i-lo);
xyz[base + 0] = rperp * this.unitX[k];
xyz[base + 1] = rperp * this.unitY[k];
xyz[base + 2] = z[k];
}
}
this.needsUpdate();
}
}