使用Sceneform生态系统有问题地旋转3D模型 [英] Problematically rotate 3D model using Sceneform ecosystem

查看:268
本文介绍了使用Sceneform生态系统有问题地旋转3D模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Android Project中使用 Sceneform SDK . /p>

我在项目中有sfbsfa对象,并且我希望将对象的初始旋转角度旋转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();

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

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

I'm using the Sceneform SDK in Android Project.

I have sfb and the sfa objects in my project, and I want the initial rotation of my object to be rotated 90 degrees. How can I achieve it?

I found the next code in these files and I changed the scale.

But I didn't find a way for the rotation.

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

解决方案

I have used setLocalRotation to successfully rotate object for 90 degrees programatically.

      // 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();

If you would be interested in more info about Quaternion I recommend: https://proandroiddev.com/arcore-cupcakes-4-understanding-quaternion-rotations-f90703f3966e.

But basically last parameter is angle in degrees. In this case 90deg -> 90f. By vector you specify direction of the rotation. In example I have rotated in x direction (x,y,z) -> (1f, 0, 0). Hope it helps.

这篇关于使用Sceneform生态系统有问题地旋转3D模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