Vuforia not showing what the webcam sees in Unity while still capturing the marker - unity3d

I am making a first-person game using Unity and Vuforia. What I'm trying to achieve is that the user can have a marker attached on an object that can be held in his hand (a bottle, a book, or toy). So when he plays the game, he can hold the object in his hand, have the object facing the webcam, and move or rotate the object to control the first person character in Unity, e.g., tilt the marker-attached bottle in physical world so the first person character moves forward in Unity's virtual world. ps. by virtual world I mean just a basic first-person character walking around in a room, not the kind of VR that involves Oculus Rift.
I just played around with Vuforia. The good thing is I can choose my own image as the marker (looks like not every marker-based Unity plug-in can do this). But with Vuforia, can I create a virtual environment that's not showing the webcam's view? I did a basic Vuforia + Unity tutorial that only shows what the webcam captures and overlays a virtual cube on the detected marker. Summary of what I need is: not showing the webcam's view but still have the webcam functioning that it can capture the marker and I can use its position/rotation. In a way you can say I am just using the marker+webcam combo as a sensor used to control my virtual world activity.
Thanks!

From what I get it appears you want to use your marker as a target object to control motion in AR..
You'll have to build the functionality in Unity only as to what you want it to do specifically according to your set gameplay..
For example if you want a virtual dog to follow a target object, one easy way to do it is to provide an offset between the marker and the game Object and play a walking/running animation.
So it will appear as if the object is always following the marker, whereas in reality it is playing same animation at a constant distance.
As far as importing the marker is concerned.. It is no different than what you must have done with your cube..
In your Vuforia account Dev Portal:
Download the Vuforia SDK and import in your Unity asset folder.
Go to Liscense Manager under Develop tab and add a Liscense Key.
Now go to the Target Manager and add your images in the Databse which you want as target. (make sure the image quality is good for it to work prperly)
Now download the database and import it in your Assets folder in Unity.
Now go to your Liscense Manager again and copy your Liscense key and Open Vuforia Configuration under Vuforia Behaviour (Script) when you click on AR Camera, you'll find a dialog box there, paste this key there.
Save the build and run your game in Unity and bring the marker in front of the Webcam and it should work properly.
Hope this helps.

Related

Unity gear VR reticle pointer shows double when focusing on close objects

