gpt4 book ai didi

three.js - 如何在threeJS中动态更改textGeometry的文本?

转载 作者:行者123 更新时间:2023-12-03 16:40:53 24 4
gpt4 key购买 nike

我试过这个:

var fontLoader = new THREE.FontLoader();

fontLoader.load("/assets/fonts/helvetiker_bold.typeface.json",function(font){

var text2D = new THREE.TextGeometry(newText.textContent, {
size: 200,
height: 2,
curveSegments: 3,
font: font
});
var color = new THREE.Color( newText.color );
var textMaterial = new THREE.MeshBasicMaterial({ color: color });
var text = new THREE.Mesh(text2D , textMaterial);
text.name = "2D Text 1";

//Add the text to current scene
current_scene.add(text);

//set the elemnt as active element
activeElement = current_scene.getObjectByName(text.name);
console.log('activeElement:',activeElement);

});

function textData(changedValue){
activeElement.geometry.parameters.text = changedValue;
}

But I didn't get any change.Is this the correct method?Or need any updates in Matrix parameter?

最佳答案

您将需要删除然后添加新的文本网格。

它有一个巨大的性能损失,但不幸的是现在就是这样。

    //------------Add Text Geometry----------

//Group to hold mesh
group = new THREE.Group();
this.scene.add(group);

//add clock mesh
startTime = new Date();
earthClockMesh = this.getTextMesh(startTime.toLocaleString(), textMaterial);
group.add(earthClockMesh);


//------------Update Text Mesh----------

//remove old mesh
group.remove(earthClockMesh);

//add new mesh
earthClockMesh = this.getTextMesh(
new Date(timeNow).toLocaleString(),
textMaterial
);
group.add(earthClockMesh);

创建新网格的功能
getTextMesh = (text, material) => {
//Number
var textgeometry = new TextBufferGeometry(
text,
Object.assign(
{},
{
font: helvatiker,
bevelEnabled: false,
curveSegments: 8,
bevelThickness: 1,
bevelSize: 0,
height: 0.7,
size: 5
}
)
);
let numberMesh = new THREE.Mesh(textgeometry, material);
// wireframe
var geo = new THREE.EdgesGeometry(numberMesh.geometry); // or WireframeGeometry

var wireframe = new THREE.LineSegments(geo, wireFrameMaterial);
numberMesh.add(wireframe);

// Translate to Center
return numberMesh;
};

关于three.js - 如何在threeJS中动态更改textGeometry的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49811721/

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