2017-07-28 00:32:08 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* arkit_interface.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2019-08-28 07:19:52 +00:00
|
|
|
/* https://godotengine.org */
|
2017-07-28 00:32:08 +00:00
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-07-28 00:32:08 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef ARKIT_INTERFACE_H
|
|
|
|
#define ARKIT_INTERFACE_H
|
|
|
|
|
|
|
|
#include "servers/camera/camera_feed.h"
|
2020-04-08 14:47:36 +00:00
|
|
|
#include "servers/xr/xr_interface.h"
|
|
|
|
#include "servers/xr/xr_positional_tracker.h"
|
2017-07-28 00:32:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
@author Bastiaan Olij <mux213@gmail.com>
|
|
|
|
|
|
|
|
ARKit interface between iPhone and Godot
|
|
|
|
*/
|
|
|
|
|
|
|
|
// forward declaration for some needed objects
|
|
|
|
class ARKitShader;
|
|
|
|
|
2020-10-01 19:18:39 +00:00
|
|
|
#ifdef __OBJC__
|
|
|
|
|
|
|
|
typedef ARAnchor GodotARAnchor;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
typedef void GodotARAnchor;
|
|
|
|
#endif
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
class ARKitInterface : public XRInterface {
|
|
|
|
GDCLASS(ARKitInterface, XRInterface);
|
2017-07-28 00:32:08 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool initialized;
|
|
|
|
bool session_was_started;
|
|
|
|
bool plane_detection_is_enabled;
|
|
|
|
bool light_estimation_is_enabled;
|
|
|
|
real_t ambient_intensity;
|
|
|
|
real_t ambient_color_temperature;
|
|
|
|
|
|
|
|
Transform transform;
|
|
|
|
CameraMatrix projection;
|
|
|
|
float eye_height, z_near, z_far;
|
|
|
|
|
|
|
|
Ref<CameraFeed> feed;
|
2020-07-15 16:03:01 +00:00
|
|
|
size_t image_width[2];
|
|
|
|
size_t image_height[2];
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector<uint8_t> img_data[2];
|
2017-07-28 00:32:08 +00:00
|
|
|
|
|
|
|
struct anchor_map {
|
2020-04-08 14:47:36 +00:00
|
|
|
XRPositionalTracker *tracker;
|
2017-07-28 00:32:08 +00:00
|
|
|
unsigned char uuid[16];
|
|
|
|
};
|
|
|
|
|
|
|
|
///@TODO should use memory map object from Godot?
|
|
|
|
unsigned int num_anchors;
|
|
|
|
unsigned int max_anchors;
|
|
|
|
anchor_map *anchors;
|
2020-04-08 14:47:36 +00:00
|
|
|
XRPositionalTracker *get_anchor_for_uuid(const unsigned char *p_uuid);
|
2017-07-28 00:32:08 +00:00
|
|
|
void remove_anchor_for_uuid(const unsigned char *p_uuid);
|
|
|
|
void remove_all_anchors();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void start_session();
|
|
|
|
void stop_session();
|
|
|
|
|
2020-07-15 16:03:01 +00:00
|
|
|
bool get_anchor_detection_is_enabled() const override;
|
|
|
|
void set_anchor_detection_is_enabled(bool p_enable) override;
|
|
|
|
virtual int get_camera_feed_id() override;
|
2017-07-28 00:32:08 +00:00
|
|
|
|
|
|
|
bool get_light_estimation_is_enabled() const;
|
|
|
|
void set_light_estimation_is_enabled(bool p_enable);
|
|
|
|
|
|
|
|
real_t get_ambient_intensity() const;
|
|
|
|
real_t get_ambient_color_temperature() const;
|
|
|
|
|
|
|
|
/* while Godot has its own raycast logic this takes ARKits camera into account and hits on any ARAnchor */
|
|
|
|
Array raycast(Vector2 p_screen_coord);
|
|
|
|
|
2020-07-15 16:03:01 +00:00
|
|
|
virtual void notification(int p_what) override;
|
2017-07-28 00:32:08 +00:00
|
|
|
|
2020-07-15 16:03:01 +00:00
|
|
|
virtual StringName get_name() const override;
|
|
|
|
virtual int get_capabilities() const override;
|
2017-07-28 00:32:08 +00:00
|
|
|
|
2020-07-15 16:03:01 +00:00
|
|
|
virtual bool is_initialized() const override;
|
|
|
|
virtual bool initialize() override;
|
|
|
|
virtual void uninitialize() override;
|
2017-07-28 00:32:08 +00:00
|
|
|
|
2020-07-15 16:03:01 +00:00
|
|
|
virtual Size2 get_render_targetsize() override;
|
|
|
|
virtual bool is_stereo() override;
|
|
|
|
virtual Transform get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform) override;
|
|
|
|
virtual CameraMatrix get_projection_for_eye(XRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) override;
|
|
|
|
virtual void commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) override;
|
2017-07-28 00:32:08 +00:00
|
|
|
|
2020-07-15 16:03:01 +00:00
|
|
|
virtual void process() override;
|
2017-07-28 00:32:08 +00:00
|
|
|
|
|
|
|
// called by delegate (void * because C++ and Obj-C don't always mix, should really change all platform/iphone/*.cpp files to .mm)
|
2020-10-01 19:18:39 +00:00
|
|
|
void _add_or_update_anchor(GodotARAnchor *p_anchor);
|
|
|
|
void _remove_anchor(GodotARAnchor *p_anchor);
|
2017-07-28 00:32:08 +00:00
|
|
|
|
|
|
|
ARKitInterface();
|
|
|
|
~ARKitInterface();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !ARKIT_INTERFACE_H */
|