Skip to content

Commit

Permalink
Added WINDOWFRAME_ADD and WINDOWFRAME_DELETE to support multiple fram…
Browse files Browse the repository at this point in the history
…e images
  • Loading branch information
LeeAkinobu committed May 27, 2024
1 parent f378ed9 commit f7f1778
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 55 deletions.
15 changes: 15 additions & 0 deletions Library_MMDAgent/include/MMDAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
#define MMDAGENT_COMMAND_ROTATESTOP "ROTATE_STOP"
#define MMDAGENT_COMMAND_STAGE "STAGE"
#define MMDAGENT_COMMAND_WINDOWFRAME "WINDOWFRAME"
#define MMDAGENT_COMMAND_WINDOWFRAME_ADD "WINDOWFRAME_ADD"
#define MMDAGENT_COMMAND_WINDOWFRAME_DELETE "WINDOWFRAME_DELETE"
#define MMDAGENT_COMMAND_WINDOWFRAME_DELETEALL "WINDOWFRAME_DELETEALL"
#define MMDAGENT_COMMAND_LIGHTCOLOR "LIGHTCOLOR"
#define MMDAGENT_COMMAND_LIGHTDIRECTION "LIGHTDIRECTION"
#define MMDAGENT_COMMAND_LIPSYNCSTART "LIPSYNC_START"
Expand Down Expand Up @@ -181,6 +184,9 @@
#define MMDAGENT_EVENT_CAPTION_SETSTYLE "CAPTION_EVENT_SETSTYLE"
#define MMDAGENT_EVENT_CAPTION_START "CAPTION_EVENT_START"
#define MMDAGENT_EVENT_CAPTION_STOP "CAPTION_EVENT_STOP"
#define MMDAGENT_EVENT_WINDOWFRAME_ADD "WINDOWFRAME_EVENT_ADD"
#define MMDAGENT_EVENT_WINDOWFRAME_DELETE "WINDOWFRAME_EVENT_DELETE"


#define MMDAGENT_CURRENTTIME
#define MMDAGENT_TAPPED
Expand Down Expand Up @@ -442,6 +448,15 @@ class MMDAgent
/* setWindowFrame: set window frame */
bool setWindowFrame(const char *fileName);

/* addWindowFrame: add window frame */
bool addWindowFrame(const char *frameAlias, const char *fileName);

/* deleteWindowFrame: delete window frame */
bool deleteWindowFrame(const char *frameAlias);

/* deleteAllWindowFrame: delete all window frame */
bool deleteAllWindowFrame();

/* changeCamera: change camera setting */
bool changeCamera(const char *pos, const char *rot, const char *distance, const char *fovy, const char *time, const char *modelalias, const char *bonename);

Expand Down
31 changes: 23 additions & 8 deletions Library_MMDAgent/include/Stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
/* POSSIBILITY OF SUCH DAMAGE. */
/* ----------------------------------------------------------------- */

/* maximum number of frame textures */
#define MMDAGENT_STAGE_FRAME_TEXTURE_MAX 30

