@airisu-dev/react-native-live2d-skia 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/Live2dSkia.podspec +159 -0
- package/README.md +258 -2
- package/android/CMakeLists.txt +113 -0
- package/android/build.gradle +223 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +9 -0
- package/android/src/main/java/com/live2dskia/Live2dSkiaPackage.kt +20 -0
- package/app.plugin.js +2 -0
- package/cli/build/index.js +157 -0
- package/cpp/cubism/CubismCompat.hpp +26 -0
- package/cpp/cubism/CubismHelpers.hpp +27 -0
- package/cpp/cubism/CubismRendererStub.cpp +14 -0
- package/cpp/cubism/CubismSetup.cpp +54 -0
- package/cpp/cubism/CubismSetup.hpp +9 -0
- package/cpp/cubism/HeldParameterUpdater.hpp +25 -0
- package/cpp/cubism/Live2DUserModel.cpp +125 -0
- package/cpp/cubism/Live2DUserModel.hpp +57 -0
- package/cpp/cubism/Live2DUserModelAnimation.cpp +107 -0
- package/cpp/drawing/JsiUnwrap.hpp +25 -0
- package/cpp/drawing/MeshCache.cpp +75 -0
- package/cpp/drawing/MeshCache.hpp +45 -0
- package/cpp/drawing/SkiaDrawer.cpp +138 -0
- package/cpp/drawing/SkiaDrawer.hpp +42 -0
- package/cpp/hybrid/HybridLive2DModel.cpp +174 -0
- package/cpp/hybrid/HybridLive2DModel.hpp +64 -0
- package/cpp/hybrid/HybridLive2dSkia.cpp +10 -0
- package/cpp/hybrid/HybridLive2dSkia.hpp +11 -0
- package/ios/Bridge.h +8 -0
- package/nitro.json +20 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/Live2dSkia+autolinking.cmake +82 -0
- package/nitrogen/generated/android/Live2dSkia+autolinking.gradle +27 -0
- package/nitrogen/generated/android/Live2dSkiaOnLoad.cpp +49 -0
- package/nitrogen/generated/android/Live2dSkiaOnLoad.hpp +34 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/live2dskia/Live2dSkiaOnLoad.kt +35 -0
- package/nitrogen/generated/ios/Live2dSkia+autolinking.rb +62 -0
- package/nitrogen/generated/ios/Live2dSkia-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/Live2dSkia-Swift-Cxx-Bridge.hpp +27 -0
- package/nitrogen/generated/ios/Live2dSkia-Swift-Cxx-Umbrella.hpp +38 -0
- package/nitrogen/generated/ios/Live2dSkiaAutolinking.mm +35 -0
- package/nitrogen/generated/ios/Live2dSkiaAutolinking.swift +16 -0
- package/nitrogen/generated/shared/c++/DrawableData.hpp +116 -0
- package/nitrogen/generated/shared/c++/HybridLive2DModelSpec.cpp +39 -0
- package/nitrogen/generated/shared/c++/HybridLive2DModelSpec.hpp +86 -0
- package/nitrogen/generated/shared/c++/HybridLive2dSkiaSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridLive2dSkiaSpec.hpp +66 -0
- package/nitrogen/generated/shared/c++/MotionPriority.hpp +80 -0
- package/package.json +149 -4
- package/plugin/build/index.d.ts +14 -0
- package/plugin/build/index.js +81 -0
- package/src/components/Live2D.tsx +131 -0
- package/src/components/index.ts +2 -0
- package/src/hooks/index.ts +8 -0
- package/src/hooks/useLive2DGesture.ts +140 -0
- package/src/hooks/useLive2DModel.ts +47 -0
- package/src/index.ts +5 -0
- package/src/loader/cubismJson.ts +23 -0
- package/src/loader/index.ts +9 -0
- package/src/loader/loadModel.ts +195 -0
- package/src/loader/modelContext.ts +80 -0
- package/src/loader/modelUrl.ts +112 -0
- package/src/native.ts +4 -0
- package/src/rendering/decodeImage.ts +12 -0
- package/src/rendering/drawer.ts +256 -0
- package/src/rendering/skia.ts +26 -0
- package/src/rendering/skiaTypes.ts +99 -0
- package/src/rendering/ticker/addToTicker.ts +52 -0
- package/src/rendering/ticker/constants.ts +11 -0
- package/src/rendering/ticker/frames.ts +35 -0
- package/src/rendering/ticker/index.ts +5 -0
- package/src/rendering/ticker/loop.ts +115 -0
- package/src/rendering/ticker/state.ts +65 -0
- package/src/rendering/ticker/stats.ts +36 -0
- package/src/rendering/ticker/types.ts +57 -0
- package/src/specs/react-native-live2d-skia.nitro.ts +88 -0
- package/src/utils/clock.ts +10 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#include "HybridLive2DModel.hpp"
|
|
2
|
+
#include <algorithm>
|
|
3
|
+
#include <numeric>
|
|
4
|
+
#include "CubismSetup.hpp"
|
|
5
|
+
#include "CubismCompat.hpp"
|
|
6
|
+
|
|
7
|
+
namespace margelo::nitro::live2dskia {
|
|
8
|
+
|
|
9
|
+
using namespace Live2D::Cubism::Core;
|
|
10
|
+
|
|
11
|
+
namespace {
|
|
12
|
+
|
|
13
|
+
template <typename T>
|
|
14
|
+
std::shared_ptr<ArrayBuffer> copyToArrayBuffer(const T* data, size_t count) {
|
|
15
|
+
return ArrayBuffer::copy(reinterpret_cast<const uint8_t*>(data), count * sizeof(T));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Live2DUserModel::Priority toPriority(std::optional<MotionPriority> priority) {
|
|
19
|
+
switch (priority.value_or(MotionPriority::NORMAL)) {
|
|
20
|
+
case MotionPriority::IDLE: return Live2DUserModel::PriorityIdle;
|
|
21
|
+
case MotionPriority::FORCE: return Live2DUserModel::PriorityForce;
|
|
22
|
+
default: return Live2DUserModel::PriorityNormal;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
} // namespace
|
|
27
|
+
|
|
28
|
+
HybridLive2DModel::HybridLive2DModel(const uint8_t* mocData, size_t mocSize, const std::string& settingsJson)
|
|
29
|
+
: HybridObject(TAG), HybridLive2DModelSpec() {
|
|
30
|
+
// The Framework must be started before any of its objects are created.
|
|
31
|
+
ensureCubismFramework();
|
|
32
|
+
_userModel = std::make_unique<Live2DUserModel>(mocData, mocSize, settingsJson);
|
|
33
|
+
|
|
34
|
+
csmVector2 size{}, origin{};
|
|
35
|
+
csmReadCanvasInfo(_userModel->model()->GetModel(), &size, &origin, &_pixelsPerUnit);
|
|
36
|
+
_canvasWidth = size.X;
|
|
37
|
+
_canvasHeight = size.Y;
|
|
38
|
+
_originX = origin.X;
|
|
39
|
+
_originY = origin.Y;
|
|
40
|
+
|
|
41
|
+
// Compute vertex positions, opacities and render orders for the default parameters.
|
|
42
|
+
_userModel->update(0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
double HybridLive2DModel::getDrawableCount() {
|
|
46
|
+
std::lock_guard lock(_mutex);
|
|
47
|
+
return csmGetDrawableCount(_userModel->model()->GetModel());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
std::vector<DrawableData> HybridLive2DModel::getDrawables() {
|
|
51
|
+
std::lock_guard lock(_mutex);
|
|
52
|
+
const csmModel* model = _userModel->model()->GetModel();
|
|
53
|
+
const int count = csmGetDrawableCount(model);
|
|
54
|
+
const int* renderOrders = cubism::renderOrders(model);
|
|
55
|
+
const csmFlags* dynamicFlags = csmGetDrawableDynamicFlags(model);
|
|
56
|
+
const csmFlags* constantFlags = csmGetDrawableConstantFlags(model);
|
|
57
|
+
const int* textureIndices = csmGetDrawableTextureIndices(model);
|
|
58
|
+
const float* opacities = csmGetDrawableOpacities(model);
|
|
59
|
+
const int* vertexCounts = csmGetDrawableVertexCounts(model);
|
|
60
|
+
const csmVector2** positions = csmGetDrawableVertexPositions(model);
|
|
61
|
+
const csmVector2** uvs = csmGetDrawableVertexUvs(model);
|
|
62
|
+
const int* indexCounts = csmGetDrawableIndexCounts(model);
|
|
63
|
+
const unsigned short** indices = csmGetDrawableIndices(model);
|
|
64
|
+
const int* maskCounts = csmGetDrawableMaskCounts(model);
|
|
65
|
+
const int** masks = csmGetDrawableMasks(model);
|
|
66
|
+
|
|
67
|
+
std::vector<int> order(count);
|
|
68
|
+
std::iota(order.begin(), order.end(), 0);
|
|
69
|
+
std::sort(order.begin(), order.end(),
|
|
70
|
+
[&](int a, int b) { return renderOrders[a] < renderOrders[b]; });
|
|
71
|
+
|
|
72
|
+
std::vector<DrawableData> result;
|
|
73
|
+
result.reserve(count);
|
|
74
|
+
for (int i : order) {
|
|
75
|
+
result.emplace_back(i,
|
|
76
|
+
(dynamicFlags[i] & csmIsVisible) != 0,
|
|
77
|
+
textureIndices[i],
|
|
78
|
+
opacities[i],
|
|
79
|
+
constantFlags[i],
|
|
80
|
+
std::vector<double>(masks[i], masks[i] + maskCounts[i]),
|
|
81
|
+
copyToArrayBuffer(positions[i], vertexCounts[i]),
|
|
82
|
+
copyToArrayBuffer(uvs[i], vertexCounts[i]),
|
|
83
|
+
copyToArrayBuffer(indices[i], indexCounts[i]));
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
void HybridLive2DModel::loadPhysics(const std::string& json) {
|
|
89
|
+
std::lock_guard lock(_mutex);
|
|
90
|
+
_userModel->loadPhysics(json);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
void HybridLive2DModel::loadPose(const std::string& json) {
|
|
94
|
+
std::lock_guard lock(_mutex);
|
|
95
|
+
_userModel->loadPose(json);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
void HybridLive2DModel::loadMotion(const std::string& group, double index, const std::string& json) {
|
|
99
|
+
std::lock_guard lock(_mutex);
|
|
100
|
+
_userModel->loadMotion(group, static_cast<int>(index), json);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
bool HybridLive2DModel::startMotion(const std::string& group, std::optional<double> index, std::optional<MotionPriority> priority) {
|
|
104
|
+
std::lock_guard lock(_mutex);
|
|
105
|
+
if (!index) return _userModel->startRandomMotion(group, toPriority(priority));
|
|
106
|
+
return _userModel->startMotion(group, static_cast<int>(*index), toPriority(priority));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
void HybridLive2DModel::loadExpression(const std::string& name, const std::string& json) {
|
|
110
|
+
std::lock_guard lock(_mutex);
|
|
111
|
+
_userModel->loadExpression(name, json);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
bool HybridLive2DModel::setExpression(const std::optional<std::string>& name) {
|
|
115
|
+
std::lock_guard lock(_mutex);
|
|
116
|
+
return name ? _userModel->setExpression(*name) : _userModel->setRandomExpression();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
void HybridLive2DModel::clearExpression() {
|
|
120
|
+
std::lock_guard lock(_mutex);
|
|
121
|
+
_userModel->clearExpression();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
void HybridLive2DModel::setParameter(const std::string& id, double value) {
|
|
125
|
+
std::lock_guard lock(_mutex);
|
|
126
|
+
_userModel->setParameter(id, static_cast<float>(value));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
void HybridLive2DModel::clearParameter(const std::string& id) {
|
|
130
|
+
std::lock_guard lock(_mutex);
|
|
131
|
+
_userModel->clearParameter(id);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
void HybridLive2DModel::focus(double x, double y) {
|
|
135
|
+
std::lock_guard lock(_mutex);
|
|
136
|
+
_userModel->focus(static_cast<float>(std::clamp(x, -1.0, 1.0)), static_cast<float>(std::clamp(y, -1.0, 1.0)));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
std::vector<std::string> HybridLive2DModel::hitTest(double x, double y) {
|
|
140
|
+
std::lock_guard lock(_mutex);
|
|
141
|
+
return _userModel->hitTest(static_cast<float>(x), static_cast<float>(y));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
void HybridLive2DModel::update(double deltaSeconds) {
|
|
145
|
+
std::lock_guard lock(_mutex);
|
|
146
|
+
_userModel->update(static_cast<float>(deltaSeconds));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
void HybridLive2DModel::loadHybridMethods() {
|
|
150
|
+
HybridLive2DModelSpec::loadHybridMethods();
|
|
151
|
+
#if LIVE2D_SKIA
|
|
152
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
153
|
+
prototype.registerRawHybridMethod("setTextures", 2, &HybridLive2DModel::setTexturesRaw);
|
|
154
|
+
prototype.registerRawHybridMethod("drawTo", 2, &HybridLive2DModel::drawToRaw);
|
|
155
|
+
});
|
|
156
|
+
#endif
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
#if LIVE2D_SKIA
|
|
160
|
+
jsi::Value HybridLive2DModel::setTexturesRaw(jsi::Runtime& runtime, const jsi::Value&, const jsi::Value* args, size_t) {
|
|
161
|
+
std::lock_guard lock(_mutex);
|
|
162
|
+
_drawer.setTextures(runtime, args[0], args[1]);
|
|
163
|
+
return jsi::Value::undefined();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
jsi::Value HybridLive2DModel::drawToRaw(jsi::Runtime& runtime, const jsi::Value&, const jsi::Value* args, size_t) {
|
|
167
|
+
std::lock_guard lock(_mutex);
|
|
168
|
+
const CanvasInfo info{_originX, _originY, _pixelsPerUnit};
|
|
169
|
+
return _drawer.draw(runtime, args[0], args[1].isBool() && args[1].getBool(),
|
|
170
|
+
_userModel->model()->GetModel(), info);
|
|
171
|
+
}
|
|
172
|
+
#endif
|
|
173
|
+
|
|
174
|
+
} // namespace margelo::nitro::live2dskia
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <memory>
|
|
3
|
+
#include <mutex>
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <vector>
|
|
6
|
+
#include "HybridLive2DModelSpec.hpp"
|
|
7
|
+
#include "Live2DUserModel.hpp"
|
|
8
|
+
#include "SkiaDrawer.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::live2dskia {
|
|
11
|
+
|
|
12
|
+
class HybridLive2DModel : public HybridLive2DModelSpec {
|
|
13
|
+
public:
|
|
14
|
+
// Takes a .moc3 file's bytes and its model3.json. Throws std::runtime_error if they can't be loaded.
|
|
15
|
+
HybridLive2DModel(const uint8_t* mocData, size_t mocSize, const std::string& settingsJson);
|
|
16
|
+
|
|
17
|
+
double getCanvasWidth() override { return _canvasWidth; }
|
|
18
|
+
double getCanvasHeight() override { return _canvasHeight; }
|
|
19
|
+
double getOriginX() override { return _originX; }
|
|
20
|
+
double getOriginY() override { return _originY; }
|
|
21
|
+
double getPixelsPerUnit() override { return _pixelsPerUnit; }
|
|
22
|
+
double getDrawableCount() override;
|
|
23
|
+
|
|
24
|
+
std::vector<DrawableData> getDrawables() override;
|
|
25
|
+
void loadPhysics(const std::string& json) override;
|
|
26
|
+
void loadPose(const std::string& json) override;
|
|
27
|
+
void loadMotion(const std::string& group, double index, const std::string& json) override;
|
|
28
|
+
bool startMotion(const std::string& group, std::optional<double> index, std::optional<MotionPriority> priority) override;
|
|
29
|
+
void loadExpression(const std::string& name, const std::string& json) override;
|
|
30
|
+
bool setExpression(const std::optional<std::string>& name) override;
|
|
31
|
+
void clearExpression() override;
|
|
32
|
+
void setParameter(const std::string& id, double value) override;
|
|
33
|
+
void clearParameter(const std::string& id) override;
|
|
34
|
+
void focus(double x, double y) override;
|
|
35
|
+
std::vector<std::string> hitTest(double x, double y) override;
|
|
36
|
+
void update(double deltaSeconds) override;
|
|
37
|
+
|
|
38
|
+
protected:
|
|
39
|
+
// Adds the raw JSI methods that take react-native-skia objects, when built with Skia.
|
|
40
|
+
void loadHybridMethods() override;
|
|
41
|
+
|
|
42
|
+
#if LIVE2D_SKIA
|
|
43
|
+
private:
|
|
44
|
+
// setTextures(shaders: SkShader[], sizes: number[]): void
|
|
45
|
+
jsi::Value setTexturesRaw(jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count);
|
|
46
|
+
// drawTo(canvas: SkCanvas, wantStats: boolean): DrawStats | undefined
|
|
47
|
+
jsi::Value drawToRaw(jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count);
|
|
48
|
+
#endif
|
|
49
|
+
|
|
50
|
+
private:
|
|
51
|
+
// The model is updated on the animation thread and controlled from the JS thread.
|
|
52
|
+
std::mutex _mutex;
|
|
53
|
+
std::unique_ptr<Live2DUserModel> _userModel;
|
|
54
|
+
#if LIVE2D_SKIA
|
|
55
|
+
SkiaDrawer _drawer;
|
|
56
|
+
#endif
|
|
57
|
+
float _canvasWidth = 0;
|
|
58
|
+
float _canvasHeight = 0;
|
|
59
|
+
float _originX = 0;
|
|
60
|
+
float _originY = 0;
|
|
61
|
+
float _pixelsPerUnit = 0;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
} // namespace margelo::nitro::live2dskia
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#include "HybridLive2dSkia.hpp"
|
|
2
|
+
#include "HybridLive2DModel.hpp"
|
|
3
|
+
|
|
4
|
+
namespace margelo::nitro::live2dskia {
|
|
5
|
+
|
|
6
|
+
std::shared_ptr<HybridLive2DModelSpec> HybridLive2dSkia::loadModel(const std::shared_ptr<ArrayBuffer>& moc, const std::string& settingsJson) {
|
|
7
|
+
return std::make_shared<HybridLive2DModel>(moc->data(), moc->size(), settingsJson);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
} // namespace margelo::nitro::live2dskia
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "HybridLive2dSkiaSpec.hpp"
|
|
3
|
+
|
|
4
|
+
namespace margelo::nitro::live2dskia {
|
|
5
|
+
class HybridLive2dSkia : public HybridLive2dSkiaSpec {
|
|
6
|
+
public:
|
|
7
|
+
HybridLive2dSkia() : HybridObject(TAG), HybridLive2dSkiaSpec() {}
|
|
8
|
+
|
|
9
|
+
std::shared_ptr<HybridLive2DModelSpec> loadModel(const std::shared_ptr<ArrayBuffer>& moc, const std::string& settingsJson) override;
|
|
10
|
+
};
|
|
11
|
+
} // namespace margelo::nitro::live2dskia
|
package/ios/Bridge.h
ADDED
package/nitro.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://nitro.margelo.com/nitro.schema.json",
|
|
3
|
+
"cxxNamespace": ["live2dskia"],
|
|
4
|
+
"ios": {
|
|
5
|
+
"iosModuleName": "Live2dSkia"
|
|
6
|
+
},
|
|
7
|
+
"android": {
|
|
8
|
+
"androidNamespace": ["live2dskia"],
|
|
9
|
+
"androidCxxLibName": "Live2dSkia"
|
|
10
|
+
},
|
|
11
|
+
"autolinking": {
|
|
12
|
+
"Live2dSkia": {
|
|
13
|
+
"all": {
|
|
14
|
+
"language": "c++",
|
|
15
|
+
"implementationClassName": "HybridLive2dSkia"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"ignorePaths": ["**/node_modules"]
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
** linguist-generated=true
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Live2dSkia+autolinking.cmake
|
|
3
|
+
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
# https://github.com/mrousavy/nitro
|
|
5
|
+
# Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
# This is a CMake file that adds all files generated by Nitrogen
|
|
9
|
+
# to the current CMake project.
|
|
10
|
+
#
|
|
11
|
+
# To use it, add this to your CMakeLists.txt:
|
|
12
|
+
# ```cmake
|
|
13
|
+
# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/Live2dSkia+autolinking.cmake)
|
|
14
|
+
# ```
|
|
15
|
+
|
|
16
|
+
# Define a flag to check if we are building properly
|
|
17
|
+
add_definitions(-DBUILDING_LIVE2DSKIA_WITH_GENERATED_CMAKE_PROJECT)
|
|
18
|
+
|
|
19
|
+
# Enable Raw Props parsing in react-native (for Nitro Views)
|
|
20
|
+
add_definitions(-DRN_SERIALIZABLE_STATE)
|
|
21
|
+
|
|
22
|
+
# Add all headers that were generated by Nitrogen
|
|
23
|
+
include_directories(
|
|
24
|
+
"../nitrogen/generated/shared/c++"
|
|
25
|
+
"../nitrogen/generated/android/c++"
|
|
26
|
+
"../nitrogen/generated/android/"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Add all .cpp sources that were generated by Nitrogen
|
|
30
|
+
target_sources(
|
|
31
|
+
# CMake project name (Android C++ library name)
|
|
32
|
+
Live2dSkia PRIVATE
|
|
33
|
+
# Autolinking Setup
|
|
34
|
+
../nitrogen/generated/android/Live2dSkiaOnLoad.cpp
|
|
35
|
+
# Shared Nitrogen C++ sources
|
|
36
|
+
../nitrogen/generated/shared/c++/HybridLive2DModelSpec.cpp
|
|
37
|
+
../nitrogen/generated/shared/c++/HybridLive2dSkiaSpec.cpp
|
|
38
|
+
# Android-specific Nitrogen C++ sources
|
|
39
|
+
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
43
|
+
# Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
|
|
44
|
+
target_compile_definitions(
|
|
45
|
+
Live2dSkia PRIVATE
|
|
46
|
+
-DFOLLY_NO_CONFIG=1
|
|
47
|
+
-DFOLLY_HAVE_CLOCK_GETTIME=1
|
|
48
|
+
-DFOLLY_USE_LIBCPP=1
|
|
49
|
+
-DFOLLY_CFG_NO_COROUTINES=1
|
|
50
|
+
-DFOLLY_MOBILE=1
|
|
51
|
+
-DFOLLY_HAVE_RECVMMSG=1
|
|
52
|
+
-DFOLLY_HAVE_PTHREAD=1
|
|
53
|
+
# Once we target android-23 above, we can comment
|
|
54
|
+
# the following line. NDK uses GNU style stderror_r() after API 23.
|
|
55
|
+
-DFOLLY_HAVE_XSI_STRERROR_R=1
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# Add all libraries required by the generated specs
|
|
59
|
+
find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
|
|
60
|
+
find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
|
|
61
|
+
find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
|
|
62
|
+
|
|
63
|
+
# Link all libraries together
|
|
64
|
+
target_link_libraries(
|
|
65
|
+
Live2dSkia
|
|
66
|
+
fbjni::fbjni # <-- Facebook C++ JNI helpers
|
|
67
|
+
ReactAndroid::jsi # <-- RN: JSI
|
|
68
|
+
react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# Link react-native (different prefab between RN 0.75 and RN 0.76)
|
|
72
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
73
|
+
target_link_libraries(
|
|
74
|
+
Live2dSkia
|
|
75
|
+
ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
|
|
76
|
+
)
|
|
77
|
+
else()
|
|
78
|
+
target_link_libraries(
|
|
79
|
+
Live2dSkia
|
|
80
|
+
ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
|
|
81
|
+
)
|
|
82
|
+
endif()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Live2dSkia+autolinking.gradle
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
/// This is a Gradle file that adds all files generated by Nitrogen
|
|
9
|
+
/// to the current Gradle project.
|
|
10
|
+
///
|
|
11
|
+
/// To use it, add this to your build.gradle:
|
|
12
|
+
/// ```gradle
|
|
13
|
+
/// apply from: '../nitrogen/generated/android/Live2dSkia+autolinking.gradle'
|
|
14
|
+
/// ```
|
|
15
|
+
|
|
16
|
+
logger.warn("[NitroModules] 🔥 Live2dSkia is boosted by nitro!")
|
|
17
|
+
|
|
18
|
+
android {
|
|
19
|
+
sourceSets {
|
|
20
|
+
main {
|
|
21
|
+
java.srcDirs += [
|
|
22
|
+
// Nitrogen files
|
|
23
|
+
"${project.projectDir}/../nitrogen/generated/android/kotlin"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Live2dSkiaOnLoad.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#ifndef BUILDING_LIVE2DSKIA_WITH_GENERATED_CMAKE_PROJECT
|
|
9
|
+
#error Live2dSkiaOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include "Live2dSkiaOnLoad.hpp"
|
|
13
|
+
|
|
14
|
+
#include <jni.h>
|
|
15
|
+
#include <fbjni/fbjni.h>
|
|
16
|
+
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
|
+
|
|
18
|
+
#include "HybridLive2dSkia.hpp"
|
|
19
|
+
|
|
20
|
+
namespace margelo::nitro::live2dskia {
|
|
21
|
+
|
|
22
|
+
int initialize(JavaVM* vm) {
|
|
23
|
+
return facebook::jni::initialize(vm, []() {
|
|
24
|
+
::margelo::nitro::live2dskia::registerAllNatives();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
void registerAllNatives() {
|
|
31
|
+
using namespace margelo::nitro;
|
|
32
|
+
using namespace margelo::nitro::live2dskia;
|
|
33
|
+
|
|
34
|
+
// Register native JNI methods
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// Register Nitro Hybrid Objects
|
|
38
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
39
|
+
"Live2dSkia",
|
|
40
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
41
|
+
static_assert(std::is_default_constructible_v<HybridLive2dSkia>,
|
|
42
|
+
"The HybridObject \"HybridLive2dSkia\" is not default-constructible! "
|
|
43
|
+
"Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
|
|
44
|
+
return std::make_shared<HybridLive2dSkia>();
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
} // namespace margelo::nitro::live2dskia
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Live2dSkiaOnLoad.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include <jni.h>
|
|
9
|
+
#include <functional>
|
|
10
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
11
|
+
|
|
12
|
+
namespace margelo::nitro::live2dskia {
|
|
13
|
+
|
|
14
|
+
[[deprecated("Use registerNatives() instead.")]]
|
|
15
|
+
int initialize(JavaVM* vm);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Register the native (C++) part of Live2dSkia, and autolinks all Hybrid Objects.
|
|
19
|
+
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
|
|
20
|
+
* inside a `facebook::jni::initialize(vm, ...)` call.
|
|
21
|
+
* Example:
|
|
22
|
+
* ```cpp (cpp-adapter.cpp)
|
|
23
|
+
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
24
|
+
* return facebook::jni::initialize(vm, []() {
|
|
25
|
+
* // register all Live2dSkia HybridObjects
|
|
26
|
+
* margelo::nitro::live2dskia::registerNatives();
|
|
27
|
+
* // any other custom registrations go here.
|
|
28
|
+
* });
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
void registerAllNatives();
|
|
33
|
+
|
|
34
|
+
} // namespace margelo::nitro::live2dskia
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Live2dSkiaOnLoad.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.live2dskia
|
|
9
|
+
|
|
10
|
+
import android.util.Log
|
|
11
|
+
|
|
12
|
+
internal class Live2dSkiaOnLoad {
|
|
13
|
+
companion object {
|
|
14
|
+
private const val TAG = "Live2dSkiaOnLoad"
|
|
15
|
+
private var didLoad = false
|
|
16
|
+
/**
|
|
17
|
+
* Initializes the native part of "Live2dSkia".
|
|
18
|
+
* This method is idempotent and can be called more than once.
|
|
19
|
+
*/
|
|
20
|
+
@JvmStatic
|
|
21
|
+
fun initializeNative() {
|
|
22
|
+
if (didLoad) return
|
|
23
|
+
try {
|
|
24
|
+
Log.i(TAG, "Loading Live2dSkia C++ library...")
|
|
25
|
+
System.loadLibrary("Live2dSkia")
|
|
26
|
+
Log.i(TAG, "Successfully loaded Live2dSkia C++ library!")
|
|
27
|
+
didLoad = true
|
|
28
|
+
} catch (e: Error) {
|
|
29
|
+
Log.e(TAG, "Failed to load Live2dSkia C++ library! Is it properly installed and linked? " +
|
|
30
|
+
"Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e)
|
|
31
|
+
throw e
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Live2dSkia+autolinking.rb
|
|
3
|
+
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
# https://github.com/mrousavy/nitro
|
|
5
|
+
# Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
# This is a Ruby script that adds all files generated by Nitrogen
|
|
9
|
+
# to the given podspec.
|
|
10
|
+
#
|
|
11
|
+
# To use it, add this to your .podspec:
|
|
12
|
+
# ```ruby
|
|
13
|
+
# Pod::Spec.new do |spec|
|
|
14
|
+
# # ...
|
|
15
|
+
#
|
|
16
|
+
# # Add all files generated by Nitrogen
|
|
17
|
+
# load 'nitrogen/generated/ios/Live2dSkia+autolinking.rb'
|
|
18
|
+
# add_nitrogen_files(spec)
|
|
19
|
+
# end
|
|
20
|
+
# ```
|
|
21
|
+
|
|
22
|
+
def add_nitrogen_files(spec)
|
|
23
|
+
Pod::UI.puts "[NitroModules] 🔥 Live2dSkia is boosted by nitro!"
|
|
24
|
+
|
|
25
|
+
spec.dependency "NitroModules"
|
|
26
|
+
|
|
27
|
+
current_source_files = Array(spec.attributes_hash['source_files'])
|
|
28
|
+
spec.source_files = current_source_files + [
|
|
29
|
+
# Generated cross-platform specs
|
|
30
|
+
"nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}",
|
|
31
|
+
# Generated bridges for the cross-platform specs
|
|
32
|
+
"nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
current_public_header_files = Array(spec.attributes_hash['public_header_files'])
|
|
36
|
+
spec.public_header_files = current_public_header_files + [
|
|
37
|
+
# Generated specs
|
|
38
|
+
"nitrogen/generated/shared/**/*.{h,hpp}",
|
|
39
|
+
# Swift to C++ bridging helpers
|
|
40
|
+
"nitrogen/generated/ios/Live2dSkia-Swift-Cxx-Bridge.hpp"
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
current_private_header_files = Array(spec.attributes_hash['private_header_files'])
|
|
44
|
+
spec.private_header_files = current_private_header_files + [
|
|
45
|
+
# iOS specific specs
|
|
46
|
+
"nitrogen/generated/ios/c++/**/*.{h,hpp}",
|
|
47
|
+
# Views are framework-specific and should be private
|
|
48
|
+
"nitrogen/generated/shared/**/views/**/*"
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {}
|
|
52
|
+
spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({
|
|
53
|
+
# Use C++ 20
|
|
54
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
|
55
|
+
# Enables C++ <-> Swift interop (by default it's only ObjC)
|
|
56
|
+
"SWIFT_OBJC_INTEROP_MODE" => "objcxx",
|
|
57
|
+
# Enables stricter modular headers
|
|
58
|
+
"DEFINES_MODULE" => "YES",
|
|
59
|
+
# Disable auto-generated ObjC header for Swift (Static linkage on Xcode 26.4 breaks here)
|
|
60
|
+
"SWIFT_INSTALL_OBJC_HEADER" => "NO",
|
|
61
|
+
})
|
|
62
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Live2dSkia-Swift-Cxx-Bridge.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "Live2dSkia-Swift-Cxx-Bridge.hpp"
|
|
9
|
+
|
|
10
|
+
// Include C++ implementation defined types
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
namespace margelo::nitro::live2dskia::bridge::swift {
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
} // namespace margelo::nitro::live2dskia::bridge::swift
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Live2dSkia-Swift-Cxx-Bridge.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
// Forward declarations of C++ defined types
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
// Forward declarations of Swift defined types
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// Include C++ defined types
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Contains specialized versions of C++ templated types so they can be accessed from Swift,
|
|
21
|
+
* as well as helper functions to interact with those C++ types from Swift.
|
|
22
|
+
*/
|
|
23
|
+
namespace margelo::nitro::live2dskia::bridge::swift {
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
} // namespace margelo::nitro::live2dskia::bridge::swift
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Live2dSkia-Swift-Cxx-Umbrella.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
// Forward declarations of C++ defined types
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
// Include C++ defined types
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// C++ helpers for Swift
|
|
17
|
+
#include "Live2dSkia-Swift-Cxx-Bridge.hpp"
|
|
18
|
+
|
|
19
|
+
// Common C++ types used in Swift
|
|
20
|
+
#include <NitroModules/ArrayBufferHolder.hpp>
|
|
21
|
+
#include <NitroModules/AnyMapUtils.hpp>
|
|
22
|
+
#include <NitroModules/RuntimeError.hpp>
|
|
23
|
+
#include <NitroModules/DateToChronoDate.hpp>
|
|
24
|
+
|
|
25
|
+
// Forward declarations of Swift defined types
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// Include Swift defined types
|
|
29
|
+
#if __has_include("Live2dSkia-Swift.h")
|
|
30
|
+
// This header is generated by Xcode/Swift on every app build.
|
|
31
|
+
// If it cannot be found, make sure the Swift module's name (= podspec name) is actually "Live2dSkia".
|
|
32
|
+
#include "Live2dSkia-Swift.h"
|
|
33
|
+
// Same as above, but used when building with frameworks (`use_frameworks`)
|
|
34
|
+
#elif __has_include(<Live2dSkia/Live2dSkia-Swift.h>)
|
|
35
|
+
#include <Live2dSkia/Live2dSkia-Swift.h>
|
|
36
|
+
#else
|
|
37
|
+
#error Live2dSkia's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "Live2dSkia", and try building the app first.
|
|
38
|
+
#endif
|