<Edit> <Mesh> <ConvertTexture / Material to RGB in Command Line?

Feel free to ask any question here
Post Reply
arqubit
Posts: 3
Joined: Sun Mar 07, 2021 3:43 pm

<Edit> <Mesh> <ConvertTexture / Material to RGB in Command Line?

Post by arqubit »

Is there a way to automate the command in the title? <Edit> <Mesh> <ConvertTexture / Material to RGB. I didn't see it as an option in the Command Line interface, but I am pretty new to that sort of thing.

Thanks,

CC is an amazing piece of software. Thanks!
daniel
Site Admin
Posts: 7717
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: <Edit> <Mesh> <ConvertTexture / Material to RGB in Command Line?

Post by daniel »

I don't think so sadly!
Daniel, CloudCompare admin
arqubit
Posts: 3
Joined: Sun Mar 07, 2021 3:43 pm

Re: <Edit> <Mesh> <ConvertTexture / Material to RGB in Command Line?

Post by arqubit »

Thank you for your reply! Is it possible to create a plugin based on the original menu code (i.e. <Edit><Mesh><ConvertTexture> and then load that as a plugin and call the plugin from the command line? How difficult is that?
WargodHernandez
Posts: 187
Joined: Tue Mar 05, 2019 3:59 pm

Re: <Edit> <Mesh> <ConvertTexture / Material to RGB in Command Line?

Post by WargodHernandez »

it would make more sense to just add the tool to the standard command line in CC if you have some C++ experience or want to learn I can provide some example info to help get it going.
arqubit
Posts: 3
Joined: Sun Mar 07, 2021 3:43 pm

Re: <Edit> <Mesh> <ConvertTexture / Material to RGB in Command Line?

Post by arqubit »

WargodHernandez, That would be great! I would appreciate it if you could point me in the right direction.
WargodHernandez
Posts: 187
Joined: Tue Mar 05, 2019 3:59 pm

Re: <Edit> <Mesh> <ConvertTexture / Material to RGB in Command Line?

Post by WargodHernandez »

Sorry for the delay, I missed this reply,


The action you will want to call is located here:
ccEntityAction::convertTextureToColor
This is a super easy function to call just pass the commandline Mesh group to it


Here is one example command to examine to understand the requirements, this converts Normals to Dip and Dip Dir, just copy the two functions changing names and relevant content

You'll need to create a command string, here is the Normals to dip dir

Code: Select all

constexpr char COMMAND_CONVERT_NORMALS_TO_DIP[]			= "NORMALS_TO_DIP";
I would change it to something like:

Code: Select all

constexpr char COMMAND_CONVERT_TEXTURE_TO_RGB[]			= "TEXTURE_TO_RGB";
and place it somewhere in the list of commands in ccCommandLineCommands.cpp

Here are the two main functions to modify:

Code: Select all

CommandConvertNormalsToDipAndDipDir::CommandConvertNormalsToDipAndDipDir()
	: ccCommandLineInterface::Command(QObject::tr("Convert normals to dip and dip. dir."), COMMAND_CONVERT_NORMALS_TO_DIP)
{}

bool CommandConvertNormalsToDipAndDipDir::process(ccCommandLineInterface &cmd)
{
	cmd.print(QObject::tr("[CONVERT NORMALS TO DIP/DIP DIR]"));
	if (cmd.clouds().empty())
	{
		return cmd.error(QObject::tr("No input point cloud (be sure to open one with \"-%1 [cloud filename]\" before \"-%2\")").arg(COMMAND_OPEN, COMMAND_CONVERT_NORMALS_TO_DIP));
	}

	for (CLCloudDesc& thisCloudDesc : cmd.clouds())
	{
		ccPointCloud* cloud = thisCloudDesc.pc;

		if (!cloud->hasNormals())
		{
			cmd.warning(QObject::tr("Cloud %1 has no normals").arg(cloud->getName()));
			continue;
		}

		ccHObject::Container container;
		container.push_back(cloud);
		if (!ccEntityAction::convertNormalsTo(container, ccEntityAction::NORMAL_CONVERSION_DEST::DIP_DIR_SFS))
		{
			return cmd.error(QObject::tr("Failed to convert normals to dip and dip direction"));
		}

		if (cmd.autoSaveMode())
		{
			QString errorStr = cmd.exportEntity(thisCloudDesc, "_DIP_AND_DIP_DIR");
			if (!errorStr.isEmpty())
			{
				return cmd.error(errorStr);
			}
		}
	}

	return true;
}
Add these two functions (but changed for the command you want to implement) to ccCommandLineCommands.cpp

And then copy and modify the following:

Code: Select all

struct CommandConvertNormalsToDipAndDipDir : public ccCommandLineInterface::Command
{
	CommandConvertNormalsToDipAndDipDir();

	bool process(ccCommandLineInterface& cmd) override;
};
Add a command struct like this (but changed for the command you want to implement) to ccCommandLineCommands.h
Post Reply