Hello,
I need to write morph data into a polygon object.
I use the following code, but there is a problem with the imported data and the morph tag cache is large.
How can I import morph data?
//Initialization morph tag.
CAPoseMorphTag* morph_tag = CAPoseMorphTag::Alloc();
if (morph_tag == nullptr)
{
GePrint(GeLoadString(IDS_MES_IMPORT_ERR) + GeLoadString(IDS_MES_MEM_ERR));
MessageDialog(GeLoadString(IDS_MES_IMPORT_ERR) + GeLoadString(IDS_MES_MEM_ERR));
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION, GeLoadString(IDS_MES_IMPORT_ERR) + GeLoadString(IDS_MES_MEM_ERR));
}
model->InsertTag(morph_tag);
morph_tag->InitMorphs();
//Add base morph to the tag.
morph_tag->SetParameter(ID_CA_POSE_POINTS, true, DESCFLAGS_SET::NONE);
morph_tag->ExitEdit(doc, true);
CAMorph* base_morph = morph_tag->AddMorph();
if (base_morph == nullptr)
{
GePrint(GeLoadString(IDS_MES_IMPORT_ERR) + GeLoadString(IDS_MES_MEM_ERR));
MessageDialog(GeLoadString(IDS_MES_IMPORT_ERR) + GeLoadString(IDS_MES_MEM_ERR));
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION, GeLoadString(IDS_MES_IMPORT_ERR) + GeLoadString(IDS_MES_MEM_ERR));
}
base_morph->Store(doc, morph_tag, CAMORPH_DATA_FLAGS::POINTS);
morph_tag->UpdateMorphs();
EventAdd();
//Get the morph data count.
Int32 morph_data_count = pmx_model->model_data_count.morph_data_count;
for (Int32 i = 0; i < morph_data_count; i++)
{
StatusSetText("Import morphs..."_s);
StatusSetBar(i * 100 / morph_data_count);
PMX_Morph_Data* morph_data = pmx_model->morph_data[i];
if (morph_data->morph_type == 1) {
CAMorph* morph = morph_tag->AddMorph();
if (morph == nullptr)
{
GePrint(GeLoadString(IDS_MES_IMPORT_ERR) + GeLoadString(IDS_MES_MEM_ERR));
MessageDialog(GeLoadString(IDS_MES_IMPORT_ERR) + GeLoadString(IDS_MES_MEM_ERR));
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION, GeLoadString(IDS_MES_IMPORT_ERR) + GeLoadString(IDS_MES_MEM_ERR));
}
maxon::PointerArray<PMX_Morph_vertex>* vertex_morph_data_arr = (maxon::PointerArray<PMX_Morph_vertex>*)morph_data->offset_data;
morph_tag->ExitEdit(doc, true);
Int32 offset_count = morph_data->offset_count;
//Set the position of the deformed point.
for (Int32 j = 0; j < offset_count; j++)
{
//This structure records the index of the point and the displacement of the point.
PMX_Morph_vertex vertex_morph_data = (*vertex_morph_data_arr)[j];
//Move the point.
//"vertex_morph_data.vertex_index"(UInt32) is index of the point.
//"vertex_morph_data.translation"(vec3) is displacement of the point.
//The parameter "PositionMultiple"(Float32) is used to set the displacement scaling.
//"model_point_obj"(Vector[]) is the point write handle of the model.
model_points[vertex_morph_data.vertex_index] += vertex_morph_data.translation * PositionMultiple;
}
//Update point data.
model_point_obj->Message(MSG_UPDATE);
morph->Store(doc, morph_tag, CAMORPH_DATA_FLAGS::POINTS);
morph_tag->UpdateMorphs();
EventAdd();
morph->SetName(morph_data->morph_name_local);
morph->SetStrength(0);
//The position of the recovery point is the initial.
for (Int32 j = 0; j < offset_count; j++)
{
PMX_Morph_vertex vertex_morph_data = (*vertex_morph_data_arr)[j];
model_points[vertex_morph_data.vertex_index] = pmx_model->vertex_data[vertex_morph_data.vertex_index]->position * PositionMultiple;
}
model_point_obj->Message(MSG_UPDATE);
}
}
//Set "ID_CA_POSE_MODE" parameter to animation.
morph_tag->SetParameter(DescID(ID_CA_POSE_MODE), ID_CA_POSE_MODE_ANIMATE, DESCFLAGS_SET::NONE);
Thank,
AiMiDi