[英]Assign texture to loaded glb model in Three.js
I load a simple glb model created in SketchUp using Three.JS. 我加载了一个使用Three.JS在SketchUp中创建的简单glb模型。 The model contains a group called Text.
该模型包含一个名为“文本”的组。
The model loads and displays fine in Three.js, and I can find the mesh by traversing the loaded model. 模型加载并在Three.js中显示良好,我可以遍历加载的模型来查找网格。
I want to create some text and then display that text as a texture on the model. 我想创建一些文本,然后在模型上将该文本显示为纹理。 But when I assign the texture, it's just black.
但是当我指定纹理时,它只是黑色。 If a assign a color instead, it works as intended.
如果改为分配颜色,则它将按预期工作。 I tried a lot of different stuff, but the texture just remains black.
我尝试了很多不同的东西,但纹理仍然保持黑色。
I assign using the below code: 我使用以下代码分配:
var textModelMesh = FindMeshWithNameInModel(model, "Text");
var textTexture = CreateCanvasTexture("Hello");
textModelMesh.material = new THREE.MeshBasicMaterial({ side: THREE.DoubleSide, map: textTexture})
How do I get the text to display on the loaded model? 如何使文本显示在加载的模型上?
Fiddle link: https://jsfiddle.net/ajo27ny4/28/ 小提琴链接: https : //jsfiddle.net/ajo27ny4/28/
The geometry of your mesh has no texture coordinates. 网格的几何没有纹理坐标。 You can see this by debugging the buffer attributes of the geometry object.
您可以通过调试几何对象的缓冲区属性来看到这一点。 There is only a
position
and normal
but no uv
attribute. 只有
position
和normal
但没有uv
属性。 I suggest you ensure valid texture coordinates in SketchUp and then perform a new glTF
export. 建议您在SketchUp中确保有效的纹理坐标,然后执行新的
glTF
导出。
three.js R105
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.