是否可以根据现实世界中检测到的图像的大小来调整放置模型的大小?我有一幅画,正在使用AR模型进行扩充,一旦检测到图像,该模型将替换该画。它应该完美地覆盖绘画。它的宽度为45厘米,并提供给XRImageDetectionController脚本。当我运行应用程序时,目标图像在其真实尺寸(45cm X 28cm)中可见,效果是预期的。理想情况下,我希望能够在各种设置中演示此增强绘画,这些设置中的真实世界图像可能具有不同的大小(保持宽高比相同)。我的特定设备是兼容ARCore的Android手机。
答案 0 :(得分:0)
我最近开始使用8th Wall,但是我还没有创建自己的项目(只是玩弄了演示项目并检查了源代码),所以我不知道100%是否可行,但这里去了:
如果查看第8墙XRDataTypes.cs
文件,则可以找到数据类型XRDetectionTexture
,XRDetectionImage
和XRDetectedImageTarget
。这些数据类型中的每一个都有一些维域实例。
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;
[...]
}
XRDetectionImage:
/**
* 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 documentation on the basics of image detection似乎很不错,实际上表明了{{ 1}}传递到在检测到的模型上指定的回调方法(图像从8th Wall文档复制,2019年1月18日):
因此,如果您知道所需的模型与图像的比例(即“模型的宽度应为检测到的图像的宽度的一半”),那么在回调中,您应该可以执行以下操作:
XRDetectedImageTarget
希望能起到帮助作用!