@@ -55,7 +55,7 @@ namespace
5555
5656Model::Model () : CubismUserModel(), _modelSetting(nullptr ), _matrixManager(),
5757 _parameterCount(0 ), _parameterDefaultValues(nullptr ), _parameterValues(nullptr ),
58- _tmpOrderedDrawIndice(nullptr ), _expFadeOutTimeMillis( 0 ), _defaultExpressionId( " " )
58+ _tmpOrderedDrawIndice(nullptr )
5959{
6060 _mocConsistency = true ;
6161
@@ -110,7 +110,7 @@ void Model::Update(float deltaSecs)
110110 _model->LoadParameters ();
111111 if (!_motionManager->IsFinished ())
112112 {
113- motionUpdated = _motionManager->UpdateMotion (_model, deltaSecs);
113+ motionUpdated = _motionManager->UpdateMotion (_model, deltaSecs);
114114 }
115115 _model->SaveParameters ();
116116
@@ -191,12 +191,19 @@ void Model::SetupModel()
191191 ACubismMotion *motion = LoadExpression (buffer, size, name.GetRawString ());
192192 if (motion)
193193 {
194+ std::string key = name.GetRawString ();
194195 if (_expressions[name] != nullptr )
195196 {
196197 ACubismMotion::Delete (_expressions[name]);
197198 _expressions[name] = nullptr ;
198199 }
200+ if (_expManagers[key] != nullptr )
201+ {
202+ CSM_DELETE (_expManagers[key]);
203+ _expManagers.erase (key);
204+ }
199205 _expressions[name] = motion;
206+ _expManagers[key] = CSM_NEW CubismExpressionMotionManager ();
200207 }
201208 });
202209 }
@@ -326,8 +333,8 @@ bool Model::IsHit(CubismIdHandle drawableId, csmFloat32 pointX, csmFloat32 point
326333 return false ; // 存在しない場合はfalse
327334 }
328335
329- const csmInt32 count = _model->GetDrawableVertexCount (drawIndex);
330- const csmFloat32* vertices = _model->GetDrawableVertices (drawIndex);
336+ const csmInt32 count = _model->GetDrawableVertexCount (drawIndex);
337+ const csmFloat32 * vertices = _model->GetDrawableVertices (drawIndex);
331338
332339 csmFloat32 left = vertices[0 ];
333340 csmFloat32 right = vertices[0 ];
@@ -405,26 +412,17 @@ void Model::UpdateBlink(float deltaSecs)
405412
406413void Model::UpdateExpression (float deltaSecs)
407414{
408- if (_expFadeOutTimeMillis > 0 )
415+ if (_expressionManager-> IsFinished () )
409416 {
410- _expFadeOutTimeMillis -= deltaSecs * 1000 ;
411- if (_expFadeOutTimeMillis <= 0 )
417+ for (auto &pair : _expManagers)
412418 {
413- if (_defaultExpressionId.empty ())
414- {
415- _expressionManager->StopAllMotions ();
416- Info (" reset expression" );
417- }
418- else
419- {
420- SetExpression (_defaultExpressionId.c_str ());
421- Info (" reset expression: %s" , _defaultExpressionId.c_str ());
422- }
423- _expFadeOutTimeMillis = 0 ;
419+ pair.second ->UpdateMotion (_model, deltaSecs);
424420 }
425421 }
426-
427- _expressionManager->UpdateMotion (_model, deltaSecs);
422+ else
423+ {
424+ _expressionManager->UpdateMotion (_model, deltaSecs);
425+ }
428426}
429427
430428void Model::UpdatePhysics (float deltaSecs)
@@ -730,7 +728,7 @@ int Model::GetMotionCount(const char *group)
730728 return _modelSetting->GetMotionCount (group);
731729}
732730
733- void Model::GetMotions (void *collector, void (*collect)(void *collector, const char *group, int no, const char *file, const char * sound))
731+ void Model::GetMotions (void *collector, void (*collect)(void *collector, const char *group, int no, const char *file, const char * sound))
734732{
735733 const int count = _modelSetting->GetMotionGroupCount ();
736734 for (int i = 0 ; i < count; i++)
@@ -1107,39 +1105,50 @@ const unsigned short *Model::GetDrawableIndices(int index)
11071105 return _model->GetDrawableVertexIndices (index);
11081106}
11091107
1110- void Model::SetExpression (const char *expressionId)
1108+ void Model::AddExpression (const char *expressionId)
11111109{
11121110 ACubismMotion *motion = _expressions[expressionId];
11131111
11141112 Info (" expression: [%s]" , expressionId);
11151113
11161114 if (motion != nullptr )
11171115 {
1118- _expressionManager ->StartMotion (motion, false );
1116+ _expManagers[expressionId] ->StartMotion (motion, false );
11191117 }
11201118 else
11211119 {
11221120 Info (" expression[%s] is null " , expressionId);
11231121 }
11241122}
11251123
1126- int Model::GetExpressionCount ( )
1124+ void Model::RemoveExpression ( const char *expressionId )
11271125{
1128- return _modelSetting->GetExpressionCount ();
1126+ if (_expManagers.find (expressionId) == _expManagers.end ())
1127+ {
1128+ return ;
1129+ }
1130+ _expManagers[expressionId]->StopAllMotions ();
1131+
1132+ Info (" reset expression: [%s]" , expressionId);
11291133}
11301134
1131- void Model::GetExpressions ( void *collector, void (*collect)( void *collector, const char *id, const char *file) )
1135+ void Model::SetExpression ( const char *expressionId )
11321136{
1133- const int count = _modelSetting->GetExpressionCount ();
1134- for (int i = 0 ; i < count; i++)
1137+ ACubismMotion *motion = _expressions[expressionId];
1138+
1139+ Info (" expression: [%s]" , expressionId);
1140+
1141+ if (motion != nullptr )
11351142 {
1136- const char *file = _modelSetting->GetExpressionFileName (i);
1137- const char *id = _modelSetting->GetExpressionName (i);
1138- collect (collector, id, file);
1143+ _expressionManager->StartMotion (motion, false );
1144+ }
1145+ else
1146+ {
1147+ Info (" expression[%s] is null " , expressionId);
11391148 }
11401149}
11411150
1142- const char * Model::SetRandomExpression ()
1151+ const char * Model::SetRandomExpression ()
11431152{
11441153 const int size = _expressions.GetSize ();
11451154 if (size == 0 )
@@ -1162,34 +1171,36 @@ const char *Model::SetRandomExpression()
11621171 return nullptr ;
11631172}
11641173
1165- void Model::ResetExpression ()
1174+ void Model::ResetExpressions ()
11661175{
1176+ for (auto & [id, expMgr] : _expManagers)
1177+ {
1178+ expMgr->StopAllMotions ();
1179+ }
11671180 _expressionManager->StopAllMotions ();
1181+
1182+ Info (" reset expressions" );
11681183}
11691184
1170- void Model::SetDefaultExpression ( const char *expressionId )
1185+ void Model::ResetExpression ( )
11711186{
1172- if (expressionId != nullptr || _expressions.IsExist (expressionId))
1173- {
1174- _defaultExpressionId = expressionId;
1175- Info (" set default expression: [%s]" , expressionId);
1176- }
1177- else
1178- {
1179- Info (" expression[%s] does not exist" , expressionId);
1180- }
1187+ _expressionManager->StopAllMotions ();
1188+ }
1189+
1190+ int Model::GetExpressionCount ()
1191+ {
1192+ return _modelSetting->GetExpressionCount ();
11811193}
11821194
1183- void Model::SetFadeOutExpression ( const char *expressionId, double fadeOutTime )
1195+ void Model::GetExpressions ( void *collector, void (*collect)( void *collector, const char *id, const char *file) )
11841196{
1185- if (fadeOutTime < 0 )
1197+ const int count = _modelSetting->GetExpressionCount ();
1198+ for (int i = 0 ; i < count; i++)
11861199 {
1187- Info (" fadeOutTime[%f] is invalid" , fadeOutTime);
1188- return ;
1200+ const char *file = _modelSetting->GetExpressionFileName (i);
1201+ const char *id = _modelSetting->GetExpressionName (i);
1202+ collect (collector, id, file);
11891203 }
1190-
1191- SetExpression (expressionId);
1192- _expFadeOutTimeMillis = fadeOutTime;
11931204}
11941205
11951206void Model::StopAllMotions ()
@@ -1214,6 +1225,23 @@ void Model::ResetPose()
12141225 }
12151226}
12161227
1228+ void Model::GetCanvasSize (float &w, float &h)
1229+ {
1230+ w = _model->GetCanvasWidth ();
1231+ h = _model->GetCanvasHeight ();
1232+ }
1233+
1234+ void Model::GetCanvasSizePixel (float &w, float &h)
1235+ {
1236+ w = _model->GetCanvasWidthPixel ();
1237+ h = _model->GetCanvasHeightPixel ();
1238+ }
1239+
1240+ float Model::GetPixelsPerUnit ()
1241+ {
1242+ return _model->GetPixelsPerUnit ();
1243+ }
1244+
12171245void Model::ReleaseMotions ()
12181246{
12191247 for (csmMap<csmString, ACubismMotion *>::const_iterator iter = _motions.Begin (); iter != _motions.End (); ++iter)
0 commit comments