I'm developing a VR app in Unity for the Samsung Gear VR and I'm trying to implement a pointer so the user can interact with the objects in the scene. When you look at distant objects it looks fine, but when you focus on close objects (which is highly needed for the app mechanics) the pointer appears to be duplicated, so you need to center the desired object in the middle of the points :P
What I've tried
-Using the GvrReticlePointer that comes with the GoogleVR package for cardboard
-Creating my own pointer by adding a canvas to the main camera with an image in the center
-Changing some of the Camera settings like field of view, stereo separation, etc.
-Configure my phone via a QR code http://imgur.com/fVrNrQk
Steps to reproduce (With canvas added to camera)
1.- Create a simple scene with a few objects to look at in Unity
2.- Set build settings for android
3.- Configure player settings to enable "Virtiual Reality Supported"
4.- Add Oculus as Virtual Reality SDK
5.- Set package name and minimum API level
6.- Add a canvas to the camera
7.- Add an image to the canvas, a cross will do the job
Observations
I'm using Unity 5.6.0b10 since google cardboard's site recommends using this version for the GoogleVR package. And I'm using the Samsung Gear VR with a Samsung Galaxy S6 edge + phone.
Solved
Apparently this is a well documented issue called voluntary Diplopia, and it's a human bug not a software one (read here, Unity's documentation, section The Reticle Interaction in VR).
The problem is trying to put the reticle at a fixed point in the user interface, like traditional 3D games. When looking at closer objects in VR this is going to cause this seeing double problem.
The solution is to position the reticle at the point in the 3D space the user is looking at. If he's looking closer, the reticle is drawn closer. Of course now you also have to scale the reticle accordingly, so the users can see it the same size no matter where they're looking at.
Unity also provides some example scripts about this, you can find them in the assets store, is called VR Samples.
Now I have performance issues (I'm working on mobile platforms): sometimes, when you turn your head fast you can see the reticle where it was drawn before. But looks way better than the double reticle version.

3d FBX file import into Unity not working as expected

I am interested in building virtual reality applications and I am at beginner level.
I imported a FBX file of Airplane and imported it in Unity,
Upon linking the animation in Unity and building it onto my Mobile, I see a 2D version of the model. How should I convert it into virtual reality application.
Below is a snalshot of the file. The aiation is also fairly simple, one plane takes off and flies for sometime before landing.
Below is a snapshot of the Game Console
So inshort the question is how do I convert this into a 3D mode so that I can use it as a virtual reality Application.
Thank you
That is 3D mode.
Making a VR application isn't done at the push of a button
Start here:
Read about VR in unity
It seems like you are a new Unity user. If so do this first:
Depending on what you want to do in your application you should look into the Unity Documentation and read about:
Basics
Cameras
Creating Gameplay
Animation
If you at some point feel you don't understand these links, you may need to take another step back and start off by checking out the official tutorials
Just save your .blend file in the Unity's Assets folder.
Look at the documentation for more informations

Accessing Main Camera Left and Right in Unity / google-vr

This is a follow up to this question regarding how to display objects on one camera only in google-vr and unity.
In the current demo project of Unity and Google-vr, I can only access Main Camera Left and Main Camera Right while running the game. During runtime, I am able to disable a layer with the culling mask of one camera.
But I am not able to save those changes while running the game. If I stop, the two Main Cameras Left/Right disappear and I only see Main Camera and GvrReticle as child.
I suspect the cameras are created or imported from a prefab during runtime.
What would be the right way to have the left / right cameras accessible when not running the screne?
It's mentioned in the guide:
Often you will wish to add the stereo rig to your scene in the Editor rather than at runtime. This allows you to tweak the default parameters of the various scripts provided in this plugin, and provides a framework on which to add additional scripts and objects, such as 3D user interface elements.
To turn your Camera into a stereo camera, select the Camera (or Cameras) in the Hierarchy panel, then execute the main menu command Component > Google VR > Update Stereo Cameras.

Vuforia recognition of hand painted marker

I have blank sheet and I want to do AR model to this sheet. I have idea do it with painted marker. For example: cross, square or something easy marker which you can paint to sheet. So how can i do it??? I use unity.
Here you want a simple marker so some simple options are:
ARToolkit Simple markers like Hiro KanZI marker (it's an open source and completely free AR Library):
http://artoolkit.org/documentation/doku.php?id=3_Marker_Training:marker_multi
Using Vuforia, you can try "Frame Marker". Vuforia provides more than 500 simple designs. You can paint it or stick it on your sheet:
https://developer.vuforia.com/library/articles/Training/Frame-Markers-Guide
FYI: Vuforia and Artoolkit for both Unity packages are available for free. You just have to import it into your Unity project.
I am writing from memory, so it might not be entirely correct.
Decide what marker you want to use.
Draw it on paper. Note, however, that the Vuforia SDK identifies points of interest in a target image (most often that is corners), so the more detailed a photo, the more points of interest, which is why their samples use high resolution images of e.g. lots of little stones. Drawing something like a square, cross, or some other simplistic marker, does not work very well.
Take a photo of it and transfer it to your computer.
Download Vuforia's Augmented Reality SDK for Unity.
Register on the Vuforia website and add your photo as an Image Target. Then save/download the database unity package they create for you from your image.
Also get a licence key.
In a blank Unity scene, import the SDK.
Add an AR camera prefab.
Add an image target prefab.
Import the downloaded database package (containing your uploaded image).
On the image target inspector, change the behaviour to use your image as the image target.
On the AR camera inspector, add your licence key, and specify the image target database.
Create or import some 3D model / primitive. Make it a child of the image target, and position it to sit on top of the image target.
Make sure the AR camera is looking at the image target.
Build the project and run the project, that's about it.
There should be many tutorials online, just google for something like vuforia augmented reality tutorial

How to create VR Video player using Google Cardboard SDK for Unity

I just downloaded Google Cardboard SDK for unity. I am fine and able to create VR project. Setup is fine and everything is working fine.
I am noob at VR Apps. Just stepped in VR Apps.
I am planing to create my own VR Enabled Video Player for android, Just like the default Google Cardboard Youtube player.
Can any one suggest me a link or can guide me in developing this app.
Scott Driscoll's answer totally works. I had some initial problems getting the Easy Movie Texture Unity plug-in to work for me, but finally figured it out, and it works flawlessly. I now have 360-video running as a texture on the inside of a sphere on my iPhone 6. And I have to say, I didn't think it would happen.
For working on a Mac, here's what I did:
Download the Easy Movie Texture plug-in from the Unity Asset Store
Open the Demo Sphere demo scene from Assets/EasyMovieTexture/Scene
Create a new (empty) Prefab to your project, and drag the Sphere GameObject from the Demo Sphere scene onto the Prefab.
Reopen your Cardboard scene and drag the new videosphere prefab into your hierarchy.
Open your source 360-video in Quicktime
File -> Export -> 720p
Change file extension from '.mov' to '.mp4'
Drag your new mp4 file into your projects Assets/Streaming Assets directory. Note: don't import through the menu system, as this will force Unity to convert to OGG.
On the "Media Player Ctrl" script component of your videosphere GameObject, locate the "Str_File_Name" field and provide the FULL filename. Make sure to include the extension as part of the string, "mymovie.mp4".
Pretty sure that's everything. Hope it helps other folks stuck on this problem. Thanks Scott Driscoll!
One last note, you can only view the video on the phone, not in preview in the editor. It would be better if it didn't work this way, but really once the initial issues of resolution and placement are resolved, I don't really need to see the video every time I run the scene in the editor.
Here are the major steps for how we do this:
Add a sphere with an equirectangular UV mapping and inward facing normals around the camera.
Purchase a plugin to play a movie on that sphere’s texture. I recommend Easy Movie Texture.
Use mp4s or ogg vorbis files that are compatible with the platform. This is phone and OS dependent.
Full details: http://immersivetechblog.foundry45.com/2015/07/31/implementing-360-video-in-unity-for-gear-vr-and-cardboard/
I saw the answers above but all of them either required Easy Movie Texture Unity plug-in or coding your way through..
There's another easy solution to this as well which won't require you to buy that asset or code your way through..
Oculus provides an already built free sample framework which you can use without much trouble..
The solution below shows both how to create both a photo viewer as well as video viewer for Unity..
Building your 360 degree PhotoViewer:
Go to Blender and delete all the prexisitng objects (if any) and make an icosphere and increase the subdivisions to a point where it looks more like a sphere like 6 and hit Generate UVs (both these options are found in settings underneath the create tab in add to sphere) and go to edit and choose Flip Normals so that you can see inside out rather than outside inwards and save it.
Bring that icosphere saved file into your assets folder in Unity.
Download GoogleVR SDK and bring GoogleVR plugin into your assets folder as well.. (You can download it here: https://developers.google.com/vr/unity/)
Delete the main camera and directional light present in default.
Bring your icosphere asset into your project.
Bring GVR Main from your assets folder into your project: GoogleVR plugin -> Legacy -> Prefab -> GVR Main
Take any panaroma or 360 photo and bring it in your assets folder.
Take this photo in your asset folder and put it above the icosphere in your scene and hit play. You should be able to see your 360 degree photos.
Building your 360 degree MoviePlayer:
Step 1 same.
Now go to the Oculus developer console and download this file and bring this to your assets folder. https://developer3.oculus.com/downloads/game-engines/1.5.0/Oculus_Sample_Framework_for_Unity_5_Project/
Bring this file you downloaded above to your assets folder.
Find MoviePlayer in your assetsFolder in bring it in your project.
Bring the icosphere you downloaded into your assets folder as well and scale it a little bit so you can see correctly.
Copy the MoviePlayer sample script and Audio Source in the components of the MovieSurface from the project and add it in the components of the sphere in the scene, also get rid of the animator in the components of the sphere.
Bring the Movie Player material found in the Materials under Mesh Renderer in MovieSurface and add it on top of your sphere.
Now this sphere formed is your 360 degree movie player so store it as an asset in the asset folder.
Create a new scene, delete the directional light and bring your saved icosphere asset into this scene and move the main camera at the centre.
Delete the non required assets to clean up some space in your project other than MoviePlayer, Plugins and Streaming Assets.
You'll have to convert the desired mp4 into an ogv file as well for the plugin to play in VR and bring both the mp4 and ogv files into your streaming assets folder and change the MovieName and click Play. You should be able to see your 360 degree video playing.
*To play it in your devices, just go to build settings and choose the desired platform and delete all the scene and just Add Open Scene and click on the Virtual Reality Supported in Other Settings under Player Settings.
To play it in your android phone you need to download the GoogleVR SDK just like above and bring it in your assets folder and find the GVRViewerMain in the assets folder and bring it in the scene and uncheck the Virtual Reality Supported you did above and just build and run the whole thing in your device (You should be able to see the view in you game mode when you hit play in Unity).
You should be able to see the video in your respective gear.
There's also a video tutorial available but I'm only able to share only 2 links with my new StackOverFlow profile.
I can't help you with Unity, but in java, you can create a texture with OpenGL-ES:
private static int GL_TEXTURE_EXTERNAL_OES = 0x8D65;
....
GLES20.glGenTextures(1, textureHandle, 0);
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureHandle[0]);
Use it to create a surface texture and a surface:
SurfaceTexture surfaceTexture = new SurfaceTexture(textureHandle[0]);
Surface surface = new Surface(surfaceTexture);
And then pass that surface to android.media.MediaPlayer:
MediaPlayer mediaPlayer = new MediaPlayer(getContext(), uriToMyMediaFile, surface);
Bind that texture to a square in your scene and call this every frame:
surfaceTexture.updateTexImage()
and the video will play when you call mediaPlayer.start();
If Unity allows you to write your own java code to run behind the scenes, this should work if you bind that texture to a surface from Unity.
If you have a video stream that you can't play with mediaPlayer (like a live video chat, etc), you can use the surface with android.media.MediaCodec as well, but there's a lot more setup work involved.
This has become very simple for Unity 5.6 and above.
You just need a sphere with its normals inverted which you can either find online or just go to blender and make an IcoSphere and flip its normals or you can use a shader to do the same on a normal sphere. In either case use an Unlit texture for the shader.
Add a Video Player in the component which comes default with Unity to this sphere.
Add any 360 degree video to this Video Player. You can also add an online link as well. And it plays consistently well throughout the range of platforms from GoogleVR to SteamVR.
The only downside is, it only plays monoscopic images/videos by default and there requires some tweaking to run stereoscopic images/videos.