1

是否可以根据真实世界检测图像的大小调整放置模型的大小?我有一幅画,我正在用一个 AR 模型来增强它,一旦检测到图像,它就会替换这幅画。它应该完美地覆盖这幅画。它宽 45 厘米,提供给 XRImageDetectionController 脚本。当我运行我的应用程序时,目标图像在其真实尺寸(45cm X 28cm)中可见,效果符合预期。理想情况下,我希望能够在各种设置中演示这种增强绘画,其中真实世界的图像可能具有不同的大小(保持纵横比相同)。我的特定设备是兼容 ARCore 的安卓手机。

4

1 回答 1

0

我最近开始使用 8th Wall,但我还没有创建自己的项目(只是玩弄了演示项目并查看了源代码),所以我不知道 100% 是否可行,但这里有:

如果您查看 8th WallXRDataTypes.cs文件,您可以找到数据类型XRDetectionTextureXRDetectionImageXRDetectedImageTarget。这些数据类型中的每一个都有一些维度字段的实例。

XRDetectionTexture:

/**
 * A unity Texture2D that can be used as a source for image-target detection.
 */
[Serializable] public struct XRDetectionTexture {

[...]

  /**
   * The expected physical width of the image-target, in meters.
   */
  public float widthInMeters;

[...]
}

XR检测图像:

/**
 * Source image data for a image-target to detect. This can either be constructed manually, or
 * from a Unity Texture2d.
 */
public struct XRDetectionImage {
  /**
   * The width of the source binary image-target, in pixels.
   */
  public readonly int widthInPixels;

  /**
   * The height of the source binary image-target, in pixels.
   */
  public readonly int heightInPixels;

  /**
   * The expected physical width of the image-target, in meters.
   */
  public readonly float targetWidthInMeters;
  [...]
  }
}

XRDetectedImageTarget:

/**
 * An image-target that was detected by an AR Engine.
 */
public struct XRDetectedImageTarget {
  [...]

  /**
   * Width of the detected image-target, in unity units.
   */
  public readonly float width;

  /**
   * Height of the detected image-target, in unity units.
   */
  public readonly float height;
  [...]
}

我自己没有这样做,我不能给你工作代码示例,但是关于图像检测基础的 8th Wall 文档似乎相当不错,实际上确实表明了一个实例XRDetectedImageTarget被传递到指定的回调方法中检测到的模型(图像复制自 8th Wall 文档,2019-01-18):

在此处输入图像描述

因此,如果您知道所需的模型与图像的比率(即“模型的宽度应该是检测到的图像宽度的一半”),那么在回调中您应该能够执行以下操作:

//calculating the size ratio might be more difficult than this, assume this is pseudocode
var sizeRatio = xrDetectedImageTarget.width / xrDetectionImage.targetWidthInMeters;

var placedModel = Instantiate(prefabModel, newPosition, newRotation, parentTransform);
placedModel.transform.localScale = this.transform.localScale * sizeRatio;

希望有效/有帮助!

于 2019-01-18T17:26:37.097 回答