【问题标题】:Problematically rotate 3D model using Sceneform ecosystem使用 Sceneform 生态系统有问题地旋转 3D 模型
【发布时间】:2019-01-02 16:40:07
【问题描述】:

我在 Android 项目中使用Sceneform SDK

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

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

但我没有找到轮换的方法。

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

【问题讨论】:

  • 您想显示它已经旋转还是在运行时旋转它?
  • @Fixus 已经旋转了。
  • 您可能想在github.com/google-ar/sceneform-android-sdk/issues 提交功能请求,因为在 SFA 文件中包含这样的内容是有意义的(我们已经有了规模......所以为什么不轮换?)跨度>

标签: android model augmented-reality arcore sceneform


【解决方案1】:

我已使用 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) 旋转。希望对您有所帮助。

【讨论】:

  • 它旋转但带有选择锚(白色圆圈),如何防止它?
【解决方案2】:

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

how to do rotatation animation in sceneform

【讨论】:

    【解决方案3】:

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

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

    它与上面提到的示例非常相似。希望对您有所帮助!

    【讨论】:

      【解决方案4】:

      为了避免Gimbal Lock 使用四元数旋转。要围绕 Zclock 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)
          }
      }
      

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-05
        • 1970-01-01
        • 2016-07-26
        • 1970-01-01
        • 2021-06-24
        • 1970-01-01
        • 2015-09-07
        • 2016-07-19
        相关资源
        最近更新 更多