UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

134 lines (109 loc) 2.66 kB
import { array_quick_sort_by_comparator } from "../../../../../../core/collection/array/array_quick_sort_by_comparator.js"; /** * * @param {THREE.Object3D|{material?:Material}} a * @param {THREE.Object3D|{material?:Material}} b * @returns {number} */ function compare_by_material(a, b) { const a_mat = a.material; const b_mat = b.material; if (a_mat === b_mat) { return 0; } if (a_mat === undefined) { return 1; } else if (b_mat === undefined) { return -1; } return a_mat.id - b_mat.id; } export class AbstractRenderAdapter { constructor() { /** * * @type {number} * @protected */ this.__object_count = 0; /** * * @type {THREE.Object3D[]} * @protected */ this.__objects = []; } /** * Sorting objects by material will help reduce context switching and number of graphics API calls */ sort_by_material() { array_quick_sort_by_comparator(this.__objects, compare_by_material, null, 0, this.__object_count - 1); } /** * * @param {THREE.BufferGeometry} geometry * @param {THREE.Material} material * @param {number} instance_count * @returns {number} */ score(geometry, material, instance_count) { return 0; } /** * Express intent to draw * @param {ShadedGeometry} sg * @returns {boolean} true if able to draw immediately, false otherwise */ intend_draw(sg) { return true; } /** * * @param {ShadedGeometry} sg * @returns {void} */ add(sg) { throw new Error('Not Implemented'); } /** * * @param {THREE.WebGLRenderer} renderer * @param {CameraView} view */ build_start(renderer, view) { } build_end() { } clear() { this.__object_count = 0; } /** * Used to perform infrequent housekeeping on the adapter's internal data structures * Returns a maintenance sequence * @return {Generator} */ * maintain() { // override as necessary } /** * @returns {THREE.Object3D[]} */ get objects() { return this.__objects; } /** * @returns {number} */ get object_count() { return this.__object_count; } dispose() { } } /** * @readonly * @type {boolean} */ AbstractRenderAdapter.prototype.isShadedGeometryRenderAdapter = true;