Hi, I have a gltf model B having morph targets. I want to access the total difference(delta) between the final position and base vertex position.Is it possible without applying the morphTargetInfluences.
Actualy , I want to assign the morph targets of object B to object A. Object A have same geometry but slight difference in vertices positions than B(I am updating it dynamically) .The morph targets should behave relative to A’s base positions not relative to B.Here’s the code I am using .
let positionsA = objA.geometry.attributes.position;
let morphAttributesB = objA.geometry.morphAttributes.position = [];
let morphAttributesB = objB.geometry.morphAttributes.position;
let positionsBaseB =objB.geometry.attributes.position;
const morphDictionary = {}
// Loop through morph targets
for ( var j = 0, jl = morphAttributesB.length; j < jl; j ++ ) {
const targetVertices = [];
var key = Object.keys(objB.morphTargetDictionary)[j];
for(var i = 0; i< morphAttributesB[j].array.length;i++){
// calculate delta % per base position change
let delta = (morphAttributesB[j].array[i] - positionsBaseB.array[i]) / positionsBaseB.array[i] ;
targetVertices[i] = positionsA.array[i] + delta * positionsA.array[i]
}
const morphAttribute = new THREE.BufferAttribute(new Float32Array(targetVertices), 3);
objA.geometry.morphAttributes.position.push(morphAttribute);
morphDictionary[key] = j;
}
objA.geometry.morphTargetsNeedUpdate = true;
However , this is not working and throwing error in render loop.
Uncaught TypeError: Cannot read properties of undefined (reading ‘length’)
at Object.update (three.module.js:17910:1)
at setProgram (three.module.js:30554:1)
at WebGLRenderer.renderBufferDirect (three.module.js:29235:1)
at renderObject (three.module.js:30110:1)
at renderObjects (three.module.js:30081:1)
at renderScene (three.module.js:29924:1)
at WebGLRenderer.render (three.module.js:29742:1)
at render$1 (index-99983b2d.esm.js:1544:1)
at loop (index-99983b2d.esm.js:1570:1)