在 a-frame 中使用 superhands 组件,是否可以在不使用物理的情况下旋转抓取的对象?
Using superhands component in a-frame, is it possible to rotate grabbed objects without using physics?
我在框架中使用更新后的 super-hands component。我已经从文档中复制了基本示例(见下文)。
<head>
<title>Most Basic Super-Hands Example</title>
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
<script src="https://cdn.rawgit.com/donmccurdy/aframe-extras/v4.1.2/dist/aframe-extras.min.js"></script>
<script src="https://unpkg.com/super-hands@3.0.0/dist/super-hands.min.js"></script>
</head>
<body>
<a-scene>
<a-assets></a-assets>
<a-entity>
<a-camera></a-camera>
<a-entity sphere-collider="objects: a-box" super-hands hand-controls="left"></a-entity>
<a-entity sphere-collider="objects: a-box" super-hands hand-controls="right"></a-entity>
</a-entity>
<!-- hover & drag-drop won't have any obvious effect without some additional event handlers or components. See the examples page for more -->
<a-box hoverable grabbable stretchable draggable dropppable color="blue" position="0 0 -1"></a-box>
</a-scene>
</body>
在抓取物体并能够影响它们的 position
但不是它们的 rotation
时,开箱即用。我想知道是否有可能(不使用物理学并向控制器添加 static body
)影响目标对象的 rotation
?
我已经能够通过添加相关的混合和相移组件来实现旋转 from this example 但是考虑到似乎可以抓取影响其位置的对象我想知道我是否可以将基本示例修改为更改 rotation
而不是 position
(理想情况下,我可以选择是否影响 position
、rotation
或两者)。我想我可能正在想象创建另一个组件,例如 rotatable
,或者可能是在可抓取组件(例如 grabbable="property: rotation"
的基础上构建,我可以将其添加到目标对象中。
我想知道这在一般情况下是否可行,因为我想更好地了解该组件以便进行更多控制。然而,为了给这个特定问题提供一些背景信息,我遇到了这样一种情况,即超级手控制器是 dynamic-body
的子级,一旦添加了 static-body
,就会导致父级 static-body
的行为出现问题 dynamic-body
。
一如既往地感谢任何建议,如果您需要更多信息,请告诉我。
如果您想在没有物理的情况下进行旋转,则需要实现您自己的 grabbable
版本来执行矩阵数学运算。它会是这样的:
tick: (function () {
const grabeeMatrix = new window.THREE.Matrix4()
const ignoreScale = new window.THREE.Vector3()
return function () {
if (this.grabber) {
grabeeMatrix.multiplyMatrices(
this.grabber.object3D.matrixWorld,
this.grabOffsetMatrix
)
grabeeMatrix.multiplyMatrices(this.parentOffsetMatrix, grabeeMatrix)
// using decomp over direct Object3D.matrix manipulation
// keeps in sync with other A-Frame components
grabeeMatrix.decompose(
this.el.object3D.position,
this.el.object3D.quaternion,
// let stretchable manage scale
ignoreScale
)
}
}
})(),
resetGrabber: function () {
if (!this.grabber) {
return false
}
this.grabber.object3D.updateMatrixWorld()
this.el.object3D.parent.updateMatrixWorld()
// save difference between grabber world matrix and grabee world matrix
this.grabOffsetMatrix
.getInverse(this.grabber.object3D.matrixWorld)
.multiply(this.el.object3D.matrixWorld)
// save difference between grabee world and local matrices
this.parentOffsetMatrix.getInverse(this.el.object3D.parent.matrixWorld)
return true
},
我在框架中使用更新后的 super-hands component。我已经从文档中复制了基本示例(见下文)。
<head>
<title>Most Basic Super-Hands Example</title>
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
<script src="https://cdn.rawgit.com/donmccurdy/aframe-extras/v4.1.2/dist/aframe-extras.min.js"></script>
<script src="https://unpkg.com/super-hands@3.0.0/dist/super-hands.min.js"></script>
</head>
<body>
<a-scene>
<a-assets></a-assets>
<a-entity>
<a-camera></a-camera>
<a-entity sphere-collider="objects: a-box" super-hands hand-controls="left"></a-entity>
<a-entity sphere-collider="objects: a-box" super-hands hand-controls="right"></a-entity>
</a-entity>
<!-- hover & drag-drop won't have any obvious effect without some additional event handlers or components. See the examples page for more -->
<a-box hoverable grabbable stretchable draggable dropppable color="blue" position="0 0 -1"></a-box>
</a-scene>
</body>
在抓取物体并能够影响它们的 position
但不是它们的 rotation
时,开箱即用。我想知道是否有可能(不使用物理学并向控制器添加 static body
)影响目标对象的 rotation
?
我已经能够通过添加相关的混合和相移组件来实现旋转 from this example 但是考虑到似乎可以抓取影响其位置的对象我想知道我是否可以将基本示例修改为更改 rotation
而不是 position
(理想情况下,我可以选择是否影响 position
、rotation
或两者)。我想我可能正在想象创建另一个组件,例如 rotatable
,或者可能是在可抓取组件(例如 grabbable="property: rotation"
的基础上构建,我可以将其添加到目标对象中。
我想知道这在一般情况下是否可行,因为我想更好地了解该组件以便进行更多控制。然而,为了给这个特定问题提供一些背景信息,我遇到了这样一种情况,即超级手控制器是 dynamic-body
的子级,一旦添加了 static-body
,就会导致父级 static-body
的行为出现问题 dynamic-body
。
一如既往地感谢任何建议,如果您需要更多信息,请告诉我。
如果您想在没有物理的情况下进行旋转,则需要实现您自己的 grabbable
版本来执行矩阵数学运算。它会是这样的:
tick: (function () {
const grabeeMatrix = new window.THREE.Matrix4()
const ignoreScale = new window.THREE.Vector3()
return function () {
if (this.grabber) {
grabeeMatrix.multiplyMatrices(
this.grabber.object3D.matrixWorld,
this.grabOffsetMatrix
)
grabeeMatrix.multiplyMatrices(this.parentOffsetMatrix, grabeeMatrix)
// using decomp over direct Object3D.matrix manipulation
// keeps in sync with other A-Frame components
grabeeMatrix.decompose(
this.el.object3D.position,
this.el.object3D.quaternion,
// let stretchable manage scale
ignoreScale
)
}
}
})(),
resetGrabber: function () {
if (!this.grabber) {
return false
}
this.grabber.object3D.updateMatrixWorld()
this.el.object3D.parent.updateMatrixWorld()
// save difference between grabber world matrix and grabee world matrix
this.grabOffsetMatrix
.getInverse(this.grabber.object3D.matrixWorld)
.multiply(this.el.object3D.matrixWorld)
// save difference between grabee world and local matrices
this.parentOffsetMatrix.getInverse(this.el.object3D.parent.matrixWorld)
return true
},