/* Stage: stage */
class Stage
{
Expand All @@ -69,12 +72,18 @@ class Stage
/* work area */
GLfloat m_floorShadow[4][4]; /* matrix for shadow of floor */

PMDTexture *m_frameTexture; /* window frame texture */
GLfloat m_frameVertices[12];
GLindices m_frameIndices[6];
GLfloat m_frameTexcoords[8];
float m_width;
float m_height;
/* frame texture */
struct FrameTexture {
PMDTexture *texture; // texture image
char *alias; // alias name
};
FrameTexture m_frameTextures[MMDAGENT_STAGE_FRAME_TEXTURE_MAX]; // list of frame textures
int m_frameTextureNum; // valid num of frame textures
GLfloat m_frameVertices[12]; // vertices to draw frame textures
GLindices m_frameIndices[6]; // indices to draw frame textures
GLfloat m_frameTexcoords[8]; // texture coordinates to draw frame textures
float m_width; // stored screen width
float m_height; // stored screen height

/* initialize: initialize stage */
void initialize();
Expand Down Expand Up @@ -126,8 +135,14 @@ class Stage
/* update: update */
void update(double ellapsedFrame);

/* loadFrameTexture: load frame texture */
bool loadFrameTexture(const char *file);
/* addFrameTexture: add frame texture */
bool addFrameTexture(const char *alias, const char *file);

/* deleteFrameTexture: delete frame texture */
bool deleteFrameTexture(const char *alias);

/* deleteAllFrameTexture: delete all frame texture */
bool deleteAllFrameTexture();

/* hasFrameTexture: return TRUE if has frame texture */
bool hasFrameTexture();
Expand Down
15 changes: 15 additions & 0 deletions Library_MMDAgent/src/include/MMDAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
#define MMDAGENT_COMMAND_ROTATESTOP "ROTATE_STOP"
#define MMDAGENT_COMMAND_STAGE "STAGE"
#define MMDAGENT_COMMAND_WINDOWFRAME "WINDOWFRAME"
#define MMDAGENT_COMMAND_WINDOWFRAME_ADD "WINDOWFRAME_ADD"
#define MMDAGENT_COMMAND_WINDOWFRAME_DELETE "WINDOWFRAME_DELETE"
#define MMDAGENT_COMMAND_WINDOWFRAME_DELETEALL "WINDOWFRAME_DELETEALL"
#define MMDAGENT_COMMAND_LIGHTCOLOR "LIGHTCOLOR"
#define MMDAGENT_COMMAND_LIGHTDIRECTION "LIGHTDIRECTION"
#define MMDAGENT_COMMAND_LIPSYNCSTART "LIPSYNC_START"
Expand Down Expand Up @@ -181,6 +184,9 @@
#define MMDAGENT_EVENT_CAPTION_SETSTYLE "CAPTION_EVENT_SETSTYLE"
#define MMDAGENT_EVENT_CAPTION_START "CAPTION_EVENT_START"
#define MMDAGENT_EVENT_CAPTION_STOP "CAPTION_EVENT_STOP"
#define MMDAGENT_EVENT_WINDOWFRAME_ADD "WINDOWFRAME_EVENT_ADD"
#define MMDAGENT_EVENT_WINDOWFRAME_DELETE "WINDOWFRAME_EVENT_DELETE"


#define MMDAGENT_CURRENTTIME
#define MMDAGENT_TAPPED
Expand Down Expand Up @@ -442,6 +448,15 @@ class MMDAgent
/* setWindowFrame: set window frame */
bool setWindowFrame(const char *fileName);

/* addWindowFrame: add window frame */
bool addWindowFrame(const char *frameAlias, const char *fileName);

/* deleteWindowFrame: delete window frame */
bool deleteWindowFrame(const char *frameAlias);

/* deleteAllWindowFrame: delete all window frame */
bool deleteAllWindowFrame();

/* changeCamera: change camera setting */
bool changeCamera(const char *pos, const char *rot, const char *distance, const char *fovy, const char *time, const char *modelalias, const char *bonename);

Expand Down
31 changes: 23 additions & 8 deletions Library_MMDAgent/src/include/Stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
/* POSSIBILITY OF SUCH DAMAGE. */
/* ----------------------------------------------------------------- */

/* maximum number of frame textures */
#define MMDAGENT_STAGE_FRAME_TEXTURE_MAX 30

/* Stage: stage */
class Stage
{
Expand All @@ -69,12 +72,18 @@ class Stage
/* work area */
GLfloat m_floorShadow[4][4]; /* matrix for shadow of floor */

PMDTexture *m_frameTexture; /* window frame texture */
GLfloat m_frameVertices[12];
GLindices m_frameIndices[6];
GLfloat m_frameTexcoords[8];
float m_width;
float m_height;
/* frame texture */
struct FrameTexture {
PMDTexture *texture; // texture image
char *alias; // alias name
};
FrameTexture m_frameTextures[MMDAGENT_STAGE_FRAME_TEXTURE_MAX]; // list of frame textures
int m_frameTextureNum; // valid num of frame textures
GLfloat m_frameVertices[12]; // vertices to draw frame textures
GLindices m_frameIndices[6]; // indices to draw frame textures
GLfloat m_frameTexcoords[8]; // texture coordinates to draw frame textures
float m_width; // stored screen width
float m_height; // stored screen height

/* initialize: initialize stage */
void initialize();
Expand Down Expand Up @@ -126,8 +135,14 @@ class Stage
/* update: update */
void update(double ellapsedFrame);

/* loadFrameTexture: load frame texture */
bool loadFrameTexture(const char *file);
/* addFrameTexture: add frame texture */
bool addFrameTexture(const char *alias, const char *file);

/* deleteFrameTexture: delete frame texture */
bool deleteFrameTexture(const char *alias);

/* deleteAllFrameTexture: delete all frame texture */
bool deleteAllFrameTexture();

/* hasFrameTexture: return TRUE if has frame texture */
bool hasFrameTexture();
Expand Down
64 changes: 61 additions & 3 deletions Library_MMDAgent/src/lib/MMDAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,8 +1168,8 @@ bool MMDAgent::setWindowFrame(const char *fileName)
}
if (MMDAgent_strequal(fileName, "NONE")) {
/* delete window frame */
m_stage->loadFrameTexture(NULL);
} else if (m_stage->loadFrameTexture(fileName) == false) {
m_stage->deleteAllFrameTexture();
} else if (m_stage->addFrameTexture("__default", fileName) == false) {
sendLogString(m_moduleId, MLOG_ERROR, "setWindowFrame: failed to load: %s", fileName);
return false;
}
Expand All @@ -1178,6 +1178,40 @@ bool MMDAgent::setWindowFrame(const char *fileName)
return true;
}

