gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 21:15:11 25 4
gpt4 key购买 nike

我正在研究 ThreeJS geometry canvas text .单击 html 按钮后,文本应该更改为另一个文本。但是,它不起作用。如何更改 TextGeometry on click 事件?

这是我正在使用的:

 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;

});

最佳答案

您必须创建另一个 TextGeometry 和网格。然后在点击事件中,您将使用新文本删除之前的文本。

function onMouseClick(){
scene.remove(mesh_first);
scene.add(mesh_second);
}

供引用- https://github.com/mrdoob/three.js/blob/master/src/core/Object3D.js#L332

关于Javascript:如何在点击事件中更改 TextGeometry?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39707217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com