@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
27 lines (20 loc) • 828 B
JavaScript
import { array_copy } from "../../../../core/collection/array/array_copy.js";
/**
*
* @param {SingleChannelSampler3D} source
* @param {Sampler2D} output
* @param {number} z_index
*/
export function scs3d_read_2d_slice(source, output, z_index) {
const source_resolution = source.resolution;
const source_width = source_resolution[0];
const source_height = source_resolution[1];
if (source_width !== output.width || source_height !== output.height) {
throw new Error('Incompatible resolutions');
}
if (output.itemSize !== 1) {
throw new Error(`Expected output to have 1 channel, instead got ${output.itemSize}`);
}
const slice_size = source_width * source_height;
array_copy(source.data, slice_size * z_index, output.data, 0, slice_size);
}