/* MMDAgent::addWindowFrame: add window frame */
bool MMDAgent::addWindowFrame(const char *frameAlias, const char *fileName)
{
if (MMDAgent_exist(fileName) == false) {
sendLogString(m_moduleId, MLOG_ERROR, "addWindowFrame: %s: not found: %s", frameAlias, fileName);
return false;
}
if (m_stage->addFrameTexture(frameAlias, fileName) == false) {
sendLogString(m_moduleId, MLOG_ERROR, "addWindowFrame: %s: failed to load or exceeds limit: %s", frameAlias, fileName);
return false;
}
sendMessage(m_moduleId, MMDAGENT_EVENT_WINDOWFRAME_ADD, "%s", frameAlias);
return true;
}

/* MMDAgent::deleteWindowFrame: delete window frame */
bool MMDAgent::deleteWindowFrame(const char *frameAlias)
{
if (m_stage->deleteFrameTexture(frameAlias) == false) {
sendLogString(m_moduleId, MLOG_WARNING, "deleteWindowFrame: frame alias not exist: %s", frameAlias);
return false;
}
sendMessage(m_moduleId, MMDAGENT_EVENT_WINDOWFRAME_DELETE, "%s", frameAlias);
return true;
}

/* MMDAgent::deleteAllWindowFrame: delete all window frame */
bool MMDAgent::deleteAllWindowFrame()
{
m_stage->deleteAllFrameTexture();
/* don't send message */
return true;
}

/* MMDAgent::changeCamera: change camera setting */
bool MMDAgent::changeCamera(const char *posOrVMD, const char *rot, const char *distance, const char *fovy, const char *time, const char *modelAlias, const char *boneName)
{
Expand Down Expand Up @@ -5694,13 +5728,37 @@ void MMDAgent::procReceivedMessage(const char *type, const char *value)
}
free(buf);
} else if (MMDAgent_strequal(type, MMDAGENT_COMMAND_WINDOWFRAME)) {
/* change window frame */
/* change window frame (old) */
sendLogString(m_moduleId, MLOG_MESSAGE_CAPTURED, "%s|%s", type, value);
if (num != 1) {
sendLogString(m_moduleId, MLOG_ERROR, "%s: number of arguments should be 1.", type);
return;
}
setWindowFrame(value);
} else if (MMDAgent_strequal(type, MMDAGENT_COMMAND_WINDOWFRAME_ADD)) {
/* add or swap window frame */
sendLogString(m_moduleId, MLOG_MESSAGE_CAPTURED, "%s|%s", type, value);
if (num != 2) {
sendLogString(m_moduleId, MLOG_ERROR, "%s: number of arguments should be 2.", type);
return;
}
addWindowFrame(argv[0], argv[1]);
} else if (MMDAgent_strequal(type, MMDAGENT_COMMAND_WINDOWFRAME_DELETE)) {
/* delete window frame */
sendLogString(m_moduleId, MLOG_MESSAGE_CAPTURED, "%s|%s", type, value);
if (num != 1) {
sendLogString(m_moduleId, MLOG_ERROR, "%s: number of arguments should be 1.", type);
return;
}
deleteWindowFrame(argv[0]);
} else if (MMDAgent_strequal(type, MMDAGENT_COMMAND_WINDOWFRAME_DELETEALL)) {
/* delete window frame */
sendLogString(m_moduleId, MLOG_MESSAGE_CAPTURED, "%s|%s", type, value);
if (num != 0) {
sendLogString(m_moduleId, MLOG_ERROR, "%s: number of arguments should be 0.", type);
return;
}
deleteAllWindowFrame();
} else if (MMDAgent_strequal(type, MMDAGENT_COMMAND_CAMERA)) {
/* camera */
sendLogString(m_moduleId, MLOG_MESSAGE_CAPTURED, "%s|%s", type, value);
Expand Down
Loading

0 comments on commit f7f1778

Please sign in to comment.