Skip to content

Instantly share code, notes, and snippets.

@donmccurdy
Created August 20, 2018 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donmccurdy/bf17af7acfcdd5ebc57da1200e7b1e46 to your computer and use it in GitHub Desktop.
Save donmccurdy/bf17af7acfcdd5ebc57da1200e7b1e46 to your computer and use it in GitHub Desktop.
Merge THREE.BufferGeometry morph attributes.
diff --git a/examples/js/utils/BufferGeometryUtils.js b/examples/js/utils/BufferGeometryUtils.js
index f1ce126f6..4c1edcea3 100644
--- a/examples/js/utils/BufferGeometryUtils.js
+++ b/examples/js/utils/BufferGeometryUtils.js
@@ -399,6 +399,7 @@ THREE.BufferGeometryUtils = {
// attributes and new attribute arrays
var attributeNames = Object.keys( this.attributes );
var attrArrays = {};
+ var morphAttrArrays = {};
var newIndices = [];
var getters = [ 'getX', 'getY', 'getZ', 'getW' ];
@@ -447,6 +448,14 @@ THREE.BufferGeometryUtils = {
newarray.push( attribute[ getters[ k ] ]( index ) );
+ for ( var m = 0; m < (this.morphAttributes[ name ]||[]).length; m ++ ) {
+
+ morphAttrArrays[ name ] = morphAttrArrays[ name ] || [];
+ morphAttrArrays[ name ][ m ] = morphAttrArrays[ name ][ m ] || [];
+ morphAttrArrays[ name ][ m ].push( this.morphAttributes[ name ][ m ][ getters[ k ] ]( index ) );
+
+ }
+
}
}
@@ -481,6 +490,14 @@ THREE.BufferGeometryUtils = {
this.addAttribute( name, attribute );
+ for ( var j = 0; j < morphAttrArrays[ name ].length; j ++ ) {
+
+ var morphAttribute = this.morphAttributes[ name ][ j ].clone();
+ morphAttribute.setArray( new morphAttribute.array.constructor( morphAttrArrays[ name ][ j ] ) );
+ this.morphAttributes[ name ][ j ] = morphAttribute;
+
+ }
+
debugger;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment