summaryrefslogtreecommitdiff
path: root/Runtime/Video/ScriptBindings/UnityEngineWebCamTexture.txt
blob: 278d7dd5f6a35eb8010d5895d1df168f09b26f92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
C++RAW

#include "UnityPrefix.h"
#include "Configuration/UnityConfigure.h"
#include "Runtime/Scripting/ScriptingManager.h"
#include "Runtime/Scripting/ScriptingExportUtility.h"
#include "Runtime/Mono/MonoBehaviour.h"
#include "Runtime/Video/VideoTexture.h"

CSRAW

namespace UnityEngine
{

CONDITIONAL ENABLE_WEBCAM
// *undocumented*
ENUM WebCamFlags
	// Camera faces the same direction as screen
	FrontFacing = 1,
END


CONDITIONAL ENABLE_WEBCAM
// A structure describing the webcam device.
STRUCT WebCamDevice
	// A human-readable name of the device. Varies across different systems.
	CSRAW public string name { get { return m_Name; } }

	// True if camera faces the same direction a screen does, false otherwise.
	CSRAW public bool isFrontFacing { get { return (m_Flags & ((int)WebCamFlags.FrontFacing)) == 1; } }

	CSRAW internal string m_Name;
	CSRAW internal int m_Flags;
END


CONDITIONAL ENABLE_WEBCAM
// WebCam Textures are textures onto which the live video input is rendered
CLASS WebCamTexture : Texture

	CUSTOM private static void Internal_CreateWebCamTexture ([Writable]WebCamTexture self, string device, int requestedWidth, int requestedHeight, int maxFramerate)
	{
		WebCamTexture* texture = NEW_OBJECT_MAIN_THREAD (WebCamTexture);
		texture->Reset();
		Scripting::ConnectScriptingWrapperToObject (self.GetScriptingObject(), texture);
		texture->AwakeFromLoad(kInstantiateOrCreateFromCodeAwakeFromLoad);
		texture->SetRequestedWidth (requestedWidth);
		texture->SetRequestedHeight (requestedHeight);
		texture->SetRequestedFPS (maxFramerate);
		texture->SetDevice (device);
	}

	// Create a WebCamTexture

	CSRAW public WebCamTexture (string deviceName, int requestedWidth, int requestedHeight, int requestedFPS)
	{
		Internal_CreateWebCamTexture (this, deviceName, requestedWidth, requestedHeight, requestedFPS);
	}

	///*listonly*
	CSRAW public WebCamTexture (string deviceName, int requestedWidth, int requestedHeight)
	{
		Internal_CreateWebCamTexture (this, deviceName, requestedWidth, requestedHeight, 0);
	}

	///*listonly*
	CSRAW public WebCamTexture (string deviceName)
	{
		Internal_CreateWebCamTexture (this, deviceName, 0, 0, 0);
	}

	///*listonly*
	CSRAW public WebCamTexture (int requestedWidth, int requestedHeight, int requestedFPS)
	{
		Internal_CreateWebCamTexture (this, "", requestedWidth, requestedHeight, requestedFPS);
	}

	///*listonly*
	CSRAW public WebCamTexture (int requestedWidth, int requestedHeight)
	{
		Internal_CreateWebCamTexture (this, "", requestedWidth, requestedHeight, 0);
	}

	///*listonly*
	CSRAW public WebCamTexture ()
	{
		Internal_CreateWebCamTexture (this, "", 0, 0, 0);
	}

	// Starts the camera
	AUTO void Play();

	// Pauses the camera.
	AUTO void Pause();

	// Stops the camera
	AUTO void Stop();

	// Returns if the camera is currently playing
	AUTO_PROP bool isPlaying IsPlaying

	// Set this to specify the name of the device to use.
	CUSTOM_PROP string deviceName { return scripting_string_new(self->GetDevice ()); } { self->SetDevice (value); }

	// Set the requested frame rate of the camera device (in frames per second).
	AUTO_PROP float requestedFPS GetRequestedFPS SetRequestedFPS

	// Set the requested width of the camera device.
	AUTO_PROP int requestedWidth GetRequestedWidth SetRequestedWidth

	// Set the requested height of the camera device.
	AUTO_PROP int requestedHeight GetRequestedHeight SetRequestedHeight

	CONDITIONAL UNITY_IPHONE_API
	CUSTOM_PROP bool isReadable { return self->IsReadable(); }

	CONDITIONAL UNITY_IPHONE_API
	CUSTOM void MarkNonReadable() { self->SetReadable(false); }

	// Return a list of available devices.
	CUSTOM_PROP static WebCamDevice[] devices
	{
		MonoWebCamDevices devs;
		WebCamTexture::GetDeviceNames(devs, true);

		ScriptingClassPtr klass = GetScriptingManager().GetCommonClasses().webCamDevice;
		ScriptingArrayPtr array = CreateScriptingArray<MonoWebCamDevice>(klass, devs.size());

		for (MonoWebCamDevices::size_type i = 0; i < devs.size(); ++i)
		{
			#if UNITY_WINRT
			ScriptingObjectPtr dev = CreateScriptingObjectFromNativeStruct(klass, devs[i]);
			Scripting::SetScriptingArrayElement<ScriptingObjectPtr>(array, i, dev);
			#else
			Scripting::SetScriptingArrayElement<MonoWebCamDevice>(array, i, devs[i]);
			#endif
		}

		return array;
	}

	// Returns pixel color at coordinates (x, y).
	CUSTOM Color GetPixel (int x, int y) {
		return self->GetPixel (x, y);
	}

	// Get a block of pixel colors.
	CSRAW public Color[] GetPixels()
	{
		return GetPixels( 0, 0, width, height );
	}

	// Get a block of pixel colors.
	CUSTOM Color[] GetPixels(int x, int y, int blockWidth, int blockHeight)
	{
		int res = blockWidth * blockHeight;
		if (blockWidth != 0 && blockHeight != res / blockWidth) {
			return SCRIPTING_NULL;
		}
		ScriptingArrayPtr colors = CreateScriptingArray<ColorRGBAf>(GetScriptingManager().GetCommonClasses().color, res );
		self->GetPixels( x, y, blockWidth, blockHeight, &Scripting::GetScriptingArrayElement<ColorRGBAf>(colors, 0));
		return colors;
	}

	// Returns the pixels data in raw format

	CUSTOM public Color32[] GetPixels32(Color32[] colors = null)
	{
		int w = self->GetDataWidth();
		int h = self->GetDataHeight();
		if (colors != SCRIPTING_NULL)
		{
			int size = GetScriptingArraySize(colors);
			if (size != w * h)
			{
				ErrorStringMsg ("Input color array length needs to match width * height, but %d != %d * %d", size, w, h);
				return SCRIPTING_NULL;
			}
		}
		else
			colors = CreateScriptingArray<ColorRGBA32>(GetScriptingManager().GetCommonClasses().color32, w * h);
		self->GetPixels(kTexFormatRGBA32, &Scripting::GetScriptingArrayElement<ColorRGBA32>(colors, 0), GetScriptingArraySize(colors) * 4);
		return colors;
	}

	// Returns an clockwise angle, which can be used to rotate a polygon so camera contents are shown in correct orientation.
	CUSTOM_PROP int videoRotationAngle { return self->GetVideoRotationAngle(); }

	CUSTOM_PROP bool videoVerticallyMirrored
	{
		return self->IsVideoVerticallyMirrored();
	}

	// Did the video buffer update this frame?
	AUTO_PROP bool didUpdateThisFrame DidUpdateThisFrame

END

CSRAW
}