Log in or register to post comments

Black camera feed while invoking unity 5.2.2 with vuforia 4.2.3

October 9, 2015 - 7:37am #1

Hi Guys,

         We are working on update for an existing app using unity, vuforia for iOS.

Device tested: iPhone 6, iPhone 5

Software versions: Unity 5.2.2, Vuforia 4.2.3[Classic license] iOS target :8 , Xcode :6.4

Scenario:
   The app ui is built in iOS and when AR is required we invoke unity with a button. 

1) We invoke a function in unityappcontroller which has the following code:

 UnityInitApplicationNoGraphics([[[NSBundle mainBundle] bundlePath] UTF8String]);
 
        [self selectRenderingAPI];
        
        [UnityRenderingView InitializeForAPI:self.renderingAPI];
        
        //_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
        
        _unityView = [self createUnityView];
 
        [DisplayManager Initialize];
        
        _mainDisplay = [DisplayManager Instance].mainDisplay;
        
        _window = a.window;
        
        [_mainDisplay createWithWindow:a.window andView:_unityView];
 
        [self createUI];
        
        [self preStartUnity];
        
        //new unity 5 code start
        
        [self startUnity:[UIApplication sharedApplication]];

Since we have already created a window we are trying to pass this window to unitycontroller.

2) The whole sequence works fine but the vuforia loads with a black screen but it does recognise markers and is also able to augment models.

The camera feed is not visible.

What we tried and failed:

1) We initiated vuforia load with a 10 sec delay once unity is loaded but still things dint change.

2) Tried to capture the videobackground texture and apply to a cube object and check. Still cube looked black.

PS: This setup was working fine with unity 3.5 and vuforia 3.X where display manager was not there.

 

 

 

Black camera feed while invoking unity 5.2.2 with vuforia 4.2.3

October 14, 2015 - 1:56am #3

Note: I would recommend to upgrade to the latest Vuforia 5.0 and Xcode 7.0.1 or newer. The example I posted below has been tested on those platforms.

Black camera feed while invoking unity 5.2.2 with vuforia 4.2.3

October 14, 2015 - 1:53am #2

Hi, 

it is possible to integrate a Unity scene into an Xcode project that contains multiple view controllers (with one of them being the Unity scene, and the others being "native" view controllers).

I was able to do that with Vuforia 5.0 and Unity 5.1 by following this nice tutorial that I've found online:

http://www.the-nerd.be/2014/08/06/add-unity3d-in-a-native-ios-application/

There are however a few things that need to be adapted from the tutorial above, to make it work with Vuforia 5.0; in particular, you do not need to create a custom "UnityAppController" class in your Xcode project, because Vuforia 5.0 already provides one for you, called VuforiaNativeRendererController (located in Assets/Plugins/iOS), which already overrides the UnityAppController interface.

You then need to add some code into the VuforiaNativeRendererController class (in the .mm file), specifically:

  • declare the createViewHierarchyImpl method:
- (void)createViewHierarchyImpl;

 

  • and then implement it (in the class implementation section) along the lines of the example given below:
- (void)createViewHierarchyImpl
{
    NSLog(@"Creating custom view hierarchy ...");
    
    _rootController = [[UIViewController alloc] init];
    _rootView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    _rootController.view = _rootView;
    
    IntroViewController *introVC = [[IntroViewController alloc] initWithNibName:nil bundle:nil];

    self.navController = [[UINavigationController alloc] initWithRootViewController:introVC];
    [_rootView addSubview:self.navController.view];
}

 

Note that in the example above, I refer to a "IntroViewController", which represents a UIViewController that I've defined to appear as first view controller in the application; in your case, you can replace it with whichever custom ViewController class you have, playing the same role.

 

Your Unity Vuforia scene will then be included in another view controller class that you also need to define, for example, something similar to the following:


#import "UI/UnityView.h"
#import "UI/UnityViewControllerBase.h"
#include "UnityAppController+ViewHandling.h"

#import "LastViewController.h"


#import "VuforiaUnitySceneViewController.h"

@interface VuforiaUnitySceneViewController ()

@end

@implementation VuforiaUnitySceneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.view addSubview:GetAppController().unityView];
    
    GetAppController().unityView.frame = self.view.frame;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

Log in or register to post comments