简体   繁体   English

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

[英]Problematically rotate 3D model using Sceneform ecosystem

I'm using the Sceneform SDK in Android Project. 我正在Android Project中使用Sceneform SDK

I have sfb and the sfa objects in my project, and I want the initial rotation of my object to be rotated 90 degrees. 我有sfbsfa在我的项目对象,我想我的对象的初始旋转旋转90度。 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. 我已经使用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();

If you would be interested in more info about Quaternion I recommend: https://proandroiddev.com/arcore-cupcakes-4-understanding-quaternion-rotations-f90703f3966e . 如果您对Quaternion的更多信息感兴趣,我建议: https//proandroiddev.com/arcore-cupcakes-4-understanding-quaternion-rotations-f90703f3966e

But basically last parameter is angle in degrees. 但基本上最后一个参数是角度度。 In this case 90deg -> 90f. 在这种情况下,90deg - > 90f。 By vector you specify direction of the rotation. 通过矢量,您可以指定旋转方向。 In example I have rotated in x direction (x,y,z) -> (1f, 0, 0). 在示例中,我在x方向上旋转(x,y,z) - >(1f,0,0)。 Hope it helps. 希望能帮助到你。

Not sure if this is what you looking for but try this it looks to me nightmare though it works i have tried it somewhere at the bottom page he will explain to you how to rotate the 3dobject look for this title "Bonus: Make the heart rotate!" 不确定这是不是你想要的但尝试这个它看起来对我来说噩梦虽然它有效但我已经在底部的某个地方试过了他会向你解释如何旋转3dobject寻找这个标题“Bonus:让心脏旋转!”

how to do rotatation animation in sceneform 如何在sceneform中进行旋转动画

I think I can help you (or at least point in a helpful direction). 我想我可以帮助你(或者至少指出一个有用的方向)。 Try: 尝试:

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

It is quite similar to the above mentioned example. 它与上面提到的例子非常相似。 Hope it helps! 希望能帮助到你!

To avoid Gimbal Lock use a Quaternion rotation. 为避免万向节锁定使用四元数旋转。 For rotating a 3D object around Z axis clock wise follow this Kotlin code: 对于围绕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)
    }
}

Hope this helps. 希望这可以帮助。

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

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