3535#include " renderInstance/renderProbeMgr.h"
3636#include " T3D/lighting/skylight.h"
3737#include " gfx/gfxDrawUtil.h"
38+ #include " math/mathUtils.h"
39+ #include " T3D/groundPlane.h"
3840
3941// GuiMaterialPreview
4042GuiMaterialPreview::GuiMaterialPreview ()
4143: mMouseState(None),
4244 runThread(0 ),
4345 lastRenderTime(0 ),
4446 mLastMousePoint(0 , 0 ),
45- mFakeSun(NULL ),
4647 mMaxOrbitDist(5 .0f ),
4748 mMinOrbitDist(0 .0f ),
4849 mOrbitDist(5 .0f )
4950{
5051 mActive = true ;
5152 mCameraMatrix .identity ();
52- mCameraRot .set ( mDegToRad (30 .0f ), 0 , mDegToRad (-30 .0f ) );
53+ mCameraRot .set (mDegToRad (3 .0f ), 0 , mDegToRad (-30 .0f ) );
5354 mCameraPos .set (0 .0f , 1 .75f , 1 .25f );
5455 mCameraMatrix .setColumn (3 , mCameraPos );
5556 mOrbitPos .set (0 .0f , 0 .0f , 0 .0f );
5657 mTransStep = 0 .01f ;
5758 mTranMult = 4.0 ;
58- mLightTransStep = 0 .01f ;
59+ mLightTransStep = 0 .5f ;
5960 mLightTranMult = 4.0 ;
6061 mOrbitRelPos = Point3F (0 ,0 ,0 );
6162
@@ -69,19 +70,22 @@ GuiMaterialPreview::GuiMaterialPreview()
6970 mTempScene ->setFogData (FogData ());
7071
7172 ScopedSceneManager scopeManager (mTempScene );
72- mBGSky = new SkySphere ();
73- mBGSky ->_setMaterial (" Prototyping:hdrMaterial" );
74- mBGSky ->registerObject ();
73+ mRealSun = new Sun ();
74+ mRealSun ->setField (" brightness" , " 2.0" );
75+ mRealSun ->setAzimuth (100 .0f );
76+ mRealSun ->registerObject ();
77+
78+ GroundPlane* plane = new GroundPlane ();
79+ plane->_setMaterial (" ToolsModule:GreyPreview" );
80+ plane->registerObject ();
7581
7682 mTSShape = new TSStatic ();
7783}
7884
7985GuiMaterialPreview::~GuiMaterialPreview ()
8086{
81- SAFE_DELETE (mFakeSun );
82-
83- mBGSky ->unregisterObject ();
84- SAFE_DELETE (mBGSky );
87+ mRealSun ->unregisterObject ();
88+ SAFE_DELETE (mRealSun );
8589
8690 if (mTSShape != NULL )
8791 deleteModel ();
@@ -94,14 +98,8 @@ bool GuiMaterialPreview::onWake()
9498 if ( !Parent::onWake () )
9599 return false ;
96100
97- if (!mFakeSun )
98- mFakeSun = LightManager::createLightInfo ();
99-
100- mFakeSun ->setColor ( LinearColorF ( 1 .0f , 1 .0f , 1 .0f ) );
101- mFakeSun ->setAmbient ( LinearColorF ( 0 .5f , 0 .5f , 0 .5f ) );
102- mFakeSun ->setDirection ( VectorF ( 0 .0f , 0 .707f , -0 .707f ) );
103- mFakeSun ->setPosition ( mFakeSun ->getDirection () * -10000 .0f );
104- mFakeSun ->setRange ( 2000000 .0f );
101+ mRealSun ->setColor ( LinearColorF ( 1 .0f , 1 .0f , 1 .0f ) );
102+ mRealSun ->setAmbientColor ( LinearColorF ( 0 .5f , 0 .5f , 0 .5f ) );
105103
106104 return true ;
107105}
@@ -111,15 +109,15 @@ void GuiMaterialPreview::setAmbientLightColor( F32 r, F32 g, F32 b )
111109{
112110 LinearColorF temp (r, g, b);
113111 temp.clamp ();
114- GuiMaterialPreview:: mFakeSun -> setAmbient ( temp );
112+ mRealSun -> setAmbientColor ( temp );
115113}
116114
117115// This function allows the light's color to be changed. This is exposed to script below.
118116void GuiMaterialPreview::setLightColor ( F32 r, F32 g, F32 b )
119117{
120118 LinearColorF temp (r, g, b);
121119 temp.clamp ();
122- GuiMaterialPreview:: mFakeSun ->setColor ( temp );
120+ mRealSun ->setColor ( temp );
123121}
124122
125123// This function is for moving the light in the scene. This needs to be adjusted to keep the light
@@ -129,21 +127,16 @@ void GuiMaterialPreview::setLightTranslate(S32 modifier, F32 xstep, F32 ystep)
129127{
130128 F32 _lighttransstep = (modifier & SI_SHIFT ? mLightTransStep : (mLightTransStep *mLightTranMult ));
131129
132- Point3F relativeLightDirection = GuiMaterialPreview::mFakeSun ->getDirection ();
133-
134- F32 azimuth = mAtan2 (relativeLightDirection.y , relativeLightDirection.x );
135- F32 elevation = mAsin (relativeLightDirection.z );
130+ // Convert current direction to spherical coordinates (azimuth and elevation in radians)
131+ F32 azimuth = mRealSun ->getAzimuth ();
132+ F32 elevation = mRealSun ->getElevation ();
136133
137134 // Modify azimuth and elevation based on input
138- azimuth + = xstep * _lighttransstep;
139- elevation = mClampF ( elevation + ystep * _lighttransstep, -M_2PI_F, M_2PI_F) ;
135+ azimuth - = xstep * _lighttransstep; // Horizontal movement affects azimuth
136+ elevation = elevation - ystep * _lighttransstep;
140137
141- // Convert back to Cartesian coordinates
142- relativeLightDirection.x = mCos (elevation) * mCos (azimuth);
143- relativeLightDirection.y = mCos (elevation) * mSin (azimuth);
144- relativeLightDirection.z = mSin (elevation);
145-
146- GuiMaterialPreview::mFakeSun ->setDirection (relativeLightDirection);
138+ // Update azimuth and elevation on the sun object
139+ mRealSun ->setDirection (azimuth, elevation);
147140}
148141
149142// Left Click
@@ -171,9 +164,9 @@ void GuiMaterialPreview::onMouseDragged(const GuiEvent &event)
171164 // If we are MovingLight...
172165 else
173166 {
174- Point2I delta = event.mousePoint - mLastMousePoint ;
175- mLastMousePoint = event.mousePoint ;
176- setLightTranslate (event.modifier , delta.x , delta.y );
167+ Point2I delta = event.mousePoint - mLastMousePoint ;
168+ mLastMousePoint = event.mousePoint ;
169+ setLightTranslate (event.modifier , delta.x , delta.y );
177170 }
178171}
179172
@@ -227,11 +220,13 @@ void GuiMaterialPreview::setObjectModel(const char* modelName)
227220 if (!mTSShape ->isProperlyAdded ())
228221 {
229222 ScopedSceneManager scopeManager (mTempScene );
223+ mTSShape ->setPosition (Point3F (0 , 0 , 1.5 ));
230224 mTSShape ->registerObject ();
231225 }
232226
233227 // Initialize camera values:
234- mOrbitPos = mTSShape ->mShapeInstance ->getShape ()->center ;
228+ mTSShape ->setPosition (Point3F (0 , 0 , mTSShape ->mShapeInstance ->getShape ()->mBounds .len_z () * 0 .5f ));
229+ mOrbitPos = mTSShape ->getPosition ();
235230 mMinOrbitDist = mTSShape ->mShapeInstance ->getShape ()->mRadius ;
236231
237232 lastRenderTime = Platform::getVirtualMilliseconds ();
@@ -329,37 +324,42 @@ void GuiMaterialPreview::renderWorld(const RectI &updateRect)
329324
330325 ScopedSceneManager scopeManager (mTempScene );
331326
332- LIGHTMGR->unregisterAllLights ();
333- LIGHTMGR->setSpecialLight (LightManager::slSunLightType, mFakeSun );
327+ RenderPassManager* renderPass = mTempScene ->getDefaultRenderPass ();
328+ SceneRenderState state
329+ (
330+ mTempScene ,
331+ SPT_Diffuse,
332+ SceneCameraState::fromGFX (),
333+ renderPass,
334+ true
335+ );
334336
335337 if (Skylight::smSkylightProbe.isValid ())
336338 PROBEMGR->submitProbe (Skylight::smSkylightProbe->getProbeInfo ());
337339
338- mTempScene ->renderScene (SPT_Diffuse );
340+ mTempScene ->renderScene (&state );
339341
340342 if (mMouseState == MovingLight)
341343 {
342344 renderSunDirection ();
343345 }
344346
345- // Make sure to remove our fake sun
346- LIGHTMGR->unregisterAllLights ();
347347}
348348
349349void GuiMaterialPreview::renderSunDirection () const
350350{
351351 // Render four arrows aiming in the direction of the sun's light
352- ColorI color = LinearColorF (mFakeSun ->getColor ()).toColorI ();
352+ ColorI color = LinearColorF (mRealSun -> getLight () ->getColor ()).toColorI ();
353353 F32 length = mTSShape ->mShapeInstance ->getShape ()->mBounds .len () * 0 .8f ;
354354
355355 // Get the sun's vectors
356- Point3F fwd = mFakeSun ->getTransform ().getForwardVector ();
357- Point3F up = mFakeSun ->getTransform ().getUpVector () * length / 8 ;
358- Point3F right = mFakeSun ->getTransform ().getRightVector () * length / 8 ;
356+ Point3F fwd = mRealSun -> getLight () ->getTransform ().getForwardVector ();
357+ Point3F up = mRealSun -> getLight () ->getTransform ().getUpVector () * length / 8 ;
358+ Point3F right = mRealSun -> getLight () ->getTransform ().getRightVector () * length / 8 ;
359359
360360 // Calculate the start and end points of the first arrow (bottom left)
361- Point3F start = mTSShape ->mShapeInstance -> getShape ()-> center - fwd * length - up / 2 - right / 2 ;
362- Point3F end = mTSShape ->mShapeInstance -> getShape ()-> center - fwd * length / 3 - up / 2 - right / 2 ;
361+ Point3F start = mTSShape ->getPosition () - fwd * length - up / 2 - right / 2 ;
362+ Point3F end = mTSShape ->getPosition () - fwd * length / 3 - up / 2 - right / 2 ;
363363
364364 GFXStateBlockDesc desc;
365365 desc.setZReadWrite (true , true );
@@ -382,15 +382,14 @@ void GuiMaterialPreview::setOrbitDistance(F32 distance)
382382void GuiMaterialPreview::resetViewport ()
383383{
384384 // Reset the camera's orientation.
385- mCameraRot .set ( mDegToRad (30 .0f ), 0 , mDegToRad (-30 .0f ) );
385+ mCameraRot .set (mDegToRad (3 .0f ), 0 , mDegToRad (-30 .0f ) );
386386 mCameraPos .set (0 .0f , 1 .75f , 1 .25f );
387387 mOrbitDist = 5 .0f ;
388- mOrbitPos = mTSShape ->mShapeInstance -> getShape ()-> center ;
388+ mOrbitPos = mTSShape ->getPosition () ;
389389
390390 // Reset the viewport's lighting.
391- GuiMaterialPreview::mFakeSun ->setColor ( LinearColorF ( 1 .0f , 1 .0f , 1 .0f ) );
392- GuiMaterialPreview::mFakeSun ->setAmbient ( LinearColorF ( 0 .5f , 0 .5f , 0 .5f ) );
393- GuiMaterialPreview::mFakeSun ->setDirection ( VectorF ( 0 .0f , 0 .707f , -0 .707f ) );
391+ GuiMaterialPreview::mRealSun ->setColor ( LinearColorF ( 1 .0f , 1 .0f , 1 .0f ) );
392+ GuiMaterialPreview::mRealSun ->setAmbientColor ( LinearColorF ( 0 .5f , 0 .5f , 0 .5f ) );
394393}
395394
396395// Expose the class and functions to the console.
0 commit comments