@airisu-dev/react-native-live2d-skia 0.0.0-stage → 0.1.0
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 +64 -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 +146 -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 +194 -0
- package/src/loader/modelContext.ts +80 -0
- package/src/loader/modelUrl.ts +112 -0
- package/src/native.ts +4 -0
- package/src/rendering/drawer.ts +256 -0
- package/src/rendering/skia.ts +114 -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,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
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Live2dSkiaAutolinking.mm
|
|
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
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
#import <NitroModules/HybridObjectRegistry.hpp>
|
|
10
|
+
|
|
11
|
+
#import <type_traits>
|
|
12
|
+
|
|
13
|
+
#include "HybridLive2dSkia.hpp"
|
|
14
|
+
|
|
15
|
+
@interface Live2dSkiaAutolinking : NSObject
|
|
16
|
+
@end
|
|
17
|
+
|
|
18
|
+
@implementation Live2dSkiaAutolinking
|
|
19
|
+
|
|
20
|
+
+ (void) load {
|
|
21
|
+
using namespace margelo::nitro;
|
|
22
|
+
using namespace margelo::nitro::live2dskia;
|
|
23
|
+
|
|
24
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
25
|
+
"Live2dSkia",
|
|
26
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
27
|
+
static_assert(std::is_default_constructible_v<HybridLive2dSkia>,
|
|
28
|
+
"The HybridObject \"HybridLive2dSkia\" is not default-constructible! "
|
|
29
|
+
"Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
|
|
30
|
+
return std::make_shared<HybridLive2dSkia>();
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Live2dSkiaAutolinking.swift
|
|
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
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
// TODO: Use empty enums once Swift supports exporting them as namespaces
|
|
11
|
+
// See: https://github.com/swiftlang/swift/pull/83616
|
|
12
|
+
public final class Live2dSkiaAutolinking {
|
|
13
|
+
public typealias bridge = margelo.nitro.live2dskia.bridge.swift
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// DrawableData.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
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#include <vector>
|
|
34
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
35
|
+
|
|
36
|
+
namespace margelo::nitro::live2dskia {
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A struct which can be represented as a JavaScript object (DrawableData).
|
|
40
|
+
*/
|
|
41
|
+
struct DrawableData final {
|
|
42
|
+
public:
|
|
43
|
+
double index SWIFT_PRIVATE;
|
|
44
|
+
bool visible SWIFT_PRIVATE;
|
|
45
|
+
double textureIndex SWIFT_PRIVATE;
|
|
46
|
+
double opacity SWIFT_PRIVATE;
|
|
47
|
+
double constantFlags SWIFT_PRIVATE;
|
|
48
|
+
std::vector<double> masks SWIFT_PRIVATE;
|
|
49
|
+
std::shared_ptr<ArrayBuffer> positions SWIFT_PRIVATE;
|
|
50
|
+
std::shared_ptr<ArrayBuffer> uvs SWIFT_PRIVATE;
|
|
51
|
+
std::shared_ptr<ArrayBuffer> indices SWIFT_PRIVATE;
|
|
52
|
+
|
|
53
|
+
public:
|
|
54
|
+
DrawableData() = default;
|
|
55
|
+
explicit DrawableData(double index, bool visible, double textureIndex, double opacity, double constantFlags, std::vector<double> masks, std::shared_ptr<ArrayBuffer> positions, std::shared_ptr<ArrayBuffer> uvs, std::shared_ptr<ArrayBuffer> indices): index(index), visible(visible), textureIndex(textureIndex), opacity(opacity), constantFlags(constantFlags), masks(masks), positions(positions), uvs(uvs), indices(indices) {}
|
|
56
|
+
|
|
57
|
+
public:
|
|
58
|
+
friend bool operator==(const DrawableData& lhs, const DrawableData& rhs) = default;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
} // namespace margelo::nitro::live2dskia
|
|
62
|
+
|
|
63
|
+
namespace margelo::nitro {
|
|
64
|
+
|
|
65
|
+
// C++ DrawableData <> JS DrawableData (object)
|
|
66
|
+
template <>
|
|
67
|
+
struct JSIConverter<margelo::nitro::live2dskia::DrawableData> final {
|
|
68
|
+
static inline margelo::nitro::live2dskia::DrawableData fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
69
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
70
|
+
return margelo::nitro::live2dskia::DrawableData(
|
|
71
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "index"))),
|
|
72
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "visible"))),
|
|
73
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "textureIndex"))),
|
|
74
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "opacity"))),
|
|
75
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "constantFlags"))),
|
|
76
|
+
JSIConverter<std::vector<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "masks"))),
|
|
77
|
+
JSIConverter<std::shared_ptr<ArrayBuffer>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "positions"))),
|
|
78
|
+
JSIConverter<std::shared_ptr<ArrayBuffer>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "uvs"))),
|
|
79
|
+
JSIConverter<std::shared_ptr<ArrayBuffer>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "indices")))
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::live2dskia::DrawableData& arg) {
|
|
83
|
+
jsi::Object obj(runtime);
|
|
84
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "index"), JSIConverter<double>::toJSI(runtime, arg.index));
|
|
85
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "visible"), JSIConverter<bool>::toJSI(runtime, arg.visible));
|
|
86
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "textureIndex"), JSIConverter<double>::toJSI(runtime, arg.textureIndex));
|
|
87
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "opacity"), JSIConverter<double>::toJSI(runtime, arg.opacity));
|
|
88
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "constantFlags"), JSIConverter<double>::toJSI(runtime, arg.constantFlags));
|
|
89
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "masks"), JSIConverter<std::vector<double>>::toJSI(runtime, arg.masks));
|
|
90
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "positions"), JSIConverter<std::shared_ptr<ArrayBuffer>>::toJSI(runtime, arg.positions));
|
|
91
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "uvs"), JSIConverter<std::shared_ptr<ArrayBuffer>>::toJSI(runtime, arg.uvs));
|
|
92
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "indices"), JSIConverter<std::shared_ptr<ArrayBuffer>>::toJSI(runtime, arg.indices));
|
|
93
|
+
return obj;
|
|
94
|
+
}
|
|
95
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
96
|
+
if (!value.isObject()) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
jsi::Object obj = value.getObject(runtime);
|
|
100
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "index")))) return false;
|
|
104
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "visible")))) return false;
|
|
105
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "textureIndex")))) return false;
|
|
106
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "opacity")))) return false;
|
|
107
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "constantFlags")))) return false;
|
|
108
|
+
if (!JSIConverter<std::vector<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "masks")))) return false;
|
|
109
|
+
if (!JSIConverter<std::shared_ptr<ArrayBuffer>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "positions")))) return false;
|
|
110
|
+
if (!JSIConverter<std::shared_ptr<ArrayBuffer>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "uvs")))) return false;
|
|
111
|
+
if (!JSIConverter<std::shared_ptr<ArrayBuffer>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "indices")))) return false;
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridLive2DModelSpec.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 "HybridLive2DModelSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::live2dskia {
|
|
11
|
+
|
|
12
|
+
void HybridLive2DModelSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("canvasWidth", &HybridLive2DModelSpec::getCanvasWidth);
|
|
18
|
+
prototype.registerHybridGetter("canvasHeight", &HybridLive2DModelSpec::getCanvasHeight);
|
|
19
|
+
prototype.registerHybridGetter("originX", &HybridLive2DModelSpec::getOriginX);
|
|
20
|
+
prototype.registerHybridGetter("originY", &HybridLive2DModelSpec::getOriginY);
|
|
21
|
+
prototype.registerHybridGetter("pixelsPerUnit", &HybridLive2DModelSpec::getPixelsPerUnit);
|
|
22
|
+
prototype.registerHybridGetter("drawableCount", &HybridLive2DModelSpec::getDrawableCount);
|
|
23
|
+
prototype.registerHybridMethod("getDrawables", &HybridLive2DModelSpec::getDrawables);
|
|
24
|
+
prototype.registerHybridMethod("loadPhysics", &HybridLive2DModelSpec::loadPhysics);
|
|
25
|
+
prototype.registerHybridMethod("loadPose", &HybridLive2DModelSpec::loadPose);
|
|
26
|
+
prototype.registerHybridMethod("loadMotion", &HybridLive2DModelSpec::loadMotion);
|
|
27
|
+
prototype.registerHybridMethod("startMotion", &HybridLive2DModelSpec::startMotion);
|
|
28
|
+
prototype.registerHybridMethod("loadExpression", &HybridLive2DModelSpec::loadExpression);
|
|
29
|
+
prototype.registerHybridMethod("setExpression", &HybridLive2DModelSpec::setExpression);
|
|
30
|
+
prototype.registerHybridMethod("clearExpression", &HybridLive2DModelSpec::clearExpression);
|
|
31
|
+
prototype.registerHybridMethod("setParameter", &HybridLive2DModelSpec::setParameter);
|
|
32
|
+
prototype.registerHybridMethod("clearParameter", &HybridLive2DModelSpec::clearParameter);
|
|
33
|
+
prototype.registerHybridMethod("focus", &HybridLive2DModelSpec::focus);
|
|
34
|
+
prototype.registerHybridMethod("hitTest", &HybridLive2DModelSpec::hitTest);
|
|
35
|
+
prototype.registerHybridMethod("update", &HybridLive2DModelSpec::update);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
} // namespace margelo::nitro::live2dskia
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridLive2DModelSpec.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
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `DrawableData` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::live2dskia { struct DrawableData; }
|
|
18
|
+
// Forward declaration of `MotionPriority` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::live2dskia { enum class MotionPriority; }
|
|
20
|
+
|
|
21
|
+
#include "DrawableData.hpp"
|
|
22
|
+
#include <vector>
|
|
23
|
+
#include <string>
|
|
24
|
+
#include <optional>
|
|
25
|
+
#include "MotionPriority.hpp"
|
|
26
|
+
|
|
27
|
+
namespace margelo::nitro::live2dskia {
|
|
28
|
+
|
|
29
|
+
using namespace margelo::nitro;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* An abstract base class for `Live2DModel`
|
|
33
|
+
* Inherit this class to create instances of `HybridLive2DModelSpec` in C++.
|
|
34
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
35
|
+
* @example
|
|
36
|
+
* ```cpp
|
|
37
|
+
* class HybridLive2DModel: public HybridLive2DModelSpec {
|
|
38
|
+
* public:
|
|
39
|
+
* HybridLive2DModel(...): HybridObject(TAG) { ... }
|
|
40
|
+
* // ...
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
class HybridLive2DModelSpec: public virtual HybridObject {
|
|
45
|
+
public:
|
|
46
|
+
// Constructor
|
|
47
|
+
explicit HybridLive2DModelSpec(): HybridObject(TAG) { }
|
|
48
|
+
|
|
49
|
+
// Destructor
|
|
50
|
+
~HybridLive2DModelSpec() override = default;
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
// Properties
|
|
54
|
+
virtual double getCanvasWidth() = 0;
|
|
55
|
+
virtual double getCanvasHeight() = 0;
|
|
56
|
+
virtual double getOriginX() = 0;
|
|
57
|
+
virtual double getOriginY() = 0;
|
|
58
|
+
virtual double getPixelsPerUnit() = 0;
|
|
59
|
+
virtual double getDrawableCount() = 0;
|
|
60
|
+
|
|
61
|
+
public:
|
|
62
|
+
// Methods
|
|
63
|
+
virtual std::vector<DrawableData> getDrawables() = 0;
|
|
64
|
+
virtual void loadPhysics(const std::string& json) = 0;
|
|
65
|
+
virtual void loadPose(const std::string& json) = 0;
|
|
66
|
+
virtual void loadMotion(const std::string& group, double index, const std::string& json) = 0;
|
|
67
|
+
virtual bool startMotion(const std::string& group, std::optional<double> index, std::optional<MotionPriority> priority) = 0;
|
|
68
|
+
virtual void loadExpression(const std::string& name, const std::string& json) = 0;
|
|
69
|
+
virtual bool setExpression(const std::optional<std::string>& name) = 0;
|
|
70
|
+
virtual void clearExpression() = 0;
|
|
71
|
+
virtual void setParameter(const std::string& id, double value) = 0;
|
|
72
|
+
virtual void clearParameter(const std::string& id) = 0;
|
|
73
|
+
virtual void focus(double x, double y) = 0;
|
|
74
|
+
virtual std::vector<std::string> hitTest(double x, double y) = 0;
|
|
75
|
+
virtual void update(double deltaSeconds) = 0;
|
|
76
|
+
|
|
77
|
+
protected:
|
|
78
|
+
// Hybrid Setup
|
|
79
|
+
void loadHybridMethods() override;
|
|
80
|
+
|
|
81
|
+
protected:
|
|
82
|
+
// Tag for logging
|
|
83
|
+
static constexpr auto TAG = "Live2DModel";
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
} // namespace margelo::nitro::live2dskia
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridLive2dSkiaSpec.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 "HybridLive2dSkiaSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::live2dskia {
|
|
11
|
+
|
|
12
|
+
void HybridLive2dSkiaSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("loadModel", &HybridLive2dSkiaSpec::loadModel);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
} // namespace margelo::nitro::live2dskia
|