[英]Problematically rotate 3D model using Sceneform ecosystem
我正在Android Project中使用Sceneform SDK 。
我有sfb
和sfa
在我的項目對象,我想我的對象的初始旋轉旋轉90度。 我怎樣才能實現它?
我找到了這些文件中的下一個代碼,我改變了比例。
但我沒有找到輪換的方法。
model: {
attributes: [
"Position",
"TexCoord",
"Orientation",
],
collision: {},
file: "sampledata/models/redmixer.obj",
name: "redmixer",
scale: 0.010015,
},
我已經使用setLocalRotation以編程方式成功旋轉對象90度。
// Create the Anchor.
Anchor anchor = hitResult.createAnchor();
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(arFragment.getArSceneView().getScene());
// Create the transformable andy and add it to the anchor.
TransformableNode node = new TransformableNode(arFragment.getTransformationSystem());
//set rotation in direction (x,y,z) in degrees 90
node.setLocalRotation(Quaternion.axisAngle(new Vector3(1f, 0, 0), 90f));
node.setParent(anchorNode);
node.setRenderable(renderable);
node.select();
如果您對Quaternion的更多信息感興趣,我建議: https : //proandroiddev.com/arcore-cupcakes-4-understanding-quaternion-rotations-f90703f3966e 。
但基本上最后一個參數是角度度。 在這種情況下,90deg - > 90f。 通過矢量,您可以指定旋轉方向。 在示例中,我在x方向上旋轉(x,y,z) - >(1f,0,0)。 希望能幫助到你。
不確定這是不是你想要的但嘗試這個它看起來對我來說噩夢雖然它有效但我已經在底部的某個地方試過了他會向你解釋如何旋轉3dobject尋找這個標題“Bonus:讓心臟旋轉!”
我想我可以幫助你(或者至少指出一個有用的方向)。 嘗試:
//Assuming you have created an anchor through hitResult or some other method and have
//an ArFragment variable "fragment"
ModelRenderable.builder().setSource(context, Uri.parse("your-model.sfb").thenAccept{
addModel(it, anchor)
}
fun addModel(model: ModelRenderable, anchor: Anchor){
val aNode = AnchorNode(createAnchor)
val tNode = TransformableNode(fragment.transformationSystem)
//set rotation properties here
tNode.rotationController...
tNode.localRotation...
tNode.setParent(aNode)
fragment.ArSceneView.scene.addChild(aNode)
}
它與上面提到的例子非常相似。 希望能幫助到你!
為避免萬向節鎖定使用四元數旋轉。 對於圍繞Z
軸clock wise
旋轉3D對象,請遵循以下Kotlin代碼:
override fun onRight(value: Float) {
objectNode.apply {
Log.d("Clock Wise", value.toString())
// XYZ is rotation direction, W component is angle size in degrees
rotation = Quaternion.axisAngle(Vector3(0.0f, 0.0f, 1.0f), -45.0f)
}
}
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.