Adding a new Camera Server implementation to Godot.

This is a new singleton where camera sources such as webcams or cameras on a mobile phone can register themselves with the Server.
Other parts of Godot can interact with this to obtain images from the camera as textures.
This work includes additions to the Visual Server to use this functionality to present the camera image in the background. This is specifically targetted at AR applications.
This commit is contained in:
BastiaanOlij
2017-08-21 00:17:24 +10:00
committed by Bastiaan Olij
parent 0a3c21d999
commit 02ea99129e
67 changed files with 2384 additions and 5 deletions

View File

@@ -36,6 +36,7 @@
#include "core/os/os.h"
#include "mesh.h"
#include "scene/resources/bit_map.h"
#include "servers/camera/camera_feed.h"
Size2 Texture::get_size() const {
@@ -2498,3 +2499,107 @@ String ResourceFormatLoaderTextureLayered::get_resource_type(const String &p_pat
return "TextureArray";
return "";
}
void CameraTexture::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_camera_feed_id", "feed_id"), &CameraTexture::set_camera_feed_id);
ClassDB::bind_method(D_METHOD("get_camera_feed_id"), &CameraTexture::get_camera_feed_id);
ClassDB::bind_method(D_METHOD("set_which_feed", "which_feed"), &CameraTexture::set_which_feed);
ClassDB::bind_method(D_METHOD("get_which_feed"), &CameraTexture::get_which_feed);
ClassDB::bind_method(D_METHOD("set_camera_active", "active"), &CameraTexture::set_camera_active);
ClassDB::bind_method(D_METHOD("get_camera_active"), &CameraTexture::get_camera_active);
ADD_PROPERTY(PropertyInfo(Variant::INT, "camera_feed_id"), "set_camera_feed_id", "get_camera_feed_id");
ADD_PROPERTY(PropertyInfo(Variant::INT, "which_feed"), "set_which_feed", "get_which_feed");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "camera_is_active"), "set_camera_active", "get_camera_active");
}
int CameraTexture::get_width() const {
Ref<CameraFeed> feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id);
if (feed.is_valid()) {
return feed->get_base_width();
} else {
return 0;
}
}
int CameraTexture::get_height() const {
Ref<CameraFeed> feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id);
if (feed.is_valid()) {
return feed->get_base_height();
} else {
return 0;
}
}
bool CameraTexture::has_alpha() const {
return false;
}
RID CameraTexture::get_rid() const {
Ref<CameraFeed> feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id);
if (feed.is_valid()) {
return feed->get_texture(which_feed);
} else {
return RID();
}
}
void CameraTexture::set_flags(uint32_t p_flags) {
// not supported
}
uint32_t CameraTexture::get_flags() const {
// not supported
return 0;
}
Ref<Image> CameraTexture::get_data() const {
// not (yet) supported
return Ref<Image>();
}
void CameraTexture::set_camera_feed_id(int p_new_id) {
camera_feed_id = p_new_id;
_change_notify();
}
int CameraTexture::get_camera_feed_id() const {
return camera_feed_id;
}
void CameraTexture::set_which_feed(CameraServer::FeedImage p_which) {
which_feed = p_which;
_change_notify();
}
CameraServer::FeedImage CameraTexture::get_which_feed() const {
return which_feed;
}
void CameraTexture::set_camera_active(bool p_active) {
Ref<CameraFeed> feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id);
if (feed.is_valid()) {
feed->set_active(p_active);
_change_notify();
}
}
bool CameraTexture::get_camera_active() const {
Ref<CameraFeed> feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id);
if (feed.is_valid()) {
return feed->is_active();
} else {
return false;
}
}
CameraTexture::CameraTexture() {
camera_feed_id = 0;
which_feed = CameraServer::FEED_RGBA_IMAGE;
}
CameraTexture::~CameraTexture() {
// nothing to do here yet
}