Javascript:如何在点击事件上更改TextGeometry?

时间:2016-09-26 15:52:10

标签: javascript jquery three.js

我正在研究ThreeJS geometry canvas text。在单击html按钮后,文本被假设为更改为另一个文本。但是,它不起作用。如何更改Click事件上的TextGeometry?

以下是我正在使用的内容:

 var theText = "Hello three.js! :)";

        var hash = document.location.hash.substr( 1 );

        if ( hash.length !== 0 ) {

            theText = hash;

        }

        var geometry = new THREE.TextGeometry( theText, {

            font: font,
            size: 80,
            height: 20,
            curveSegments: 2

        });

        geometry.computeBoundingBox();

        var centerOffset = -0.5 * ( geometry.boundingBox.max.x - geometry.boundingBox.min.x );

        var material = new THREE.MultiMaterial( [
            new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, overdraw: 0.5 } ),
            new THREE.MeshBasicMaterial( { color: 0x000000, overdraw: 0.5 } )
        ] );

        var mesh = new THREE.Mesh( geometry, material );

        mesh.position.x = centerOffset;
        mesh.position.y = 100;
        mesh.position.z = 0;

        mesh.rotation.x = 0;
        mesh.rotation.y = Math.PI * 2;

        group = new THREE.Group();
        group.add( mesh );

        scene.add( group );
    }
      $('.button').on('click', function(e){
      theText.dispose();

       var menu= new Array('option1', 'option2', 'option3');
       theText=menu;

           });

1 个答案:

答案 0 :(得分:2)

您必须创建另一个TextGeometry和网格物体。然后在click事件上,您将使用新文本删除以前的文本。

double diff;
  int astate;

  string line8;
   ifstream myfile8 ("elect12.csv");
    //cout << endl << "Total Popular Votes for Other Candidates: ";
     while (getline (myfile8, line))
     {
      istringstream iss(line);
      int a, b, c, d, e;
      if (!(iss >> a >> b >> c >> d >> e )) //{ break; }
       diff = (a-b);
       diff = diff/d;
       diff = diff*100;
       astate = diff;         
       /*cout << "Obama's best state was " << line8 << ", where he won by " << diff << " points." << endl;*/
       cout << astate << endl; 

供参考 - firebase-cli