Pass MeshData to a node and modify the uv data


#1

Hi, I have some problem when i custom a new node

I storage uv to a json file, In a new file, I what to used the json file which storage the uv_data to assign the uv_data, but when i complete the node and used it, the Passed Geometry`s uv_data is loesing, when I debug it, the json value is exists.


this is the picture

MStatus TransferUVNode::compute( const MPlug& plug, MDataBlock& data )
{
	MStatus status;

	if( plug == m_output_mesh )
	{
		auto inputMeshDataHandler = data.inputValue(m_input_mesh );
		auto inputFilePathDataHandler = data.inputValue(m_input_file_path);
		auto inputAlembicNameDataHandler = data.inputValue(m_input_alembic_name);
		auto outputMeshDataHandle = data.outputValue(m_output_mesh);

		MObject in_mesh = inputMeshDataHandler.asMesh();
		MString file_path = inputFilePathDataHandler.asString();
		MString alembic_name = inputAlembicNameDataHandler.asString(); // storage transform name
		
		if (in_mesh.isNull() | 
			alembic_name == MString("") | 
			file_path == MString("") |
			!std::filesystem::exists(std::string(file_path.asChar())))
		{
			return MS::kSuccess;
		}


		json uv_json;
		std::ifstream(std::string(file_path.asChar())) >> uv_json;

		
		auto u_arr_list = uv_json[std::string(alembic_name.asChar())]["u_info"];
		auto v_arr_list = uv_json[std::string(alembic_name.asChar())]["v_info"];

		MFloatArray u_array;
		MFloatArray v_array;

		for (auto u_info : u_arr_list)
		{
			u_array.append(u_info);
		}
		for (auto v_info : v_arr_list)
		{
			v_array.append(v_info);
		}

		MIntArray assigned_uv_count;
		MIntArray assigned_uv_ids;

		auto uv_assigned_count_list = uv_json[std::string(alembic_name.asChar())]["assigned_uv_count"];
		auto uv_assigned_ids_list = uv_json[std::string(alembic_name.asChar())]["assigned_uv_ids"];
		
		for (auto data : uv_assigned_count_list)
		{
			u_array.append(data);
		}
		for (auto ids : uv_assigned_ids_list)
		{
			v_array.append(ids);
		}


		MFnMeshData dataCreator;
		MObject outMeshData = dataCreator.create();

		MFnMesh mesh_fn;
		mesh_fn.copy(in_mesh);

		
		CHECK_MSTATUS_AND_RETURN_IT(mesh_fn.clearUVs());
		CHECK_MSTATUS_AND_RETURN_IT(mesh_fn.setUVs(u_array, v_array));
		CHECK_MSTATUS_AND_RETURN_IT(mesh_fn.assignUVs(assigned_uv_count, assigned_uv_ids));

		mesh_fn.updateSurface();
		outputMeshDataHandle.set(mesh_fn.object());

		data.setClean(plug);
	}
	else 
	{
		return MS::kUnknownParameter;
	}

	return MS::kSuccess;
}