Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c83f36c976 | ||
|
|
29e0c1e9a8 | ||
|
|
7b07e7fbc1 | ||
|
|
b6ac86a134 | ||
|
|
6bbbb3c3ef | ||
|
|
e38da96e37 |
|
After Width: | Height: | Size: 16 KiB |
@@ -5,12 +5,20 @@ layout (binding = 1) uniform sampler2D samplerColor;
|
||||
layout (location = 0) in vec2 inUV;
|
||||
layout (location = 1) in vec3 inNormal;
|
||||
|
||||
layout(push_constant) uniform PushConstants {
|
||||
float myValue;
|
||||
float ux;
|
||||
float uy;
|
||||
} pushConstants;
|
||||
|
||||
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture(samplerColor, inUV);
|
||||
vec2 pos = vec2(pushConstants.ux/2048.f, pushConstants.uy/2048.f);
|
||||
vec2 uv = pos + vec2(inUV.x/8.f, inUV.y/8.f);
|
||||
vec4 color = texture(samplerColor, uv);
|
||||
|
||||
outFragColor = color;
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ layout (location = 1) out vec3 outNormal;
|
||||
|
||||
layout(push_constant) uniform PushConstants {
|
||||
float myValue;
|
||||
float ux;
|
||||
float uy;
|
||||
} pushConstants;
|
||||
|
||||
out gl_PerVertex
|
||||
|
||||
@@ -165,7 +165,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
void CppCallback(const string& motion_type)
|
||||
void CppCallback()
|
||||
{
|
||||
JNIEnv* env = nullptr;
|
||||
bool needDetach = false;
|
||||
@@ -196,7 +196,7 @@ void CppCallback(const string& motion_type)
|
||||
}
|
||||
|
||||
// 2. 获取 OnLoadActionFinished 方法 ID(注意方法名大小写必须一致!)
|
||||
jmethodID methodId = env->GetMethodID(callbackClass, "OnLoadActionFinished", "(Ljava/lang/String;)V");
|
||||
jmethodID methodId = env->GetMethodID(callbackClass, "OnLoadMotionListFinished", "(Ljava/lang/String;)V");
|
||||
if (methodId == nullptr) {
|
||||
env->ExceptionDescribe(); // 打印异常
|
||||
env->ExceptionClear();
|
||||
@@ -205,7 +205,7 @@ void CppCallback(const string& motion_type)
|
||||
}
|
||||
|
||||
// 3. 构造 jstring 参数
|
||||
jstring jResult = env->NewStringUTF(motion_type.c_str());
|
||||
jstring jResult = env->NewStringUTF("ok");
|
||||
|
||||
// 4. 调用 Java 回调
|
||||
env->CallVoidMethod(g_callback, methodId, jResult);
|
||||
@@ -258,7 +258,7 @@ void CppAnimationFinishedCallback()
|
||||
}
|
||||
|
||||
// 2. 获取 OnLoadActionFinished 方法 ID(注意方法名大小写必须一致!)
|
||||
jmethodID methodId = env->GetMethodID(callbackClass, "OnAnimationFinished", "()V");
|
||||
jmethodID methodId = env->GetMethodID(callbackClass, "OnPlayMotionListFinished", "()V");
|
||||
if (methodId == nullptr) {
|
||||
env->ExceptionDescribe(); // 打印异常
|
||||
env->ExceptionClear();
|
||||
@@ -309,10 +309,29 @@ Java_com_hmwl_face_1sdk_FaceActivity_PreReadAction(JNIEnv *env, jobject thiz, js
|
||||
aout << "ArgLen to long:" << len << std::endl;
|
||||
}
|
||||
|
||||
std::string ret = g_Application->preReadyMotion(nativeString, CppCallback);
|
||||
std::string ret = g_Application->preLoadMotionList(nativeString, CppCallback);
|
||||
return env->NewStringUTF(ret.c_str());
|
||||
}
|
||||
|
||||
const char DELIMITER = 0x1F; // same as \u001F
|
||||
|
||||
std::vector<std::string> splitMotionString(const std::string& input) {
|
||||
std::vector<std::string> result;
|
||||
if (input.empty()) return result;
|
||||
|
||||
size_t start = 0;
|
||||
size_t pos = input.find(DELIMITER);
|
||||
|
||||
while (pos != std::string::npos) {
|
||||
result.push_back(input.substr(start, pos - start));
|
||||
start = pos + 1;
|
||||
pos = input.find(DELIMITER, start);
|
||||
}
|
||||
// Add last part
|
||||
result.push_back(input.substr(start));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
@@ -336,6 +355,18 @@ Java_com_hmwl_face_1sdk_FaceActivity_ChangeMotionCpp(JNIEnv *env, jobject thiz,
|
||||
|
||||
if(g_Application->isInited())
|
||||
{
|
||||
g_Application->changeMotion(nativeString, CppAnimationFinishedCallback, loop);
|
||||
std::vector<std::string> motions = splitMotionString(nativeString);
|
||||
g_Application->changeMotionList(motions, CppAnimationFinishedCallback, loop);
|
||||
}
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_hmwl_face_1sdk_FaceActivity_StopMotionNative(JNIEnv *env, jobject thiz) {
|
||||
g_Application->StopMotion();
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_hmwl_face_1sdk_FaceActivity_ResumeMotionNative(JNIEnv *env, jobject thiz) {
|
||||
// TODO: implement ResumeMotionNative()
|
||||
g_Application->ResumeMotion();
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -31,7 +30,6 @@ import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class FaceActivity extends GameActivity implements FaceLandmarkerHelper.LandmarkerListener {
|
||||
private static final String TAG = "FaceActivity";
|
||||
@@ -141,6 +139,16 @@ public class FaceActivity extends GameActivity implements FaceLandmarkerHelper.L
|
||||
StopRunning();
|
||||
}
|
||||
|
||||
private native void StopMotionNative();
|
||||
public void StopMotion(){
|
||||
StopMotionNative();
|
||||
}
|
||||
|
||||
private native void ResumeMotionNative();
|
||||
public void ResumeMotion(){
|
||||
ResumeMotionNative();
|
||||
}
|
||||
|
||||
private native void StopRunning();
|
||||
|
||||
// Native 方法
|
||||
@@ -282,28 +290,39 @@ public class FaceActivity extends GameActivity implements FaceLandmarkerHelper.L
|
||||
|
||||
protected native void SetCppInitArg(String json);
|
||||
|
||||
protected void SetInitArg(String json)
|
||||
public void SetInitArg(String json)
|
||||
{
|
||||
SetCppInitArg(json);
|
||||
}
|
||||
|
||||
public interface CallbackInterface {
|
||||
void OnLoadActionFinished(String result);
|
||||
public interface LoadMotionListFinishedCallback {
|
||||
void OnLoadMotionListFinished(String result);
|
||||
}
|
||||
|
||||
public interface AnimationFinishedCallbackInterface {
|
||||
void OnAnimationFinished();
|
||||
public interface PlayMotionListFinishedCallback {
|
||||
void OnPlayMotionListFinished();
|
||||
}
|
||||
|
||||
protected native String PreReadAction(String motion, CallbackInterface callback);
|
||||
protected String PreLoadAction(String json, CallbackInterface callback){
|
||||
protected native String PreReadAction(String motion, LoadMotionListFinishedCallback callback);
|
||||
public String PreLoadAction(String json, LoadMotionListFinishedCallback callback){
|
||||
return PreReadAction(json, callback);
|
||||
}
|
||||
|
||||
protected native void ChangeMotionCpp(String json, AnimationFinishedCallbackInterface callback, boolean loop);
|
||||
protected void ChangeMotion(String json, AnimationFinishedCallbackInterface callback, boolean loop){
|
||||
Log.i("FaceActivity", "ChangeState:" + json);
|
||||
ChangeMotionCpp(json, callback, loop);
|
||||
protected native void ChangeMotionCpp(String json, PlayMotionListFinishedCallback callback, boolean loop);
|
||||
public void PlayMotionList(List<String> motionList, boolean loop, PlayMotionListFinishedCallback callback)
|
||||
{
|
||||
if(callback == null)
|
||||
{
|
||||
callback = new PlayMotionListFinishedCallback() {
|
||||
@Override
|
||||
public void OnPlayMotionListFinished() {
|
||||
Log.i(TAG, "OnPlayMotionListFinished: ");
|
||||
}
|
||||
};
|
||||
}
|
||||
final String DELIMITER = "\u001F"; // ASCII Unit Separator
|
||||
String motion_list_str = String.join(DELIMITER, motionList);
|
||||
ChangeMotionCpp(motion_list_str, callback, loop);
|
||||
}
|
||||
|
||||
// 添加这个缺失的方法
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.hmwl.face_sdk;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Frame {
|
||||
public String name;
|
||||
public float x;
|
||||
public float y;
|
||||
public Frame(String name, float x, float y)
|
||||
{
|
||||
this.name = name;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
public JSONObject toJsonObject(){
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("name", name);
|
||||
jsonObject.put("x", x);
|
||||
jsonObject.put("y", y);
|
||||
return jsonObject;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,32 +5,29 @@ import org.json.JSONObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Motion {
|
||||
public String type = "no";
|
||||
public List<String> png_names = new ArrayList<>();
|
||||
public String name = "no";
|
||||
public List<Frame> frames = new ArrayList<>();
|
||||
public Motion(String name, List<Frame> frames)
|
||||
{
|
||||
this.name = name;
|
||||
this.frames = frames;
|
||||
}
|
||||
|
||||
public JSONObject toJsonObject() {
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("type", type);
|
||||
JSONArray ja = new JSONArray();
|
||||
for(int i = 0; i < png_names.size(); ++i){
|
||||
ja.put(png_names.get(i));
|
||||
jsonObject.put("name", name);
|
||||
JSONArray jframes = new JSONArray();
|
||||
for(int i = 0; i < frames.size(); ++i){
|
||||
jframes.put(frames.get(i).toJsonObject());
|
||||
}
|
||||
jsonObject.put("png_names", ja);
|
||||
jsonObject.put("frames", jframes);
|
||||
return jsonObject;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
try {
|
||||
return toJsonObject().toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.hmwl.face_sdk;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MotionList {
|
||||
public List<Motion> motions = new ArrayList<>();
|
||||
public JSONObject toJsonObject() {
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
JSONArray jMotions = new JSONArray();
|
||||
for(int i = 0; i < motions.size(); ++i){
|
||||
jMotions.put(motions.get(i).toJsonObject());
|
||||
}
|
||||
jsonObject.put("motions", jMotions);
|
||||
return jsonObject;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new JSONObject();
|
||||
}
|
||||
}
|
||||
public String toJsonString(){
|
||||
return toJsonObject().toString();
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,9 @@ glslangValidator -V app/src/main/assets/shaders/bg.vert -o app/src/main/assets/s
|
||||
glslangValidator -V app/src/main/assets/shaders/texture.frag -o app/src/main/assets/shaders/texture.frag.spv
|
||||
glslangValidator -V app/src/main/assets/shaders/texture.vert -o app/src/main/assets/shaders/texture.vert.spv
|
||||
|
||||
glslangValidator -V app/src/main/assets/shaders/texture_thick.frag -o app/src/main/assets/shaders/texture_thick.frag.spv
|
||||
glslangValidator -V app/src/main/assets/shaders/texture_thick.vert -o app/src/main/assets/shaders/texture_thick.vert.spv
|
||||
|
||||
glslangValidator -V app/src/main/assets/shaders/simple_shader.frag -o app/src/main/assets/shaders/simple_shader.frag.spv
|
||||
glslangValidator -V app/src/main/assets/shaders/simple_shader.vert -o app/src/main/assets/shaders/simple_shader.vert.spv
|
||||
|
||||
glslangValidator -V app/src/main/assets/shaders/texture_thick.frag -o app/src/main/assets/shaders/texture_thick.frag.spv
|
||||
rem glslangValidator -V app/src/main/assets/shaders/texture_thick.vert -o app/src/main/assets/shaders/texture_thick.vert.spv
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 4.7 KiB |