我正在尝试使用来自麦克风的频率数据来动态更改 A-Frame 中 GLTF 模型的比例和/或位置。这是我到目前为止所拥有的:
<script>
AFRAME.registerComponent('voicecontrol', {
init: function () {
console.log("voicecontrol called");
},
tick: function (time, timeDelta) {
// get scene
var sceneEl = this.el; // Or this.el since we're in a component.
// get model
var mandalaEl = sceneEl.querySelector('#interactiveMandala');
// get current frequency
var currentFreq = freqAvg();
var positionChange = ((currentFreq/16) + 1 );
//console.log("position change factor " + positionChange);
mandalaEl.setAttribute('animation', 'to', {x:positionChange, y:0, z:positionChange});
console.log(mandalaEl.getAttribute('animation', 'to'));
}
});
</script>
和:
<a-scene embedded arjs voicecontrol>
...
<a-marker type='pattern' url='https://raw.githubusercontent.com/DaveyDangerpants/youarehere/master/images/pattern-marker.patt'>
<a-entity rotation="90 0 0">
<a-entity position="0 0 0" scale=".1 .1 .1" animation="property: rotation; to: 0 0 360; loop: true; easing:linear; dur: 45000;">
<a-entity id="interactiveMandala" gltf-model="#mandala" scale="0.15 0.15 0.15" position="0 0 0"
animation="property: position; to:0 0 0; dur: 100;">
</a-entity>
</a-entity>
</a-entity>
</a-marker>
我可以看到麦克风数据流入,控制台似乎表明我正在正确设置动画组件的“to”值,但模型没有移动。这是 AR.JS 的问题吗?我从来没有用 A-Frame 或 AR.js 做过任何东西,所以我有点迷茫。帮助!