UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

39 lines (30 loc) 1.11 kB
import { vec3 } from "gl-matrix"; import { NormalizeSafe } from "./NormalizeSafe.js"; /** * * @param {STSpace} ts_res * @param {STSpace} pTS0 * @param {STSpace} pTS1 * @returns {void} */ export function AvgTSpace(ts_res, pTS0, pTS1) { // this if is important. Due to floating point precision // averaging when ts0==ts1 will cause a slight difference // which results in tangent space splits later on if ( pTS0.fMagS === pTS1.fMagS && pTS0.fMagT === pTS1.fMagT && vec3.exactEquals(pTS0.vOs, pTS1.vOs) && vec3.exactEquals(pTS0.vOt, pTS1.vOt) ) { ts_res.fMagS = pTS0.fMagS; ts_res.fMagT = pTS0.fMagT; vec3.copy(ts_res.vOs, pTS0.vOs); vec3.copy(ts_res.vOt, pTS0.vOt); } else { ts_res.fMagS = 0.5 * (pTS0.fMagS + pTS1.fMagS); ts_res.fMagT = 0.5 * (pTS0.fMagT + pTS1.fMagT); vec3.add(ts_res.vOs, pTS0.vOs, pTS1.vOs); vec3.add(ts_res.vOt, pTS0.vOt, pTS1.vOt); NormalizeSafe(ts_res.vOs, ts_res.vOs); NormalizeSafe(ts_res.vOt, ts_res.vOt); } }