Skip to content

Instantly share code, notes, and snippets.

@soundyogi
Last active April 29, 2018 07:00
Show Gist options
  • Save soundyogi/34e1daaa5179940110afdd65d57ae168 to your computer and use it in GitHub Desktop.
Save soundyogi/34e1daaa5179940110afdd65d57ae168 to your computer and use it in GitHub Desktop.
three js more than 8 morph targets non animated, pre-compute morph targets
/* Precompute Morph Target Shape
I needed 12 Morph Target but Three JS supports only 8 at runtime.
Since we did not use them for animation we used this to precompute our meshes.
By soundyogi, adapted from jspdown
*/
var vertices = geometry.attributes.position.array;
var morphTargets = geometry.morphAttributes.position;
var verticesReference = vertices.slice()
var refVertice;
var targetVertices;
for (var v = 0, vl = vertices.length; v < vl; v++) {
refVertice = verticesReference[v];
vertices[v] = refVertice;
for (var t = 0, tl = morphTargets.length; t < tl; t++) {
var weight = 0.7
vertices[v] += (morphTargets[t].array[v] - refVertice) * weight;
}
}
geometry.verticesNeedUpdate = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment