0

JSON ファイルからアニメーションを実行しようとしています。カスタム JSON ローダーを使用しています (つまり、three.js に含まれているものではありません)。そのため、多くのフレームを含むframesという名前のオブジェクトがあり、すべてに形状情報があり、アニメーションに必要なデータが4by4変換マトリックス(pythonスクリプトから生成)の形式で含まれているsimulation_matrixがあります。だから私はアニメーションのためにこのコードを使用しています..これはロードするサンプルの JSON スクリプトです。

    // This method is for adding static shapes
    // This works perfectly fine ..
    parent.add_shape = function(frame)
 {   
     var material = new THREE.MeshLambertMaterial({
        color:              frame.shape.color,
        wireframe:          true,
        wireframeLinewidth: 0.1,
        opacity: 0.5
       })

     var geometry = new THREE.CylinderGeometry(frame.shape.radius,frame.shape.radius,frame.shape.height,50,50);
     // mesh_dict dictionary maps a mesh(shape) to its frame
     parent.mesh_dict[frame] = new THREE.Mesh(geometry,material);
     var init_orientation = frame.simulation_matrix[0];
     var orienter = new THREE.Matrix4();
     orienter.elements = [];
     //Since simulation_matrix is generated from python, it is a 
     // list of lists, We need to push it to the elemens of Matrix4 manually ..

     for(var i in init_orientation)
         {
           for(var j in init_orientation[i]) 
           { 
              orienter.elements.push(init_orientation[i][j]) ;
            }
          }  
     parent.mesh_dict[frame].applyMatrix(new THREE.Matrix4());
     parent.mesh_dict[frame].applyMatrix(orienter);
     parent.scene.add(parent.mesh_dict[frame]);
     parent.renderer.render(parent.scene,parent.camera); 
  }                  
    // This method basically takes the meshes defined in add_shape, and 
    // applies simulation matrix to it, and requests animation frame for
    // animation.
  parent.animate = function()
 {

   for(var frame in JSONObj.frames) 
         {
          // defining simulation_matrix in a var.   
          var matrix = JSONObj.frames[frame].simulation_matrix[parent.animation_counter];
          var animation_matrix = new THREE.Matrix4();
          animation_matrix.elements = [];
          // pushing it to a Matrix4   
          for(var i in matrix)
              {
                for(var j in matrix[i]) 
                { 
                   animation_matrix.elements.push(matrix[i][j]) ;
                 }
              }  
         console.log(animation_matrix);
         console.log(animation_matrix.elements);
         // Making sure we are not applying matrix to the earlier transform
         //mesh_dict is a dictionary of meshes, used in creating shapes,mapped to the
         //frame which contains them    
         parent.mesh_dict[JSONObj.frames[frame]].applyMatrix(new THREE.Matrix4());   

         // now applying transform, after setting to identity matrix ...
         parent.mesh_dict[JSONObj.frames[frame]].applyMatrix(animation_matrix);                  

         }    

     console.log(parent.animation_counter);    
     //update timestep ...
     parent.animation_counter++;
     // This is to loop over again and again ...
     // assuming 10 animations frames
     if(parent.animation_counter == 10){ parent.animation_counter = 0; }

     requestAnimationFrame(parent.animate);

 }

問題は、複数の形状を作成できることですが、ループ内でそれらにシミュレーション マトリックスを適用すると、そのうちの 1 つだけがアニメーション化され、それも非常に予期しない方法で行われます。

4

1 に答える 1