UNPKG

nanogl-gltf

Version:
42 lines (41 loc) 1.7 kB
const Semantics = { POSITION: { indexed: false, attrib: 'aPosition' }, NORMAL: { indexed: false, attrib: 'aNormal' }, TANGENT: { indexed: false, attrib: 'aTangent' }, TEXCOORD: { indexed: true, attrib: 'aTexCoord' }, COLOR: { indexed: true, attrib: 'aColor' }, JOINTS: { indexed: true, attrib: 'aSkinJoints' }, WEIGHTS: { indexed: true, attrib: 'aSkinWeights' }, }; /** * The default implementation of ISemantics. * * It uses the following convention: POSITION = aPosition, NORMAL = aNormal, TANGENT = aTangent, TEXCOORD = aTexCoord, COLOR = aColor, JOINTS = aSkinJoints, WEIGHTS = aSkinWeights */ export class DefaultSemantics { /** * Get the GLSL attribute name for a morphed attribute with a given semantic and index. * Typically the same as getAttributeName but with a suffix _mt{index} * @param semantic Attribute semantic * @param index Index of the morph target */ getMorphedAttributeName(semantic, index) { return this.getAttributeName(semantic) + '_mt' + index; } /** * Get the GLSL attribute name for an attribute with a given semantic. * If the semantic is indexed, it will be suffixed with the set index (e.g. TEXCOORD_0 -> aTexCoord0) * @param semantic Attribute semantic */ getAttributeName(semantic) { const [basename, set_index = 0] = semantic.split('_'); const infos = Semantics[basename]; if (infos !== undefined) { if (set_index > 0 || infos.indexed) return infos.attrib + set_index; return infos.attrib; } throw new Error(`Invalid Semantic ${semantic}`); // return semantic; } }