this.el.object3D.position.set(0,0,0) 如果在调试器中没有断点则不起作用
this.el.object3D.position.set(0,0,0) doesn't work if without breakpoint in debugger
我在 Vive(蓝框)控制器的元素上附加了一个元素(门)。
附加后我想用代码 "this.el.object3D.position.set(0,0,0)" 将门的位置设置为“0 0 0”,以将门附加到蓝色框。
但是如果没有使用浏览器调试器中的断点,它就不起作用。
当我设置断点并通过它时,结果是正确的。
Glitch 中带有演示的代码:https://glitch.com/edit/#!/join/aedfdc5a-698b-4e6c-96c3-4dddfce0a6eb
也许有人知道原因?
感谢您的帮助。
当您尝试更改位置时,子元素似乎没有完全附加自己。
你可以很容易地通过制作一个计时器来检查它,它会在 append()
之后改变位置。
您可以使用 MutationObserver,它会在附加子项时触发一个事件。
然后你可以进行更改:
var viveController, door
// Observer config -> what am i going to react upon
var observerOptions = {
childList: true,
}
// create the observer - it takes a callback as an argument
// no need to filter what event was caught, just move the damn door
var observer = new MutationObserver((e)=>{
door.setAttribute("position", "0, 0, 0")
});
observer.observe(viveController, observerOptions);
viveController.appendChild(door)
检查它是否正常工作 here。
我在 Vive(蓝框)控制器的元素上附加了一个元素(门)。
附加后我想用代码 "this.el.object3D.position.set(0,0,0)" 将门的位置设置为“0 0 0”,以将门附加到蓝色框。
但是如果没有使用浏览器调试器中的断点,它就不起作用。
当我设置断点并通过它时,结果是正确的。
Glitch 中带有演示的代码:https://glitch.com/edit/#!/join/aedfdc5a-698b-4e6c-96c3-4dddfce0a6eb
也许有人知道原因?
感谢您的帮助。
当您尝试更改位置时,子元素似乎没有完全附加自己。
你可以很容易地通过制作一个计时器来检查它,它会在 append()
之后改变位置。
您可以使用 MutationObserver,它会在附加子项时触发一个事件。 然后你可以进行更改:
var viveController, door
// Observer config -> what am i going to react upon
var observerOptions = {
childList: true,
}
// create the observer - it takes a callback as an argument
// no need to filter what event was caught, just move the damn door
var observer = new MutationObserver((e)=>{
door.setAttribute("position", "0, 0, 0")
});
observer.observe(viveController, observerOptions);
viveController.appendChild(door)
检查它是否正常工作 here。