将标签添加到轴助手 - 无法获取四肢顶点
Add labels to AxisHelper - can't get vertices of extremities
我想在随之旋转的 AxisHelper 上添加标签。从这个链接,我使用了这个代码片段:
// Axes
axes2 = new THREE.AxisHelper(70);
// Axes labels
addLabelAxes();
// Add axes to zoomScene
zoomScene.add(axes2);
function addLabelAxes() {
// Axes label
var loader = new THREE.FontLoader();
loader.load( 'js/helvetiker_regular.typeface.js', function ( font ) {
textGeo = new THREE.TextGeometry( 'Example label', {
font: font,
size: 15,
height: 5,
curveSegments: 10,
} );
var color = new THREE.Color();
color.setRGB(255, 0, 0);
textMaterial = new THREE.MeshBasicMaterial({ color: color });
meshText = new THREE.Mesh(textGeo, textMaterial);
// Position of first axis
meshText.position.x = axes2.geometry.vertices[1].x;
meshText.position.y = axes2.geometry.vertices[1].y;
meshText.position.z = axes2.geometry.vertices[1].z;
meshText.rotation = zoomCamera.rotation;
zoomScene.add(meshText);
});
但是我在控制台日志中收到以下错误:
TypeError: axes2.geometry.vertices is undefined
addLabelAxes/<()
sphere_dev.js:230
THREE.FontLoader.prototype.load/<()
three.min.js:382
THREE.XHRLoader.prototype.load/<()
这里可能出了什么问题?
AxisHelper
的几何是BufferGeometry
型,而不是Geometry
型。
您可以像这样访问AxisHelper
几何体的位置元素:
var axes = new THREE.AxisHelper( 20 );
var position = axes.geometry.attributes.position;
position
是一个BufferAttribute
。如果你研究它的内容,结构应该是显而易见的。
然后,您可以使用如下模式访问属性的元素:
var x = position.getX( index ); // or getY, getZ
三.js R.76
相关文章:
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- jquery试图按名称获取按钮位置
- 如何在jQuery中获取元素的形式
- 如何在php文件中获取$.post-ajax传递的值
- 在Shopify中获取博客文章的图片
- 使用Javascript获取所选选项ID
- 在jQuery中获取表的行索引
- 使用jquery将mysql数据获取到新的表行中
- 在动态创建的元素上获取对特定选择器的引用
- 从城市名称获取惊喜
- Angular只从数组中获取所需的数据
- 无法将数据从firebase获取到我的html页面
- 从ajax请求中获取javascript对象
- 如何从画布上的某个移动事件中获取X和Y
- 是否有一个JS/jQuery函数可以获取某个类的每个元素的ID
- 将标签添加到轴助手 - 无法获取四肢顶点
- Three.js:使用变形目标获取更新的顶点
- 如何在three.js中获取顶点的绝对位置
- 如何获取球体几何的顶点
- 如何在Three.js中从上传的obj文件中获取顶点