Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.07k stars 1.15k forks source link

3D model with Image tracking is scaled 1D #142

Closed alessiograncini closed 4 years ago

alessiograncini commented 5 years ago

Once I inserted in the ImgeInfoprefab a simple cube on the image, the cube is scaled 1D toward Y-direction. How to avoid this ? Did This happen to you ? thanks

alessiograncini commented 5 years ago

I ended up fixing it this way trackedImage.transform.localScale = new Vector3(trackedImage.size.x, 0.3f, trackedImage.size.y);

that 0.3 was 1 before. If there is a better ad more official fix, please go for it. Thank you.

LucasRizzotto commented 5 years ago

This really needs a fix.

ElliotMebane commented 5 years ago

I was seeing the Y-axis stretching and ultimately solved it, though I'm not sure if it was a configuration/package setting or simply setting uniform Vector3s for the scaling.

In OnTrackedImagesChanged I set a uniform Vector3 for the trackedIMage scale: trackedImage.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f);

In UpdateInfo I also use a uniform Vector3 for the scale: trackedImage.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);

My cube is at the first level of the hierarchy in the ImageInfo prefab (sibling with PlaneParent and Canvas).

Configuration:

Mac, OS 10.14.5

Unity 2019.3.0a5 ARKit XR Plugin preview.5 - 2.1.0 (abandoned version: preview.1 - 2.2.0 due to Xcode build errors mentioned in forum post below) ARFoundation from GitHub branch 2.1 (2019.07.04 downloaded), shows up as preview.3 - 2.1.0 in Package Manager. I also updated it to preview. 2 2.0 within Package Manager to try it and it works too. https://github.com/Unity-Technologies/arfoundation-samples/tree/2.1

Build Settings: Run in Xcode as Release Requires ARKit support not checked Target Min. iOS Version 11 (default) Quality Medium (iOS default)

iPad Pro 9.7 inch OS 12.3.1

Build Error (resolved): ARKit XR Plugin 2.2.0-preview.1 will only work with Xcode 11 and iOS 13. https://forum.unity.com/threads/error-when-building-samplescene-from-arfoundation-to-iphone-6s.545338/

(Filename: currently not available on il2cpp Line: -1)

UnityException: Transform child out of bounds at TrackedImageInfoManager.UpdateInfo (UnityEngine.XR.ARFoundation.ARTrackedImage trackedImage) [0x00000] in <00000000000000000000000000000000>:0 at TrackedImageInfoManager.OnTrackedImagesChanged (UnityEngine.XR.ARFoundation.ARTrackedImagesChangedEventArgs eventArgs) [0x00000] in <00000000000000000000000000000000>:0 at System.Action1[T].Invoke (T obj) [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.XR.ARFoundation.ARTrackedImageManager.OnTrackablesChanged (System.Collections.Generic.List1[T] added, System.Collections.Generic.List1[T] updated, System.Collections.Generic.List1[T] removed) [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.XR.ARFoundation.ARTrackableManager`4[TSubsystem,TSubsystemDescriptor,TSessionRelativeData,TTrackable].Update () [0x00000] in <00000000000000000000000000000000>:0

HawkenKing commented 5 years ago

what is the correct way to make a 3d model follow a marker? I also encountered the scale issue

alessiograncini commented 5 years ago

Thanks for the reply @ElliotMebane . I will look into that. @HawkenKing the correct way it's swapping the prefab spot [I guess] getting its transform and relative scale with the image. I suggest to make a new script that has an array or list of game objects that any x action swap the original prefab keeping scale and position inheriting some parameters from the trackerimageinfo script. If I will develop more with that, will be posting.

spvn commented 4 years ago

Why was this closed? There's still no resolution to it? My 3D prefabs are still getting scaled in Y direction when they're spawned

spvn commented 4 years ago

Ok for anyone encountering this, if you're using the ARFoundation samples for your own 3D model, take note that the TrackedImageInfoManager sets the scale of your object in OnTrackedImagesChanged.

JShull commented 3 years ago

@spvn thank you for this comment... For the life of me could not figure out why my object was being scaled down.

spvn commented 3 years ago

@JShull goodness I don't even remember working with ARFoundation 1 year ago. glad to have helped and good luck with ARFoundation lol.