1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-29 14:00:49 +03:00

Compare commits

...

1 Commits

Author SHA1 Message Date
nds
ee333b42b9 0032325: Visualization - Possibility to use fixed positioned light source
- implementation for Positional light only.
2021-04-23 18:06:50 +03:00
7 changed files with 111 additions and 1 deletions

View File

@@ -248,6 +248,11 @@ void AIS_LightSource::updateLightTransformPersistence()
else
{
aTrsfPers.Nullify();
if (myLightSource->Is2DPers() && myLightSource->Type() == Graphic3d_TOLS_POSITIONAL)
{
aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER,
Graphic3d_Vec2i(myLightSource->Position().X(), myLightSource->Position().Y()));
}
}
break;
}
@@ -291,7 +296,10 @@ void AIS_LightSource::updateLightLocalTransformation()
if (myIsZoomable)
{
gp_Trsf aTrsf;
aTrsf.SetTranslation (gp::Origin(), myLightSource->Position());
if (!myLightSource->Is2DPers())
{
aTrsf.SetTranslation (gp::Origin(), myLightSource->Position());
}
myLocalTransformation = new TopLoc_Datum3D (aTrsf);
}
break;

View File

@@ -57,6 +57,7 @@ Graphic3d_CLight::Graphic3d_CLight (Graphic3d_TypeOfLightSource theType)
myType (theType),
myRevision (0),
myIsHeadlight(false),
myIs2DPers(false),
myIsEnabled (true),
myToCastShadows (false)
{
@@ -138,6 +139,19 @@ void Graphic3d_CLight::SetHeadlight (Standard_Boolean theValue)
myIsHeadlight = theValue;
}
// =======================================================================
// function : SetIs2DPers
// purpose :
// =======================================================================
void Graphic3d_CLight::SetIs2DPers (Standard_Boolean theValue)
{
if (myType == Graphic3d_TOLS_AMBIENT)
{
throw Standard_ProgramError ("Graphic3d_CLight::SetIs2DPers() is not applicable to ambient light");
}
myIs2DPers = theValue;
}
// =======================================================================
// function : SetDirection
// purpose :
@@ -322,5 +336,6 @@ void Graphic3d_CLight::DumpJson (Standard_OStream& theOStream, Standard_Integer
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myType)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myRevision)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsHeadlight)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIs2DPers)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsEnabled)
}

View File

@@ -75,6 +75,13 @@ public:
//! Setup headlight flag.
Standard_EXPORT void SetHeadlight (Standard_Boolean theValue);
//! Returns true if the light is positioned in 2D persistence; FALSE by default.
//! Headlight flag means that light position/direction are defined not in a World coordinate system, but relative to the camera orientation.
Standard_Boolean Is2DPers() const { return myIs2DPers; }
//! Setup 2D persistence for positioning light.
Standard_EXPORT void SetIs2DPers (Standard_Boolean theValue);
//! @name positional/spot light properties
public:
@@ -275,6 +282,7 @@ protected:
const Graphic3d_TypeOfLightSource myType; //!< Graphic3d_TypeOfLightSource enumeration
Standard_Size myRevision; //!< modification counter
Standard_Boolean myIsHeadlight; //!< flag to mark head light
Standard_Boolean myIs2DPers; //!< flag to mark head light position in 2D persistence
Standard_Boolean myIsEnabled; //!< enabled state
Standard_Boolean myToCastShadows;//!< casting shadows is requested

View File

