Search Unity

  1. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Scaled Content

Discussion in 'AR' started by jimmya, Oct 17, 2017.

  1. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    793
    During our talk at Unite, Tim and I talked about scaled content and why you would want it. We also discussed why you would not want to scale the content itself, but use "camera-tricks" to do the scaling. We showed two options for scaling content, one of them uses one camera, while the other uses two cameras. The first option (single camera) was shown in the talk. The second (two camera) option is outlined below, and the code and project for it on ARKit Plugin is available at https://bitbucket.org/Unity-Technologies/unity-arkit-plugin/branch/alt-scaled-content

    For the two camera solution, we use one camera to keep track of the GameObjects in the current real world coordinate system e.g. the size and position of the table you are trying to display things on. Lets call this camera the "TrackingDataCamera", and keep this moving and rotating according to what the ARKit device does. It will also render any of the ARKit generated GameObjects, like the debug planes and feature points.

    The second camera, which we will call the "ContentCamera" will have a parent transform that will be positioned and rotated in such a way that rendering the content scene using this camera will make the scene (which is static remember) appear in the right place, and at the right size. How is this achieved? We start with a "content anchor", which is a point in real world coordinates where you want your scaled scene to appear. We calculate the offset of our TrackingDataCamera from this point. We then multiply this offset by the inverse of the scale you desire for your scene (e.g. if you want your city scene to be 1/100 the size, we will multiply the offset by 100). We then translate the parent transform of the ContentCamera to this multiplied offset from the anchor. The camera transform for this ContentCamera still follows the same positioning and rotation of the TrackedCamera, so its orientation matches what device does. See rough sketch for how parent transform is moved.
    IMG_3879.JPG

    How to use this? In the UnityARContentScalingScene, replace the SkyscraperRoot GameObject with whatever scene objects contains your content. When you start the scene, it will look for a surface, and when you tap on the debug plane that describes the surface, it will use that hit position as the "ContentAnchor" noted above. Your content will appear at that position. If you know what scale you want your content at, put that value in ContentCameraParent GameObject in the Content Scale parameter of the Content Scale Maanger component. The GUI + and - buttons can help you find the correct scale for your content if that is not correct.
     
    Last edited: Oct 17, 2017
    GeckoTrader and ina like this.
  2. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    979
    Can you link to your talk? It looks like your post is just on the second option. What's the first option you recommend?
     
    GeckoTrader likes this.
  3. GeckoTrader

    GeckoTrader

    Joined:
    Nov 24, 2016
    Posts:
    8
    During our talk at Unite, Tim and I talked about scaled content and why you would want it. We also discussed why you would not want to scale the content itself

    Why?
     
  4. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    793
  5. daniilkorotin

    daniilkorotin

    Joined:
    Oct 8, 2017
    Posts:
    4
    Jimmya, are you planning to merge any of the scaling branches into `default`? There are quite a few differences in the plugin files, e.g. generating planes is tuned in the `scaled-content-test` branch (they get scaled with the object if trying to use scaling scene with the `default` plugin version). Would be really useful to have the updated code in the `default` branch if there are no conflicts.
     
  6. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    793
    What I was pointing out with the blog post link is the fact that there is now an experimental cross-platform ARInterface, which has a Scaled Content sample with just one camera. That code should work with latest ARKit plugin code.
     
    daniilkorotin likes this.
  7. nickfourtimes

    nickfourtimes

    Joined:
    Oct 13, 2010
    Posts:
    196
    I was just looking through the ScaledContent sample. It looks like the "only" thing you're doing is scaling the parent transform of the AR camera, and that's achieving the scaling of the whole level/scene. Is that correct, or am I missing something?
     
  8. nickfourtimes

    nickfourtimes

    Joined:
    Oct 13, 2010
    Posts:
    196
    Ah, wait, there's also the code in OnBeforeRender which I'm assuming is required. I was hoping it was just the parent-scale stuff, so I could still use it without upgrading from 2017.1, but then if the latter is true, then I guess we need 2017.2 for the Pose stuff.
     
  9. GeckoTrader

    GeckoTrader

    Joined:
    Nov 24, 2016
    Posts:
    8
    I just tested the scaled content for UnityARInterface.
    I can never get to look over the top of the castle as it remain a constant distance from the camera!
    Added Issue to Github.
     
  10. jcfalcone89

    jcfalcone89

    Joined:
    Jun 17, 2015
    Posts:
    11
    For me the issue was more with the ray cast or wrong position. Using 2 cameras was a pain in the ass to make the raycast work properly and with a holder and scale the objects was placed in the wrong place. So I scaled everything down :(
     
  11. JelmerV

    JelmerV

    Joined:
    Nov 29, 2012
    Posts:
    238
    You could look at the scaledcontentplace script for inspiration for your code. Though I haven't completely gotten my head around it either
     
  12. ahartwell

    ahartwell

    Joined:
    Nov 17, 2017
    Posts:
    1
    Anyone have luck porting this to ARCore? Having some trouble finding all of the places that need to be changed.
     
  13. Deleted User

    Deleted User

    Guest

unityunity