Page 1 of 1

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

Posted: Sun Mar 07, 2021 3:54 pm
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!

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

Posted: Sun Mar 07, 2021 4:03 pm
by daniel
I don't think so sadly!

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

Posted: Fri Mar 19, 2021 2:27 pm
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?

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

Posted: Fri Mar 19, 2021 8:18 pm
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.

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

Posted: Mon Mar 22, 2021 1:53 pm
by arqubit
WargodHernandez, That would be great! I would appreciate it if you could point me in the right direction.

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

Posted: Mon Mar 29, 2021 10:13 pm
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