0
votes

Loaded the model without morphTargets initially and cloned the geometry. Using webworker read the file containing morphTargets alone and converted as THREE object using this code

i = timeStep;
dstVertices = [];
srcVertices = morphTargets.vertices;
for (v = 0, vl = srcVertices.length; v < vl; v += 3) {
    var vertex = new THREE.Vector3();
    vertex.x = srcVertices[ v ];
    vertex.y = srcVertices[ v + 1 ];
    vertex.z = srcVertices[ v + 2 ];
    dstVertices.push(vertex);
}
geo.morphTargets.push(dstVertices);
timeStep += 1;

On later stage created the new geometry included vertices and faces from the cloned geometry and dstVertices as morphTargets.

Removed the previously created mesh from the scene and added the newly created mesh containing morphTargets.

console is throwing this error:

Uncaught TypeError: Cannot read property '52' of undefined
    at setMeshBuffers (three_70.js:18797)
    at updateObject (three_70.js:21142)
    at THREE.WebGLRenderer.renderBuffer (three_70.js:19970)
    at renderObjects (three_70.js:20681)
    at THREE.WebGLRenderer.render (three_70.js:20544)
    at animate (index1.php:70)

Can anyone guide me where I am going wrong?

1

1 Answers

0
votes

I assume you parsed a graphic file and you were trying to create webgl objects in web worker. I faced the same kind of problem while I was parsing 3d file and initiating WebGL's objects with using web worker. First, I got errors like yours then I realized each web worker has own scope. So, I passed(postMessage) the values into my main.js who triggered the web worker and then I was ready to define the objects on main.js's onmessage method.

You can post your v, v+1 and v+2 values by using postmessage method and you can create your three verctor object in where you defined and called your web worker.

What I am trying to say is that you shouldn't init the three.vectors object in web worker because it is hard to handle. Don't forget web worker supports simple object transfers on postmessage. Therefore, you should try to make it simple. Don't try to post three.vector object while using postmessage.