11

我在 Android 项目中使用Sceneform SDK 。

我有我的项目中sfbsfa对象,我希望我的对象的初始旋转旋转 90 度。我怎样才能实现它?

我在这些文件中找到了下一个代码并更改了比例。

但是我没有找到旋转的方法。

model: {
  attributes: [
     "Position",
     "TexCoord",
     "Orientation",
  ],
  collision: {},
  file: "sampledata/models/redmixer.obj",
  name: "redmixer",
  scale: 0.010015,
},
4

4 回答 4

12

我已经使用 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();

如果您对有关四元数的更多信息感兴趣,我推荐:https ://proandroiddev.com/arcore-cupcakes-4-understanding-quaternion-rotations-f90703f3966e 。

但基本上最后一个参数是以度为单位的角度。在这种情况下 90deg -> 90f。通过矢量,您可以指定旋转方向。在示例中,我沿 x 方向 (x,y,z) -> (1f, 0, 0) 旋转。希望能帮助到你。

于 2018-11-17T08:18:16.737 回答
1

不确定这是否是你要找的,但试试这个,它看起来对我来说是一场噩梦,虽然它有效我已经在底部页面的某个地方尝试过,他会向你解释如何旋转 3dobject 寻找这个标题“奖金:让心脏旋转!”

如何在sceneform中做旋转动画

于 2018-07-26T10:17:36.113 回答
0

为避免Gimbal Lock使用四元数旋转。Z要围绕轴旋转 3D 对象,请clock wise遵循以下 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)
    }
}

希望这可以帮助。

于 2019-04-08T13:38:03.033 回答
0

我想我可以帮助你(或者至少指出一个有用的方向)。尝试:

//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)
}

它与上面提到的示例非常相似。希望能帮助到你!

于 2018-08-01T00:19:43.733 回答