繁体   English   中英

使用Sceneform生态系统有问题地旋转3D模型

[英]Problematically rotate 3D model using Sceneform ecosystem

我正在Android Project中使用Sceneform SDK

我有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();

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

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

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

如何在sceneform中进行旋转动画

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

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

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

为避免万向节锁定使用四元数旋转。 对于围绕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)
    }
}

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM