draggable - 如何根据相机使网格只能在 x 和 y 方向拖动?
问题描述
我希望我的子网格只能在相对于相机的 x 和 y 方向上拖动。我正在使用巴比伦的免费相机。尝试使用“Left Right Dragger”和“DragPlaneNormal”,但未能达到预期的效果,网格可在 z 方向拖动。
const axis = new BABYLON.Vector3(0,1,0);
const leftRightDragger = new BABYLON.PointerDragBehavior({dragAxis: axis});
leftRightDragger.moveAttached = true;
clone_child[child].addBehavior(leftRightDragger);
or
var pointerDragBehavior = new BABYLON.PointerDragBehavior({dragPlaneNormal: new BABYLON.Vector3(1,1,0)});
clone_child[child].addBehavior(pointerDragBehavior);
pointerDragBehavior.useObjectOrientationForDragging = false;
解决方案
使用 babylonjs 生命周期方法。
const mesh // the mesh now dragging
const zPos = mesh.position.z
scene.registerBeforeRender(() => {
mesh.position.z = zPos
})
推荐阅读
- c++ - 对齐存储的 g++ 编译器问题 - 这是编译器错误吗?
- c# - 如何从 Asp.net 核心依赖注入中注册的子类解析父类实例
- python - 如何获取特定 Twitter 用户的整个用户时间线
- angular - foreach 内部的 Angular 订阅不返回承诺
- mysql - MySQL JOIN 2 行
- android - 如何在我的 android 应用程序中使用 google 登录而不在我的 firastore 数据库中认证 SHA-1 指纹?
- python - 有没有办法在拆分字符串时包含空格?
- angular - 服务器出错时如何获取响应内容
- python - 如何在 tkinter 中重复更新图像
- javascript - 如何自动下载画布图像?