AFRAME文字几何组件是否从中心旋转? [英] AFRAME text-geometry component rotation from center?
问题描述
是否可以将枢轴点设置在中心?我正在使用文本几何组件,它从一个角旋转。我想使文本从中心旋转。
解决方案似乎文本几何图形
组件没有偏移量
ish属性(来源这里)
我会这样处理:加载文本网格后-抓住它并手动提供偏移量。
1)您可以很容易地抓取网格:
let mesh = this .el.getObject3D('mesh');
2)要计算偏移量-从边界框中获取宽度。
let bbox = new THREE.Box3()。setFromObject(this.el.object3D);
let offset =(bbox.min.x-bbox.max.x)/ 2
mesh.position.set(offset,0,0)
您可以在此处进行查看。
现在我有一个主要问题-也许我不知道什么-但是一旦文本出现就没有事件发出网格已加载。我试过 loaded
或 window / document.onload
,但它们似乎在真正加载文本网格之前执行。我需要加载它,否则边界框是无限的-使偏移量计算几乎无用。在我的小提琴中,我将代码放入了 setTimeout()
中。
编辑
1 )最好等待动画,直到完成上述计算。您可以定义 startEvent
并在重新定位网格后发出它
。 ..
mesh.position.set()
this.el.emit( go)
..
< a-entity animation = startEvents:go>< / a -实体>
2)计算宽度时需要包括比例尺。这是因为本地空间大小现在不同:
let xscale = this.el.getAttribute('scale')。x
let offset =((bbox.min.x-bbox.max.x)/ xscale)/ 2
mesh.position.set(offset,0,0)
在此处查看。
Is there a way to setup the pivot point to be in the center? I am using text-geometry component and it rotates from a corner. i would like to make the text spin from the center.
<a-entity animation="property: rotation; dur: 5000;to: 0 360 0;loop:true;easing:linear" position="0 4 -3" scale="0.6 1.2 1" text-geometry="value: MultiMedia; font: #dawningFont; bevelEnabled: true; bevelSize: 0.1; bevelThickness: 0.1; curveSegments: 1; size: 1.5; height: 0.5;" material="color:yellow; metalness:0.9; roughness: 0.05; sphericalEnvMap: #chrome;"></a-entity>
I have tried adding a parent entity and adding the animation to the parent but it doesn't seem to fix it, instead it starts rotating in a circle path.
解决方案 Seems that the text-geometry
component doesn't have an offset
ish property (source here)
I'd tackle it like this: Once the text mesh is loaded - grab it and manually provide an offset.
1) You can grab the mesh quite easily:
let mesh = this.el.getObject3D('mesh');
2) To calculate the offset - get the width from the bounding box.
let bbox = new THREE.Box3().setFromObject(this.el.object3D);
let offset = (bbox.min.x - bbox.max.x) / 2
mesh.position.set(offset, 0, 0)
You can check it out here.
Now i have one major issue - maybe i don't know something - but there is no event emitted once the text mesh is loaded. I tried loaded
or window/document.onload
but they seem to execute just before the text mesh is being really loaded. I need it to load, otherwise the bounding box is infinite - making the offset calculation pretty much useless. In my fiddle i threw the code into a setTimeout()
.
Edit
1) Its good idea to wait with the animation, until the above calculations are set. You can define a startEvent
and emit it after repositioning the mesh
...
mesh.position.set()
this.el.emit("go")
..
<a-entity animation="startEvents: go"></a-entity>
2) you need to include the scale when calculating width. This is because the local space size is now different:
let xscale = this.el.getAttribute('scale').x
let offset = ((bbox.min.x - bbox.max.x) / xscale ) / 2
mesh.position.set(offset, 0, 0)
Check it out here.
这篇关于AFRAME文字几何组件是否从中心旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!