-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMorphCode.js
42 lines (42 loc) · 1.3 KB
/
MorphCode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
export const WEIGHTS_UNIFORM = 'uMorphWeights';
function declareAttribute(infos) {
return infos.attributes.map((attrib, i) => {
return `IN ${infos.type} ${attrib};`;
}).join('\n');
}
function generateMorphFunction(infos) {
const morphMix = infos.attributes.map((attrib, i) => {
return `${attrib} * ${WEIGHTS_UNIFORM}[${i}]`;
}).join(' +\n ');
return `void MorphAttribute_${infos.name}( inout ${infos.type} ${infos.name} ){
${infos.name} += ${morphMix};
}`;
}
function generateMorphCall(infos) {
return `MorphAttribute_${infos.name}( vertex.${infos.name} );`;
}
function declareAttributes(infos) {
return infos.map(declareAttribute).join('\n');
}
function generateMorphFunctions(infos) {
return infos.map(generateMorphFunction).join('\n');
}
function generateMorphCalls(infos) {
return infos.map(generateMorphCall).join('\n');
}
function declareWeights(numtgt) {
return `uniform float ${WEIGHTS_UNIFORM}[${numtgt}];`;
}
const MorphCode = {
preVertexCode(morph) {
return [
declareWeights(morph.numTargets),
declareAttributes(morph.morphInfos),
generateMorphFunctions(morph.morphInfos)
].join('\n');
},
vertexCode(morph) {
return generateMorphCalls(morph.morphInfos);
}
};
export default MorphCode;