@@ -354,6 +354,22 @@ void OpenGl_ShaderManager::UpdateWorldViewStateTo (const OpenGl_Mat4& theWorldVi
myWorldViewState.Update();
}
// =======================================================================
// function : convertTo2DPersPosition
// purpose :
// =======================================================================
gp_Pnt OpenGl_ShaderManager::convertTo2DPersPosition (const gp_Pnt& thePosition) const
{
OpenGl_Mat4 aProjMat = myContext->ProjectionState.Current();
OpenGl_Mat4 aModelMat = myContext->ModelWorldState.Current() * myContext->WorldViewState.Current();
Standard_ShortReal aX, anY, aZ;
Graphic3d_TransformUtils::UnProject<Standard_ShortReal> (thePosition.X(), thePosition.Y(), 0,
aModelMat, aProjMat, myContext->Viewport(),
aX, anY, aZ);
return gp_Pnt(aX, anY, aZ);
}
// =======================================================================
// function : pushLightSourceState
// purpose :
@@ -520,6 +536,15 @@ void OpenGl_ShaderManager::pushLightSourceState (const Handle(OpenGl_ShaderProgr
const Graphic3d_Mat4& anOrientInv = myWorldViewState.WorldViewMatrixInverse();
aLightParams.Position = anOrientInv * Graphic3d_Vec4 (aLightParams.Position.xyz(), 1.0f);
}
else if (aLight.Is2DPers())
{
gp_Pnt aPosition = convertTo2DPersPosition (aLight.Position());
aLightParams.Position.x() = static_cast<float>(aPosition.X());
aLightParams.Position.y() = static_cast<float>(aPosition.Y());
aLightParams.Position.z() = static_cast<float>(aPosition.Z());
aLightParams.Position.w() = 0.0f;
}
else
{
aLightParams.Position.x() = static_cast<float>(aLight.Position().X() - myLocalOrigin.X());

View File

@@ -273,6 +273,9 @@ public:
//! Invalidate state of OCCT light sources.
Standard_EXPORT void UpdateLightSourceState();
//! Converts position to 3D point in 2D pesistence.
gp_Pnt convertTo2DPersPosition (const gp_Pnt& thePosition) const;
//! Pushes current state of OCCT light sources to specified program (only on state change).
//! Note that light sources definition depends also on WorldViewState.
void PushLightSourceState (const Handle(OpenGl_ShaderProgram)& theProgram) const

View File

@@ -11044,6 +11044,24 @@ static int VLight (Draw_Interpretor& theDi,
}
aLightCurr->SetHeadlight (isHeadLight);
}
else if (anArgCase.IsEqual ("2DPERS") ||
anArgCase.IsEqual ("-2DPERS"))
{
if (aLightCurr.IsNull()
|| aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
{
Message::SendFail() << "Syntax error at argument '" << anArg << "'";
return 1;
}
Standard_Boolean is2DPers = Standard_False;
if (anArgIt + 1 < theArgsNb
&& Draw::ParseOnOff (theArgVec[anArgIt + 1], is2DPers))
{
++anArgIt;
}
aLightCurr->SetIs2DPers (is2DPers);
}
else if (anArgCase.IsEqual ("NAME")
|| anArgCase.IsEqual ("-NAME"))
{
@@ -15091,6 +15109,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
"\n -{dir}ection X Y Z (for directional light or for spotlight)"
"\n -color colorName"
"\n -{head}light 0|1"
"\n -2dpers 0|1"
"\n -castShadows 0|1"
"\n -{sm}oothness value"
"\n -{int}ensity value"

View File

@@ -0,0 +1,32 @@
puts "================================="
puts "0032325: Visualization - Possibility to use fixed positioned light source"
puts "================================="
pload MODELING VISUALIZATION
vclear
vinit View1
vlight -clear
vbackground -color GRAY
vrenderparams -shadingModel PHONG
vlight -add ambient -COLOR WHITE -intensity 0.1
box b 10 10 10 30 30 30
vdisplay b -dispMode 1
vaspects b -material Brass
vfit
puts "=== Check headlight option with positional light ==="
vlight -add positional -2dpers 1 -color WHITE -display Light1 -pos 30 20 0
vlight -add positional -2dpers 1 -color WHITE -display Light2 -pos 380 370 0
vlight -add positional -2dpers 1 -color WHITE -display Light3 -pos 30 380 0
vdump $imagedir/${casename}_1.png
vrotate 10 0 0
vdump $imagedir/${casename}_2.png
vpan -60 0
vdump $imagedir/${casename}_3.png