Jump to content

[SOLVED] Best way to turn off/on all the "Projected lights" at the same time


photo

Recommended Posts

Hi,
I've a scene with several projected lights ( around 100+ ) of them, and I would like like to turn off/on all off them at the same time.
All the lights actually are nodes with name starting with LightProj, so my initial idea was try to create a collection of all of them at Init time, and then by pressing a key or based on returned rotation SUN Y angle, turn them off or on.
Looking at the NODE documentation I found how to select exact note by perfect name matching ( World::getNodeByName("sun"); that I use to get and set sun rotation) but not a good example to filter all the objects with the same "prefix", and how to cycle them.
But thinking at this initial idea, maybe there are "smarter" solution like put all that lights in a dedicated viewport mask, and then disable that one? Probably it will have less impact on performance since doesn't have to cycle between all the node to disable them.

What are your thoughts?
 

LightProj.PNG

Edited by andrea.padovani
Link to comment

Pretty sure is not the best way, but following there is an example that is working on our target system, so I can also leave like this for my use case:
 

	int lamps = 0;
	Unigine::Vector<Unigine::NodePtr> nodes;
	Unigine::World::getNodes(nodes);


	for (int i = 0; i < nodes.size(); i++)
	{
		auto thisName = nodes[i]->getName();
		std::string tmp_string(thisName);
		if (tmp_string.rfind("LightProj", 0) == 0 ) {
			std::string logMsg = "node name: " + tmp_string + "\n";
			const char* logMsgChar = logMsg.c_str();
			Log::message(logMsgChar);
			nodes[i]->setEnabled(false);
			lamps++;
		}
	}

I'm doing this at Init time, to avoid "lag spikes" during change ( it will not happen really often by the way ) maybe I can create another set of nodes, containing only my "lamps" ( LightProj* ) and at run time cycle only trough that subset, instead all nodes.

 

Link to comment

yes this is one of the simplest solutions.

init: collect all the LightProj to vector.
update: go through vector and turn on/off each of them. 

however, I wanted to advise or rename the spotlights some other name. because LightProj** is the default name. this can lead to further confusion as you have more projectors.
or create and add a property to mark the lights to be turned off / on.

  • Thanks 1
Link to comment
15 hours ago, cash-metall said:

yes this is one of the simplest solutions.

init: collect all the LightProj to vector.
update: go through vector and turn on/off each of them. 

however, I wanted to advise or rename the spotlights some other name. because LightProj** is the default name. this can lead to further confusion as you have more projectors.
or create and add a property to mark the lights to be turned off / on.

Thanks for suggestion, currently the scene is full of lights, and my bad was not change the name on the first object before copy it all over the scene.
Based on my current needing it's not a problem, when I need to use this function is really that I need to turn off all that kind of lights.

On top of that also, in order to "optimize" a little bit the code, I'm not using anymore the entire world node collection and checking it's name, but I'm using the recently introduced getNodesByType function.

So basically I'm cycling between a really smaller collection rather than the previous one, and also not going to make any comparison between the names.

Edited by andrea.padovani
Link to comment
  • silent changed the title to [SOLVED] Best way to turn off/on all the "Projected lights" at the same time
×
×
  • Create New...