UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

62 lines (58 loc) 1.84 kB
import { y as PBR2_HAS_UV_TRANSFORM, a8 as _registerPbrExt } from './index-DMbDahsc.esm.js'; const PBR2_OCCL_UV_SPLIT = 1 << 28; function writeOne(data, offsets, texName, tex) { const mOff = offsets.get(`${texName}UVm`); const tOff = offsets.get(`${texName}UVt`); if (mOff === void 0 || tOff === void 0) { return; } const mi = mOff / 4; const ti = tOff / 4; const sx = tex?.uScale ?? 1; const sy = tex?.vScale ?? 1; const ang = tex?.uAng ?? 0; const ox = tex?.uOffset ?? 0; const oy = tex?.vOffset ?? 0; if (ang === 0) { data[mi] = sx; data[mi + 1] = 0; data[mi + 2] = 0; data[mi + 3] = sy; } else { const c = Math.cos(ang); const s = Math.sin(ang); data[mi] = c * sx; data[mi + 1] = s * sy; data[mi + 2] = -s * sx; data[mi + 3] = c * sy; } data[ti] = ox; data[ti + 1] = oy; data[ti + 2] = 0; data[ti + 3] = 0; } const pbrExt = { id: "uv-transform", phase: "fragment", detect(mat) { const m = mat; const split = !!m.occlusionTexture && !m.occlusionTexCoord; return { f: 0, f2: (m._hasUvTx ? PBR2_HAS_UV_TRANSFORM : 0) | (split ? PBR2_OCCL_UV_SPLIT : 0) }; }, writeUbo(data, material, offsets) { const m = material; writeOne(data, offsets, "baseColor", m.baseColorTexture); writeOne(data, offsets, "normal", m.normalTexture); writeOne(data, offsets, "orm", m.ormTexture); writeOne(data, offsets, "emissive", m.emissiveTexture); writeOne(data, offsets, "specGloss", m.specGlossTexture); writeOne(data, offsets, "occl", m.occlusionTexture); } }; function enableMaterialUvTransform(material) { material._hasUvTx = true; _registerPbrExt(pbrExt); return material._renderFeatures === void 0; } export { enableMaterialUvTransform }; //# sourceMappingURL=enable-material-uv-transform-Bfrq4EoX.esm.js.map