如何在ARCore中调整对象的大小?

Pol*_*ion 9 android object augmented-reality arcore

我在ArFragment中显示了3D对象。因此,我将.obj文件和.mtl文件放在sampledata文件夹中。我右键单击obj文件,然后选择“导入Sceneform资产”以添加.sfa / .sfb文件。

因此,当我标记图像时,我可以显示3d对象,但是对象太大。

这是我的.sfa文件的详细信息

{
   bound_relative_root: {
      x: 0.5,
      y: 0,
      z: 0.5,
   },
   materials: [
      {
         name: "Material.001",
         parameters: [
            {
               baseColor: null,
            },
            {
               baseColorTint: [
                  0.80000000000000004,
                  0.80000000000000004,
                  0.80000000000000004,
                  1,
               ],
            },
            {
               metallic: 1,
            },
            {
               roughness: 0.120695,
            },
            {
               opacity: null,
            },
         ],
         source: "build/sceneform_sdk/default_materials/obj_material.sfm",
      },
   ],
   model: {
      attributes: [
         "Position",
         "TexCoord",
         "Orientation",
      ],
      collision: {},
      file: "sampledata/dongbaek.obj",
      name: "dongbaek",
      recenter: "root",
      scale: 0.200000
   },
   version: "0.52:1",
}
Run Code Online (Sandbox Code Playgroud)

我认为它可以按比例调整大小,但是我更改了值,但没有改变。相同大小

那么如何调整3d对象的大小呢?

添加3d对象文件以制作.sfa / .sfb文件时是否存在任何问题?(导入Sceneform Asset)

如果您知道,请帮助我。

Lad*_*odi 8

对象缩放由缩放控制器更改。通过设置minScale和maxScale值。设置父节点之前-锚节点。请参见下面的示例。

      // 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());
// Maxscale must be greater than minscale
        node.getScaleController().setMaxScale(0.02f);
        node.getScaleController().setMinScale(0.01f);

        node.setParent(anchorNode);
        node.setRenderable(renderable);
        node.select();
Run Code Online (Sandbox Code Playgroud)

  • 您的答案是正确的,尽管我会补充说MaxScale必须大于MinScale,因为那样您会遇到异常。 (3认同)

Man*_*lTS 3

根据您的项目不同的方法:

  1. 更改比例值,重新生成 sfb 文件
  2. 将您的节点放入TransformableNode中,并让ScaleController缩放您的模型
  3. 直接使用setLocalScale或setWorldScale
  4. 缩放 .obj 文件,然后生成 .sfa 和 .sfb 文件