Skip to content

Commit 57571ab

Browse files
committed
initial 4.0
0 parents  commit 57571ab

Some content is hidden

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

41 files changed

+3689
-0
lines changed

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Xcode
2+
#
3+
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4+
5+
## User settings
6+
xcuserdata/
7+
8+
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
9+
*.xcscmblueprint
10+
*.xccheckout
11+
12+
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
13+
build/
14+
DerivedData/
15+
*.moved-aside
16+
*.pbxuser
17+
!default.pbxuser
18+
*.mode1v3
19+
!default.mode1v3
20+
*.mode2v3
21+
!default.mode2v3
22+
*.perspectivev3
23+
!default.perspectivev3
24+
25+
## Gcc Patch
26+
/*.gcno
27+
28+
*.d
29+
*.o
30+
*.dblite

SConstruct

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
import subprocess
5+
6+
if sys.version_info < (3,):
7+
def decode_utf8(x):
8+
return x
9+
else:
10+
import codecs
11+
def decode_utf8(x):
12+
return codecs.utf_8_decode(x)[0]
13+
14+
# Most of the settings are taken from https://github.com/BastiaanOlij/gdnative_cpp_example
15+
16+
opts = Variables([], ARGUMENTS)
17+
18+
# Gets the standard flags CC, CCX, etc.
19+
env = DefaultEnvironment()
20+
21+
# Define our options
22+
opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r', 'release']))
23+
opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'ios']))
24+
opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['','ios']))
25+
opts.Add(EnumVariable('arch', "Compilation platform", '', ['', 'arm64', 'armv7', 'x86_64']))
26+
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
27+
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bin/'))
28+
opts.Add(PathVariable('target_name', 'The library name.', 'gdexample', PathVariable.PathAccept))
29+
opts.Add(EnumVariable('mode', 'Library build mode', 'static', ['static', 'dynamic']))
30+
31+
# Local dependency paths, adapt them to your setup
32+
godot_path = "godot/"
33+
godot_library = "ios.fat.a"
34+
35+
# Updates the environment with the option variables.
36+
opts.Update(env)
37+
38+
# Process some arguments
39+
if env['use_llvm']:
40+
env['CC'] = 'clang'
41+
env['CXX'] = 'clang++'
42+
43+
if env['p'] != '':
44+
env['platform'] = env['p']
45+
46+
if env['platform'] == '':
47+
print("No valid target platform selected.")
48+
quit();
49+
50+
# For the reference:
51+
# - CCFLAGS are compilation flags shared between C and C++
52+
# - CFLAGS are for C-specific compilation flags
53+
# - CXXFLAGS are for C++-specific compilation flags
54+
# - CPPFLAGS are for pre-processor flags
55+
# - CPPDEFINES are for pre-processor defines
56+
# - LINKFLAGS are for linking flags
57+
58+
# Check our platform specifics
59+
if env['platform'] == "ios":
60+
env.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
61+
62+
if env['arch'] == 'x86_64':
63+
sdk_name = 'iphonesimulator'
64+
env.Append(CCFLAGS=['-mios-simulator-version-min=10.0'])
65+
else:
66+
sdk_name = 'iphoneos'
67+
env.Append(CCFLAGS=['-miphoneos-version-min=10.0'])
68+
69+
try:
70+
sdk_path = decode_utf8(subprocess.check_output(['xcrun', '--sdk', sdk_name, '--show-sdk-path']).strip())
71+
except (subprocess.CalledProcessError, OSError):
72+
raise ValueError("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name))
73+
74+
env['target_path'] += 'ios/'
75+
env.Append(CCFLAGS=['-arch', env['arch'], "-isysroot", "$IPHONESDK", "-stdlib=libc++", '-isysroot', sdk_path])
76+
env.Append(CXXFLAGS=['-std=c++17'])
77+
env.Append(CCFLAGS=['-DPTRCALL_ENABLED'])
78+
79+
if env['target'] in ('debug', 'd'):
80+
env.Append(CCFLAGS=['-g', '-O2', '-DDEBUG', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ALLOC', '-DDISABLE_FORCED_INLINE', '-DTYPED_METHOD_BIND'])
81+
else:
82+
env.Append(CCFLAGS=['-g', '-O3'])
83+
84+
85+
env.Append(
86+
CCFLAGS="-fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies -miphoneos-version-min=10.0".split()
87+
)
88+
env.Append(LINKFLAGS=[])
89+
90+
env.Append(
91+
LINKFLAGS=[
92+
"-arch",
93+
env['arch'],
94+
"-miphoneos-version-min=10.0",
95+
'-isysroot', sdk_path,
96+
'-F' + sdk_path
97+
]
98+
)
99+
100+
# make sure our binding library is properly includes
101+
env.Append(CPPPATH=[
102+
'.',
103+
godot_path,
104+
godot_path + 'main/',
105+
godot_path + 'core/',
106+
godot_path + 'core/os/',
107+
godot_path + 'core/platform/',
108+
godot_path + 'platform/iphone/',
109+
godot_path + 'modules/',
110+
godot_path + 'scene/',
111+
godot_path + 'servers/',
112+
godot_path + 'drivers/',
113+
godot_path + 'thirdparty/',
114+
])
115+
env.Append(LIBPATH=[godot_path + 'bin/'])
116+
env.Append(LIBS=[godot_library])
117+
118+
# tweak this if you want to use different folders, or more folders, to store your source code in.
119+
sources = Glob('godot_plugin/*.cpp')
120+
sources.append(Glob("godot_plugin/*.mm"))
121+
sources.append(Glob("godot_plugin/*.m"))
122+
123+
library = env.StaticLibrary(target=env['target_path'] + env['target_name'] , source=sources)
124+
125+
Default(library)
126+
127+
# Generates help for the -h scons option.
128+
Help(opts.GenerateHelpText(env))

arkit/SCsub

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
3+
Import("env")
4+
Import("env_modules")
5+
6+
env_arkit = env_modules.Clone()
7+
8+
# (iOS) Enable module support
9+
env_arkit.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
10+
11+
# (iOS) Build as separate static library
12+
modules_sources = []
13+
env_arkit.add_source_files(modules_sources, "*.cpp")
14+
env_arkit.add_source_files(modules_sources, "*.mm")
15+
mod_lib = env_modules.add_library("#bin/libgodot_arkit_module" + env["LIBSUFFIX"], modules_sources)

arkit/arkit.gdip

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[config]
2+
name="ARKit"
3+
binary="arkit_lib.a"
4+
5+
initialization="register_arkit_types"
6+
deinitialization="unregister_arkit_types"
7+
8+
[dependencies]
9+
linked=[]
10+
embedded=[]
11+
system=["AVFoundation.framework", "ARKit.framework"]
12+
13+
capabilities=["arkit"]
14+
15+
files=[]
16+
17+
[plist]
18+
NSCameraUsageDescription="Device camera is used for some functionality"

arkit/arkit_interface.h

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*************************************************************************/
2+
/* arkit_interface.h */
3+
/*************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/*************************************************************************/
8+
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
9+
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/*************************************************************************/
30+
31+
#ifndef ARKIT_INTERFACE_H
32+
#define ARKIT_INTERFACE_H
33+
34+
#include "servers/camera/camera_feed.h"
35+
#include "servers/xr/xr_interface.h"
36+
#include "servers/xr/xr_positional_tracker.h"
37+
38+
/**
39+
@author Bastiaan Olij <[email protected]>
40+
41+
ARKit interface between iPhone and Godot
42+
*/
43+
44+
// forward declaration for some needed objects
45+
class ARKitShader;
46+
47+
#ifdef __OBJC__
48+
49+
typedef ARAnchor GodotARAnchor;
50+
51+
#else
52+
53+
typedef void GodotARAnchor;
54+
#endif
55+
56+
class ARKitInterface : public XRInterface {
57+
GDCLASS(ARKitInterface, XRInterface);
58+
59+
private:
60+
bool initialized;
61+
bool session_was_started;
62+
bool plane_detection_is_enabled;
63+
bool light_estimation_is_enabled;
64+
real_t ambient_intensity;
65+
real_t ambient_color_temperature;
66+
67+
Transform transform;
68+
CameraMatrix projection;
69+
float eye_height, z_near, z_far;
70+
71+
Ref<CameraFeed> feed;
72+
size_t image_width[2];
73+
size_t image_height[2];
74+
Vector<uint8_t> img_data[2];
75+
76+
struct anchor_map {
77+
XRPositionalTracker *tracker;
78+
unsigned char uuid[16];
79+
};
80+
81+
///@TODO should use memory map object from Godot?
82+
unsigned int num_anchors;
83+
unsigned int max_anchors;
84+
anchor_map *anchors;
85+
XRPositionalTracker *get_anchor_for_uuid(const unsigned char *p_uuid);
86+
void remove_anchor_for_uuid(const unsigned char *p_uuid);
87+
void remove_all_anchors();
88+
89+
protected:
90+
static void _bind_methods();
91+
92+
public:
93+
void start_session();
94+
void stop_session();
95+
96+
bool get_anchor_detection_is_enabled() const override;
97+
void set_anchor_detection_is_enabled(bool p_enable) override;
98+
virtual int get_camera_feed_id() override;
99+
100+
bool get_light_estimation_is_enabled() const;
101+
void set_light_estimation_is_enabled(bool p_enable);
102+
103+
real_t get_ambient_intensity() const;
104+
real_t get_ambient_color_temperature() const;
105+
106+
/* while Godot has its own raycast logic this takes ARKits camera into account and hits on any ARAnchor */
107+
Array raycast(Vector2 p_screen_coord);
108+
109+
virtual void notification(int p_what) override;
110+
111+
virtual StringName get_name() const override;
112+
virtual int get_capabilities() const override;
113+
114+
virtual bool is_initialized() const override;
115+
virtual bool initialize() override;
116+
virtual void uninitialize() override;
117+
118+
virtual Size2 get_render_targetsize() override;
119+
virtual bool is_stereo() override;
120+
virtual Transform get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform) override;
121+
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;
122+
virtual void commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) override;
123+
124+
virtual void process() override;
125+
126+
// called by delegate (void * because C++ and Obj-C don't always mix, should really change all platform/iphone/*.cpp files to .mm)
127+
void _add_or_update_anchor(GodotARAnchor *p_anchor);
128+
void _remove_anchor(GodotARAnchor *p_anchor);
129+
130+
ARKitInterface();
131+
~ARKitInterface();
132+
};
133+
134+
#endif /* !ARKIT_INTERFACE_H */

0 commit comments

Comments
 (0)