完成动画在设备上播放和切换
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
package com.hmwl.face_sdk;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -12,7 +13,11 @@ public class Motion {
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("type", type);
|
||||
jsonObject.put("png_names", png_names);
|
||||
JSONArray ja = new JSONArray();
|
||||
for(int i = 0; i < png_names.size(); ++i){
|
||||
ja.put(png_names.get(i));
|
||||
}
|
||||
jsonObject.put("png_names", ja);
|
||||
return jsonObject;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -7,7 +7,7 @@ android {
|
||||
compileSdk 36
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.hmwl.f20251030"
|
||||
applicationId "com.hmwl.f20251101"
|
||||
minSdk 30
|
||||
targetSdk 36
|
||||
versionCode 1
|
||||
|
||||
@@ -2,6 +2,33 @@
|
||||
"11": [
|
||||
"11.png"
|
||||
],
|
||||
"action24": [
|
||||
"000000.png",
|
||||
"000001.png",
|
||||
"000002.png",
|
||||
"000003.png",
|
||||
"000004.png",
|
||||
"000005.png",
|
||||
"000006.png",
|
||||
"000007.png",
|
||||
"000008.png",
|
||||
"000009.png",
|
||||
"000010.png",
|
||||
"000011.png",
|
||||
"000012.png",
|
||||
"000013.png",
|
||||
"000014.png",
|
||||
"000015.png",
|
||||
"000016.png",
|
||||
"000017.png",
|
||||
"000018.png",
|
||||
"000019.png",
|
||||
"000020.png",
|
||||
"000021.png",
|
||||
"000022.png",
|
||||
"000023.png",
|
||||
"000024.png"
|
||||
],
|
||||
"12": [
|
||||
"12.png"
|
||||
],
|
||||
@@ -94,32 +121,5 @@
|
||||
],
|
||||
"81": [
|
||||
"81.png"
|
||||
],
|
||||
"action24": [
|
||||
"000000.png",
|
||||
"000001.png",
|
||||
"000002.png",
|
||||
"000003.png",
|
||||
"000004.png",
|
||||
"000005.png",
|
||||
"000006.png",
|
||||
"000007.png",
|
||||
"000008.png",
|
||||
"000009.png",
|
||||
"000010.png",
|
||||
"000011.png",
|
||||
"000012.png",
|
||||
"000013.png",
|
||||
"000014.png",
|
||||
"000015.png",
|
||||
"000016.png",
|
||||
"000017.png",
|
||||
"000018.png",
|
||||
"000019.png",
|
||||
"000020.png",
|
||||
"000021.png",
|
||||
"000022.png",
|
||||
"000023.png",
|
||||
"000024.png"
|
||||
]
|
||||
}
|
||||
@@ -33,10 +33,10 @@ public class MainActivity extends FaceActivity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
Motion motion = new Motion();
|
||||
motion.type = "4";
|
||||
motion.png_names.add("4.png");
|
||||
motion.type = "11";
|
||||
motion.png_names.add("11.png");
|
||||
InitArg initArg = new InitArg();
|
||||
initArg.action_fps = 3;
|
||||
initArg.action_fps = 10;
|
||||
initArg.zoom = 1.5f;
|
||||
initArg.motion = motion;
|
||||
SetInitArg(initArg.toJson());
|
||||
@@ -44,12 +44,13 @@ public class MainActivity extends FaceActivity
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
FaceInit(this);
|
||||
Toast.makeText(this, "4.png", Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(this, "11.png", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
String GetCurMotionState(int index)
|
||||
{
|
||||
Motion motion = new Motion();
|
||||
motion.type = pngFilesByFolder.get(index).folderName;
|
||||
motion.png_names = pngFilesByFolder.get(index).getFileList();
|
||||
return motion.toJson();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">f20251030</string>
|
||||
<string name="app_name">f20251101</string>
|
||||
</resources>
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
void createRenderPass();
|
||||
void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex, long long frameTime);
|
||||
void createSyncObjects();
|
||||
void drawFrame(long long frameTime);
|
||||
virtual void drawFrame(long long frameTime);
|
||||
virtual void render(VkCommandBuffer commandBuffer, long long frameTime);
|
||||
virtual bool isInited() { return inited; }
|
||||
|
||||
@@ -89,4 +89,6 @@ protected:
|
||||
void destroy_texture(Texture texture);
|
||||
std::mutex mtx;
|
||||
long long _lastDrawFrameTime;
|
||||
|
||||
std::mutex changeMotionMtx;
|
||||
};
|
||||
+46
-40
@@ -456,34 +456,7 @@ void FaceApp::create_face_pipelines()
|
||||
VK_CHECK(vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipeline_create_info, nullptr, &m_graphicsPipeline));
|
||||
}
|
||||
|
||||
void FaceApp::setup_descriptor_pool()
|
||||
{
|
||||
// 保守估计:假设每个描述符集可能有多个绑定
|
||||
const uint32_t setsCount = kMaxTexture;
|
||||
//const uint32_t multiplier = 3; // 安全系数
|
||||
|
||||
std::vector<VkDescriptorPoolSize> pool_sizes = {
|
||||
{
|
||||
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.descriptorCount = 3
|
||||
},
|
||||
{
|
||||
.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
.descriptorCount = setsCount + 4
|
||||
},
|
||||
// 如果需要其他类型的描述符,在这里添加
|
||||
};
|
||||
|
||||
VkDescriptorPoolCreateInfo descriptor_pool_info{};
|
||||
descriptor_pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||
descriptor_pool_info.poolSizeCount = static_cast<uint32_t>(pool_sizes.size());
|
||||
descriptor_pool_info.pPoolSizes = pool_sizes.data();
|
||||
descriptor_pool_info.maxSets = setsCount + 7; // 额外预留一些集合
|
||||
descriptor_pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||
|
||||
VK_CHECK(vkCreateDescriptorPool(device, &descriptor_pool_info, nullptr, &descriptor_pool));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -553,6 +526,32 @@ void FaceApp::setup_descriptor_set_layout()
|
||||
VK_CHECK(vkCreatePipelineLayout(device, &pipeline_layout_create_info, nullptr, &m_pipelineLayout));
|
||||
}
|
||||
|
||||
void FaceApp::setup_descriptor_pool()
|
||||
{
|
||||
|
||||
std::vector<VkDescriptorPoolSize> pool_sizes = {
|
||||
{
|
||||
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.descriptorCount = kMaxTexture
|
||||
},
|
||||
{
|
||||
.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
.descriptorCount = (kMaxTexture + 1)
|
||||
},
|
||||
// 如果需要其他类型的描述符,在这里添加
|
||||
};
|
||||
|
||||
VkDescriptorPoolCreateInfo descriptor_pool_info{};
|
||||
descriptor_pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||
descriptor_pool_info.poolSizeCount = static_cast<uint32_t>(pool_sizes.size());
|
||||
descriptor_pool_info.pPoolSizes = pool_sizes.data();
|
||||
descriptor_pool_info.maxSets = kMaxTexture + (kMaxTexture + 1);
|
||||
descriptor_pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||
|
||||
VK_CHECK(vkCreateDescriptorPool(device, &descriptor_pool_info, nullptr, &descriptor_pool));
|
||||
|
||||
}
|
||||
|
||||
void FaceApp::setup_descriptor_set()
|
||||
{
|
||||
m_descriptor_sets.resize(kMaxTexture);
|
||||
@@ -646,21 +645,10 @@ void FaceApp::setup_descriptor_set()
|
||||
|
||||
void FaceApp::render(VkCommandBuffer commandBuffer, long long frameTime)
|
||||
{
|
||||
static long long game_time = 0;
|
||||
game_time += frameTime;
|
||||
long long actionTime = (1000 / _initArg.action_fps);
|
||||
if (game_time > actionTime)
|
||||
{
|
||||
_curTexIndex++;
|
||||
if (_curTexIndex >= _curMotion.png_names.size())
|
||||
{
|
||||
_curTexIndex = 0;
|
||||
}
|
||||
game_time = game_time - actionTime;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
std::unique_lock<std::mutex> lock_point(mtx_point);
|
||||
|
||||
//Application::render(commandBuffer);
|
||||
|
||||
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout_bg, 0, 1, &m_descriptor_set_bg, 0, NULL);
|
||||
@@ -926,7 +914,7 @@ void FaceApp::createUniformBuffer()
|
||||
|
||||
|
||||
void FaceApp::create_pipelines_bg()
|
||||
{
|
||||
{
|
||||
VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
|
||||
input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
||||
input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
@@ -1137,6 +1125,23 @@ void FaceApp::SetInitArg(const char* arg)
|
||||
|
||||
}
|
||||
|
||||
void FaceApp::drawFrame(long long frameTime)
|
||||
{
|
||||
std::unique_lock lock(changeMotionMtx);
|
||||
static long long game_time = 0;
|
||||
game_time += frameTime;
|
||||
long long actionTime = (1000 / _initArg.action_fps);
|
||||
if (game_time > actionTime)
|
||||
{
|
||||
_curTexIndex++;
|
||||
if (_curTexIndex >= _curMotion.png_names.size())
|
||||
{
|
||||
_curTexIndex = 0;
|
||||
}
|
||||
game_time = game_time - actionTime;
|
||||
}
|
||||
Application::drawFrame(frameTime);
|
||||
}
|
||||
|
||||
void FaceApp::changeMotion(const char* json)
|
||||
{
|
||||
@@ -1150,6 +1155,7 @@ void FaceApp::changeMotion(Motion& motion)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock_changeMotion(changeMotionMtx);
|
||||
_curMotion = motion;
|
||||
for (int i = 0; i < _curMotion.png_names.size(); ++i)
|
||||
{
|
||||
|
||||
+3
-1
@@ -100,7 +100,7 @@ private:
|
||||
VkPipelineLayout m_pipelineLayout = VK_NULL_HANDLE;
|
||||
VkDescriptorSetLayout m_descriptorSetLayout = VK_NULL_HANDLE;
|
||||
vector<VkDescriptorSet> m_descriptor_sets;
|
||||
const int kMaxTexture = 30;
|
||||
const uint32_t kMaxTexture = 30;
|
||||
vector<Texture> m_texs;
|
||||
vector<Texture> m_texs_ex;
|
||||
|
||||
@@ -141,6 +141,8 @@ public:
|
||||
Motion _curMotion;
|
||||
int _curTexIndex = 0;
|
||||
void SetInitArg(const char* arg);
|
||||
|
||||
void drawFrame(long long frameTime)override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user