Skip to content

Commit d4501a6

Browse files
l0ftywhizzshreyasiyer14
authored andcommitted
Added basic model controller for changing size, playing animations and
made the project Vuforia based.
1 parent 3645d9f commit d4501a6

File tree

407 files changed

+18934
-37
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

407 files changed

+18934
-37
lines changed

Assets/Common.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Common/CameraSettings.cs

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/*===============================================================================
2+
Copyright (c) 2015 PTC Inc. All Rights Reserved.
3+
4+
Copyright (c) 2015 Qualcomm Connected Experiences, Inc. All Rights Reserved.
5+
6+
Vuforia is a trademark of PTC Inc., registered in the United States and other
7+
countries.
8+
===============================================================================*/
9+
using UnityEngine;
10+
using System.Collections;
11+
using Vuforia;
12+
13+
public class CameraSettings : MonoBehaviour
14+
{
15+
#region PRIVATE_MEMBERS
16+
private bool mVuforiaStarted = false;
17+
private bool mAutofocusEnabled = true;
18+
private bool mFlashTorchEnabled = false;
19+
private CameraDevice.CameraDirection mActiveDirection = CameraDevice.CameraDirection.CAMERA_DEFAULT;
20+
#endregion //PRIVATE_MEMBERS
21+
22+
23+
#region MONOBEHAVIOUR_METHODS
24+
void Start ()
25+
{
26+
var vuforia = VuforiaARController.Instance;
27+
vuforia.RegisterVuforiaStartedCallback(OnVuforiaStarted);
28+
vuforia.RegisterOnPauseCallback(OnPaused);
29+
}
30+
#endregion // MONOBEHAVIOUR_METHODS
31+
32+
33+
#region PUBLIC_METHODS
34+
public bool IsFlashTorchEnabled()
35+
{
36+
return mFlashTorchEnabled;
37+
}
38+
39+
public void SwitchFlashTorch(bool ON)
40+
{
41+
if (CameraDevice.Instance.SetFlashTorchMode(ON))
42+
{
43+
Debug.Log("Successfully turned flash " + ON);
44+
mFlashTorchEnabled = ON;
45+
}
46+
else
47+
{
48+
Debug.Log("Failed to set the flash torch " + ON);
49+
mFlashTorchEnabled = false;
50+
}
51+
}
52+
53+
public bool IsAutofocusEnabled()
54+
{
55+
return mAutofocusEnabled;
56+
}
57+
58+
public void SwitchAutofocus(bool ON)
59+
{
60+
if (ON)
61+
{
62+
if (CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO))
63+
{
64+
Debug.Log("Successfully enabled continuous autofocus.");
65+
mAutofocusEnabled = true;
66+
}
67+
else
68+
{
69+
// Fallback to normal focus mode
70+
Debug.Log("Failed to enable continuous autofocus, switching to normal focus mode");
71+
mAutofocusEnabled = false;
72+
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_NORMAL);
73+
}
74+
}
75+
else
76+
{
77+
Debug.Log("Disabling continuous autofocus (enabling normal focus mode).");
78+
mAutofocusEnabled = false;
79+
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_NORMAL);
80+
}
81+
}
82+
83+
public void TriggerAutofocusEvent()
84+
{
85+
// Trigger an autofocus event
86+
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_TRIGGERAUTO);
87+
88+
// Then restore original focus mode
89+
StartCoroutine(RestoreOriginalFocusMode());
90+
}
91+
92+
public void SelectCamera(CameraDevice.CameraDirection camDir)
93+
{
94+
if (RestartCamera (camDir))
95+
{
96+
mActiveDirection = camDir;
97+
98+
// Upon camera restart, flash is turned off
99+
mFlashTorchEnabled = false;
100+
}
101+
}
102+
103+
public bool IsFrontCameraActive()
104+
{
105+
return (mActiveDirection == CameraDevice.CameraDirection.CAMERA_FRONT);
106+
}
107+
#endregion // PUBLIC_METHODS
108+
109+
110+
#region PRIVATE_METHODS
111+
private void OnVuforiaStarted()
112+
{
113+
mVuforiaStarted = true;
114+
// Try enabling continuous autofocus
115+
SwitchAutofocus(true);
116+
}
117+
118+
private void OnPaused(bool paused)
119+
{
120+
bool appResumed = !paused;
121+
if (appResumed && mVuforiaStarted)
122+
{
123+
// Restore original focus mode when app is resumed
124+
if (mAutofocusEnabled)
125+
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
126+
else
127+
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_NORMAL);
128+
}
129+
else
130+
{
131+
// Set the torch flag to false on pause (because the flash torch is switched off by the OS automatically)
132+
mFlashTorchEnabled = false;
133+
}
134+
}
135+
136+
private IEnumerator RestoreOriginalFocusMode()
137+
{
138+
// Wait 1.5 seconds
139+
yield return new WaitForSeconds(1.5f);
140+
141+
// Restore original focus mode
142+
if (mAutofocusEnabled)
143+
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
144+
else
145+
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_NORMAL);
146+
}
147+
148+
private bool RestartCamera(CameraDevice.CameraDirection direction)
149+
{
150+
ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
151+
if (tracker != null)
152+
tracker.Stop();
153+
154+
CameraDevice.Instance.Stop();
155+
CameraDevice.Instance.Deinit();
156+
157+
if (!CameraDevice.Instance.Init(direction))
158+
{
159+
Debug.Log("Failed to init camera for direction: " + direction.ToString());
160+
return false;
161+
}
162+
if (!CameraDevice.Instance.Start())
163+
{
164+
Debug.Log("Failed to start camera for direction: " + direction.ToString());
165+
return false;
166+
}
167+
168+
if (tracker != null)
169+
{
170+
if (!tracker.Start())
171+
{
172+
Debug.Log("Failed to restart the Tracker.");
173+
return false;
174+
}
175+
}
176+
177+
return true;
178+
}
179+
#endregion // PRIVATE_METHODS
180+
}

Assets/Common/CameraSettings.cs.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Common/FrameRateSettings.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*========================================================================
2+
Copyright (c) 2016 PTC Inc. All Rights Reserved.
3+
4+
Copyright (c) 2015 Qualcomm Connected Experiences, Inc. All Rights Reserved.
5+
6+
Vuforia is a trademark of PTC Inc., registered in the United States and other
7+
countries.
8+
=========================================================================*/
9+
using UnityEngine;
10+
using Vuforia;
11+
12+
public class FrameRateSettings : MonoBehaviour
13+
{
14+
#region MONOBEHAVIOUR_METHODS
15+
void Start ()
16+
{
17+
VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);
18+
}
19+
#endregion
20+
21+
22+
#region PRIVATE_METHODS
23+
private void OnVuforiaStarted ()
24+
{
25+
// Query Vuforia for recommended frame rate and set it in Unity
26+
int targetFps = VuforiaRenderer.Instance.GetRecommendedFps(VuforiaRenderer.FpsHint.NONE);
27+
28+
// By default, we use Application.targetFrameRate to set the recommended frame rate.
29+
// Google Cardboard does not use vsync, and OVR explicitly disables it. If developers
30+
// use vsync in their quality settings, they should also set their QualitySettings.vSyncCount
31+
// according to the value returned above.
32+
// e.g: If targetFPS > 50 --> vSyncCount = 1; else vSyncCount = 2;
33+
if (Application.targetFrameRate != targetFps)
34+
{
35+
Debug.Log("Setting frame rate to " + targetFps + "fps");
36+
Application.targetFrameRate = targetFps;
37+
}
38+
}
39+
#endregion
40+
}

Assets/Common/FrameRateSettings.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)