Removing distant lights

How do I remove a distant light?

A call to InsertDistantLight returns a DistantLightKey instance but later calling instance.Delete() (and/or instance.Dispose()) does not remove the distant light - the lighting of my geometry does not change.

In fact, further calls to InsertDistantLight seem to add more and more distant lights, brightening the scene towards saturation, hinting that the Delete/Dispose had no effect.

Check the usage of the SetMainDistantLight() in CHPSView.cpp of the MFC Sandbox.

void CHPSView::SetMainDistantLight(HPS::DistantLightKit const & light)
{
	// Delete previous light before inserting new one
	if (_mainDistantLight.Type() != HPS::Type::None)
		_mainDistantLight.Delete();
	_mainDistantLight = GetCanvas().GetFrontView().GetSegmentKey().InsertDistantLight(light);
}

Mike

Thanks!

On a related note of lighting of the axis triad by distant lights:

The lefthand triad is lit by the distant light. When the distant light is removed, lighting for the triad has gone (as on the righthand triad)!

I’ve enabled the triad via the standard:

Canvas.
GetFrontView().
GetAxisTriadControl().
SetVisibility(true).
SetLocation(AxisTriadControl.Location.BottomRight);

I wonder if this is a subwindow issue? The doc here ( Subwindows — HOOPS Visualize HPS Documentation ) hints at putting the triad in a subwindow (I presume that’s what the AxisTriadControl does) but does not show how to use this idea in conjunction with Canvas.GetFrontView().GetAxisTriadControl()… so I’m stuck on how to implement this (and whether it would fix the triad lighting issue anyway!)

(Note)
Canvas.
GetFrontView().
GetAxisTriadControl().
SetVisibility(true).
SetLocation(AxisTriadControl.Location.BottomRight).
GetSegmentKey().
InsertDistantLight(new Vector(0, 0, 1));

Adding a distant light to the triad segment affects the lighting of the overall scene, so maybe the triad subwindow is lightweight? According to the subwindow docs:

Lightweight Subwindow Features and Limitations

  • Uses less resources than standard subwindow

  • Cannot be nested

  • Lights positioned in lightweight subwindows will affect geometry in the parent window

  • Background is always transparent

  • Selection events pass through

Paul,

A distant light is typically added to the scene hierarchy under the view. You can see this by examining the segment browser. The light “illuminates all geometry in the same scene, irrespective of its location in the segment tree.”

The axis triad is automatically created within a lightweight subwindow.

The rendering impact of deleting the distant light on the axis triad is expected and the same for other geometry in the scene.

The exception mentioned in Lights — HOOPS Visualize HPS Documentation should read,

The only exception is with standard subwindows - lights do not affect geometry in a standard subwindow.

I hope this helps.

Mike

Thanks, Mike.

So am I correct to say, in summary there is no way to illuminate using distant lights the triad independently of the model because:

a) adding/removing a distant light to the model segment affects the lighting of the triad segment

b) and adding/removing a distant light to the triad segment affects the lighting of the model segment

I have a use-case where the model needs to be unlit (for a particular rendering effect) but the triad should remain lit (for UX consistency). Do you have any thoughts on how to achieve this?

Paul,

Yes, regarding (a) & (b) lights apply to all geometry everywhere within the standard subwindow. This means everything under the model and the triad segment as they are both in the same subwindow (defined at the root level). The triad is in a lightweight subwindow.

You can achieve lighting independence as you describe but changing the traid subwindow to a standard subwindow and adding a distant light.

You can add the following to try this in the MFC Sandbox (i.e. CHPSView.cpp).

void CHPSView::OnUserCode2()
{
	// enable axis triad
	_canvas.GetFrontView().GetAxisTriadControl().SetVisibility(true).SetLocation(HPS::AxisTriadControl::Location::BottomRight);
	Update();
}

void CHPSView::OnUserCode3()
{
	// get the axis triad segment key
	HPS::SegmentKey triadKey = _canvas.GetFrontView().GetAxisTriadControl().GetSegmentKey();
	if (triadKey.Type() != HPS::Type::None)
	{
		HPS::Rectangle position;
		HPS::IntRectangle offsets;
		HPS::Subwindow::Type type;

		// Change the subwindow type to standard
		triadKey.GetSubwindowControl().ShowSubwindow(position, offsets, type);
		triadKey.GetSubwindowControl().
			SetBackground(HPS::Subwindow::Background::Transparent).
			SetSubwindow(position, offsets, HPS::Subwindow::Type::Standard);
		// duplicate the existing distant light within this subwindow
		if (_mainDistantLight.Type() != HPS::Type::None)
		{
			HPS::DistantLightKit light;
			HPS::Vector dir;
			bool relative = true;
			_mainDistantLight.ShowDirection(dir);
			_mainDistantLight.ShowCameraRelative(relative);
			light.SetDirection(dir);
			light.SetCameraRelative(relative);
			triadKey.InsertDistantLight(light);
		}
		// else insert some distant light

		// adjust the text size for the new subwindow
		HPS::SegmentKey xAxisKey = triadKey.Subsegment("x", false);
		HPS::SegmentKey yAxisKey = triadKey.Subsegment("y", false);
		HPS::SegmentKey zAxisKey = triadKey.Subsegment("z", false);
		HPS::TextAttributeKit textAttKit;
		xAxisKey.ShowTextAttribute(textAttKit);
		float size;
		HPS::Text::SizeUnits units;
		textAttKit.ShowSize(size, units);
		textAttKit.SetSize(size * 5, units);
		if (xAxisKey.Type() != HPS::Type::None)
		{
			xAxisKey.SetTextAttribute(textAttKit);
		}
		if (yAxisKey.Type() != HPS::Type::None)
		{
			yAxisKey.SetTextAttribute(textAttKit);
		}
		if (zAxisKey.Type() != HPS::Type::None)
		{
			zAxisKey.SetTextAttribute(textAttKit);
		}
	}
	else
		TRACE("missed triad key\n");

	Update();
}

After loading a model, choosing User Code 2 and then 3 and then deleting the distant light under the view, the rendering of the model does not have a distant light but the axis triad still has its own distant light.

Mike

1 Like