【发布时间】:2021-12-02 03:09:59
【问题描述】:
Framework used: React
3D Image: glb/gltf format
Rendered using: three.js packages
Mission: To insert a number to each of the object and display it above them
方法:我尝试获取画布元素,然后使用添加文本
var parentofCanvas = document.getElementById("untitled.glb");
var childCanvas = parentofCanvas.firstChild;
var context = childCanvas.getContext("webgl");
console.log(childCanvas);
console.log(parentofCanvas.firstChild.nodeName);
console.log(context);
// var text = "Howdy World!";
// context.font = "25px Arial";
// context.fillStyle = "red";
// var x = 50;
// var y = 100;
// context.fillText(text, x, y);
}, []);
其中 x 和 y 是坐标。我收到一条错误消息,提示 fillText 不是函数。那么,我错过了什么?还有其他方法可以在 3D 画布图像中插入/渲染 html 元素吗?
codeandbox 链接:https://codesandbox.io/s/dreamy-lichterman-lbb4z?file=/src/Test.js
(仅供参考:这是 Dreamy-lichterman 的一个分叉项目)
【问题讨论】:
标签: javascript reactjs three.js 3d gltf