Torque3D Documentation / _generateds / guiMaterialPreview.cpp

guiMaterialPreview.cpp

Engine/source/T3D/guiMaterialPreview.cpp

More...

Public Functions

ConsoleDocClass(GuiMaterialPreview , "@brief Visual preview of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specified <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Material\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )
DefineEngineMethod(GuiMaterialPreview , deleteModel , void , () , "Deletes the preview <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">model.\n</a>" )
DefineEngineMethod(GuiMaterialPreview , reset , void , () , "Resets the viewport <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> default zoom, pan , rotate and lighting." )
DefineEngineMethod(GuiMaterialPreview , setAmbientLightColor , void , (LinearColorF color) , "Sets the color of the ambient light in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">scene.\n</a>" )
DefineEngineMethod(GuiMaterialPreview , setLightColor , void , (LinearColorF color) , "Sets the color of the light in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">scene.\n</a>" )
DefineEngineMethod(GuiMaterialPreview , setModel , void , (const char *shapeName) , "Sets the model <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be displayed in this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control\n\n</a>" "@param shapeName Name of the model <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">display.\n</a>" )
DefineEngineMethod(GuiMaterialPreview , setOrbitDistance , void , (F32 distance) , "Sets the distance at which the camera orbits the object. Clamped <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the " "acceptable range defined in the class by min and max orbit <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">distances.\n\n</a>" "@param distance The distance <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set the orbit <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> (will be clamped)." )

Detailed Description

Public Functions

ConsoleDocClass(GuiMaterialPreview , "@brief Visual preview of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specified <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Material\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )

DefineEngineMethod(GuiMaterialPreview , deleteModel , void , () , "Deletes the preview <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">model.\n</a>" )

DefineEngineMethod(GuiMaterialPreview , reset , void , () , "Resets the viewport <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> default zoom, pan , rotate and lighting." )

DefineEngineMethod(GuiMaterialPreview , setAmbientLightColor , void , (LinearColorF color) , "Sets the color of the ambient light in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">scene.\n</a>" )

DefineEngineMethod(GuiMaterialPreview , setLightColor , void , (LinearColorF color) , "Sets the color of the light in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">scene.\n</a>" )

DefineEngineMethod(GuiMaterialPreview , setModel , void , (const char *shapeName) , "Sets the model <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be displayed in this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control\n\n</a>" "@param shapeName Name of the model <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">display.\n</a>" )

DefineEngineMethod(GuiMaterialPreview , setOrbitDistance , void , (F32 distance) , "Sets the distance at which the camera orbits the object. Clamped <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the " "acceptable range defined in the class by min and max orbit <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">distances.\n\n</a>" "@param distance The distance <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set the orbit <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> (will be clamped)." )

IMPLEMENT_CONOBJECT(GuiMaterialPreview )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24// Original header:
 25// GuiMaterialPreview Control for Material Editor Written by Travis Vroman of Gaslight Studios
 26// Updated 2-14-09
 27// Portions based off Constructor viewport code.
 28
 29#include "console/engineAPI.h"
 30#include "T3D/guiMaterialPreview.h"
 31#include "renderInstance/renderPassManager.h"
 32#include "lighting/lightManager.h"
 33#include "lighting/lightInfo.h"
 34#include "core/resourceManager.h"
 35#include "scene/sceneManager.h"
 36#include "scene/sceneRenderState.h"
 37
 38// GuiMaterialPreview
 39GuiMaterialPreview::GuiMaterialPreview()
 40:  mMouseState(None),
 41   mModel(NULL),
 42   runThread(0),
 43   lastRenderTime(0),
 44   mLastMousePoint(0, 0),
 45   mFakeSun(NULL),
 46   mMaxOrbitDist(5.0f),
 47   mMinOrbitDist(0.0f),
 48   mOrbitDist(5.0f)
 49{
 50   mActive = true;
 51   mCameraMatrix.identity();
 52   mCameraRot.set( mDegToRad(30.0f), 0, mDegToRad(-30.0f) );
 53   mCameraPos.set(0.0f, 1.75f, 1.25f);
 54   mCameraMatrix.setColumn(3, mCameraPos);
 55   mOrbitPos.set(0.0f, 0.0f, 0.0f);
 56   mTransStep = 0.01f;
 57   mTranMult = 4.0;
 58   mLightTransStep = 0.01f;
 59   mLightTranMult = 4.0;
 60   mOrbitRelPos = Point3F(0,0,0);
 61
 62   // By default don't do dynamic reflection
 63   // updates for this viewport.
 64   mReflectPriority = 0.0f;
 65   mMountedModel = NULL;
 66   mSkinTag = 0;
 67}
 68
 69GuiMaterialPreview::~GuiMaterialPreview()
 70{
 71   SAFE_DELETE(mModel);
 72   SAFE_DELETE(mFakeSun);
 73}
 74
 75bool GuiMaterialPreview::onWake()
 76{
 77   if( !Parent::onWake() )
 78      return false;
 79
 80   if (!mFakeSun)
 81      mFakeSun = LightManager::createLightInfo();
 82
 83   mFakeSun->setColor( LinearColorF( 1.0f, 1.0f, 1.0f ) );
 84   mFakeSun->setAmbient( LinearColorF( 0.5f, 0.5f, 0.5f ) );
 85   mFakeSun->setDirection( VectorF( 0.0f, 0.707f, -0.707f ) );
 86   mFakeSun->setPosition( mFakeSun->getDirection() * -10000.0f );
 87   mFakeSun->setRange( 2000000.0f );
 88
 89   return true;
 90}
 91
 92// This function allows the viewport's ambient color to be changed. This is exposed to script below.
 93void GuiMaterialPreview::setAmbientLightColor( F32 r, F32 g, F32 b )
 94{
 95   LinearColorF temp(r, g, b);
 96   temp.clamp();
 97   GuiMaterialPreview::mFakeSun->setAmbient( temp );
 98}
 99
100// This function allows the light's color to be changed. This is exposed to script below.
101void GuiMaterialPreview::setLightColor( F32 r, F32 g, F32 b )
102{
103   LinearColorF temp(r, g, b);
104   temp.clamp();
105   GuiMaterialPreview::mFakeSun->setColor( temp );
106}
107
108// This function is for moving the light in the scene. This needs to be adjusted to keep the light
109// from getting all out of whack. For now, we'll just rely on the reset function if we need it 
110// fixed.
111void GuiMaterialPreview::setLightTranslate(S32 modifier, F32 xstep, F32 ystep)
112{
113   F32 _lighttransstep = (modifier & SI_SHIFT ? mLightTransStep : (mLightTransStep*mLightTranMult));
114
115   Point3F relativeLightDirection = GuiMaterialPreview::mFakeSun->getDirection();
116   // May be able to get rid of this. For now, it helps to fix the position of the light if i gets messed up.
117   if (modifier & SI_PRIMARY_CTRL)
118   {
119      relativeLightDirection.x += ( xstep * _lighttransstep * -1 );//need to invert this for some reason. Otherwise, it's backwards.
120      relativeLightDirection.y += ( ystep * _lighttransstep );
121      GuiMaterialPreview::mFakeSun->setDirection(relativeLightDirection);
122   }
123   // Default action taken by mouse wheel clicking.
124   else
125   {
126      relativeLightDirection.x += ( xstep * _lighttransstep * -1 ); //need to invert this for some reason. Otherwise, it's backwards.
127      relativeLightDirection.z += ( ystep * _lighttransstep );
128      GuiMaterialPreview::mFakeSun->setDirection(relativeLightDirection);
129   }
130}
131
132// This is for panning the viewport camera.
133void GuiMaterialPreview::setTranslate(S32 modifier, F32 xstep, F32 ystep)
134{
135   F32 transstep = (modifier & SI_SHIFT ? mTransStep : (mTransStep*mTranMult));
136
137   F32 nominalDistance = 20.0;
138   Point3F vec = mCameraPos;
139   vec -= mOrbitPos;
140   transstep *= vec.len() / nominalDistance;
141
142   if (modifier & SI_PRIMARY_CTRL)
143   {
144      mOrbitRelPos.x += ( xstep * transstep );
145      mOrbitRelPos.y += ( ystep * transstep );
146   }
147   else
148   {
149      mOrbitRelPos.x += ( xstep * transstep );
150      mOrbitRelPos.z += ( ystep * transstep );
151   }
152}
153
154// Left Click
155void GuiMaterialPreview::onMouseDown(const GuiEvent &event)
156{
157   mMouseState = MovingLight;
158   mLastMousePoint = event.mousePoint;
159   mouseLock();
160}
161
162// Left Click Release
163void GuiMaterialPreview::onMouseUp(const GuiEvent &event)
164{
165   mouseUnlock();
166   mMouseState = None;
167}
168
169// Left Click Drag
170void GuiMaterialPreview::onMouseDragged(const GuiEvent &event)
171{
172   if(mMouseState != MovingLight)
173   {
174      return;
175   }
176   // If we are MovingLight...
177   else
178   {
179   Point2I delta = event.mousePoint - mLastMousePoint;
180   mLastMousePoint = event.mousePoint;
181   setLightTranslate(event.modifier, delta.x, delta.y);
182   }
183}
184
185// Right Click
186void GuiMaterialPreview::onRightMouseDown(const GuiEvent &event)
187{
188   mMouseState = Rotating;
189   mLastMousePoint = event.mousePoint;
190   mouseLock();
191}
192
193// Right Click Release
194void GuiMaterialPreview::onRightMouseUp(const GuiEvent &event)
195{
196   mouseUnlock();
197   mMouseState = None;
198}
199
200// Right Click Drag
201void GuiMaterialPreview::onRightMouseDragged(const GuiEvent &event)
202{
203   if (mMouseState != Rotating)
204   {
205      return;
206   }
207   Point2I delta = event.mousePoint - mLastMousePoint;
208   mLastMousePoint = event.mousePoint;
209   mCameraRot.x += (delta.y * 0.01f);
210   mCameraRot.z += (delta.x * 0.01f);
211}
212
213// Mouse Wheel Scroll Up
214bool GuiMaterialPreview::onMouseWheelUp(const GuiEvent &event)
215{
216   mOrbitDist = (mOrbitDist - 0.10f);
217   return true;
218}
219
220// Mouse Wheel Scroll Down
221bool GuiMaterialPreview::onMouseWheelDown(const GuiEvent &event)
222{
223   mOrbitDist = (mOrbitDist + 0.10f);
224   return true;
225}
226
227// Mouse Wheel Click
228void GuiMaterialPreview::onMiddleMouseDown(const GuiEvent &event)
229{
230   if (!mActive || !mVisible || !mAwake)
231   {
232      return;
233   }
234   mMouseState = Panning;
235   mLastMousePoint = event.mousePoint;
236   mouseLock();
237}
238
239// Mouse Wheel Click Release
240void GuiMaterialPreview::onMiddleMouseUp(const GuiEvent &event)
241{
242   mouseUnlock();
243   mMouseState = None;
244}
245
246// Mouse Wheel Click Drag
247void GuiMaterialPreview::onMiddleMouseDragged(const GuiEvent &event)
248{
249   if (mMouseState != Panning)
250   {
251      return;
252   }
253   Point2I delta = event.mousePoint - mLastMousePoint;
254   mLastMousePoint = event.mousePoint;
255   setTranslate(event.modifier, delta.x, delta.y);
256}
257
258// This is used to set the model we want to view in the control object.
259void GuiMaterialPreview::setObjectModel(const char* modelName)
260{
261   deleteModel();
262
263   Resource<TSShape> model = ResourceManager::get().load(modelName);
264   if (! bool(model))
265   {
266      Con::warnf(avar("GuiMaterialPreview: Failed to load model %s. Please check your model name and load a valid model.", modelName));
267      return;
268   }
269
270   mModel = new TSShapeInstance(model, true);
271   AssertFatal(mModel, avar("GuiMaterialPreview: Failed to load model %s. Please check your model name and load a valid model.", modelName));
272
273   // Initialize camera values:
274   mOrbitPos = mModel->getShape()->center;
275   mMinOrbitDist = mModel->getShape()->mRadius;
276
277   lastRenderTime = Platform::getVirtualMilliseconds();
278}
279
280void GuiMaterialPreview::deleteModel()
281{
282   SAFE_DELETE(mModel);
283   runThread = 0;
284}
285
286// This is called whenever there is a change in the camera.
287bool GuiMaterialPreview::processCameraQuery(CameraQuery* query)
288{
289   MatrixF xRot, zRot;
290   Point3F vecf, vecu, vecr;;
291   xRot.set(EulerF(mCameraRot.x, 0.0f, 0.0f));
292    zRot.set(EulerF(0.0f, 0.0f, mCameraRot.z));
293
294   if(mMouseState != Panning)
295   {
296      // Adjust the camera so that we are still facing the model:
297      Point3F vec;
298
299      mCameraMatrix.mul(zRot, xRot);
300      mCameraMatrix.getColumn(1, &vec);
301      vec *= mOrbitDist;
302      mCameraPos = mOrbitPos - vec;
303
304      query->farPlane = 2100.0f;
305      query->nearPlane = query->farPlane / 5000.0f;
306      query->fov = 45.0f;
307      mCameraMatrix.setColumn(3, mCameraPos);
308      query->cameraMatrix = mCameraMatrix;
309   }
310   else
311   {
312     mCameraMatrix.mul( zRot, xRot );
313     mCameraMatrix.getColumn( 1, &vecf ); // Forward vector
314     mCameraMatrix.getColumn( 2, &vecu ); // Up vector
315     mCameraMatrix.getColumn( 0, &vecr ); // Right vector
316
317      Point3F flatVecf(vecf.x, vecf.y, 0.0f);
318
319      Point3F modvecf = flatVecf * mOrbitRelPos.y;
320      Point3F modvecu = vecu * mOrbitRelPos.z;
321      Point3F modvecr = vecr * mOrbitRelPos.x;
322
323     // Change the orbit position
324     mOrbitPos += modvecu - modvecr + modvecf;
325
326     F32 vecfmul = mOrbitDist;
327     Point3F virtualVecF = vecf * mOrbitDist;
328     vecf *= vecfmul;
329
330     mCameraPos = mOrbitPos - virtualVecF;
331
332     // Update the camera's position
333     mCameraMatrix.setColumn( 3, (mOrbitPos - vecf) );
334
335     query->farPlane = 2100.0f;
336      query->nearPlane = query->farPlane / 5000.0f;
337      query->fov = 45.0f;
338     query->cameraMatrix = mCameraMatrix;
339
340     // Reset the relative position
341     mOrbitRelPos = Point3F(0,0,0);
342   }
343   return true;
344}
345
346void GuiMaterialPreview::onMouseEnter(const GuiEvent & event)
347{
348   Con::executef(this, "onMouseEnter");
349}
350
351void GuiMaterialPreview::onMouseLeave(const GuiEvent & event)
352{
353   Con::executef(this, "onMouseLeave");
354}
355
356void GuiMaterialPreview::renderWorld(const RectI &updateRect)
357{
358   // nothing to render, punt
359   if ( !mModel && !mMountedModel )
360      return;
361
362   S32 time = Platform::getVirtualMilliseconds();
363   //S32 dt = time - lastRenderTime;
364   lastRenderTime = time;
365
366   
367
368   F32 left, right, top, bottom, nearPlane, farPlane;
369   bool isOrtho;
370   GFX->getFrustum( &left, &right, &bottom, &top, &nearPlane, &farPlane, &isOrtho);
371   Frustum frust( isOrtho, left, right, bottom, top, nearPlane, farPlane, MatrixF::Identity );
372
373   FogData savedFogData = gClientSceneGraph->getFogData();
374   gClientSceneGraph->setFogData( FogData() );  // no fog in preview window
375
376   RenderPassManager* renderPass = gClientSceneGraph->getDefaultRenderPass();
377   SceneRenderState state
378   (
379      gClientSceneGraph,
380      SPT_Diffuse,
381      SceneCameraState( GFX->getViewport(), frust, GFX->getWorldMatrix(), GFX->getProjectionMatrix() ),
382      renderPass,
383      true
384   );
385
386   // Set up our TS render state here.
387   TSRenderState rdata;
388   rdata.setSceneState( &state );
389
390   // We might have some forward lit materials
391   // so pass down a query to gather lights.
392   LightQuery query;
393   query.init( SphereF( Point3F::Zero, 1.0f ) );
394   rdata.setLightQuery( &query );
395
396   // Set up pass transforms
397   renderPass->assignSharedXform(RenderPassManager::View, MatrixF::Identity);
398   renderPass->assignSharedXform(RenderPassManager::Projection, GFX->getProjectionMatrix());
399
400   LIGHTMGR->unregisterAllLights();
401   LIGHTMGR->setSpecialLight( LightManager::slSunLightType, mFakeSun );
402
403   if ( mModel )
404      mModel->render( rdata );
405
406   if ( mMountedModel )
407   {
408      // render a weapon
409      /*
410      MatrixF mat;
411
412      GFX->pushWorldMatrix();
413      GFX->multWorld( mat );
414
415      GFX->popWorldMatrix();
416     */
417   }
418
419   renderPass->renderPass( &state );
420
421   gClientSceneGraph->setFogData( savedFogData );         // restore fog setting
422
423   // Make sure to remove our fake sun
424   LIGHTMGR->unregisterAllLights();
425}
426
427// Make sure the orbit distance is within the acceptable range.
428void GuiMaterialPreview::setOrbitDistance(F32 distance)
429{
430   mOrbitDist = mClampF(distance, mMinOrbitDist, mMaxOrbitDist);
431}
432
433// This function is meant to be used with a button to put everything back to default settings.
434void GuiMaterialPreview::resetViewport()
435{
436   // Reset the camera's orientation.
437   mCameraRot.set( mDegToRad(30.0f), 0, mDegToRad(-30.0f) );
438   mCameraPos.set(0.0f, 1.75f, 1.25f);
439   mOrbitDist = 5.0f;
440   mOrbitPos = mModel->getShape()->center;
441
442   // Reset the viewport's lighting.
443   GuiMaterialPreview::mFakeSun->setColor( LinearColorF( 1.0f, 1.0f, 1.0f ) );
444   GuiMaterialPreview::mFakeSun->setAmbient( LinearColorF( 0.5f, 0.5f, 0.5f ) );
445   GuiMaterialPreview::mFakeSun->setDirection( VectorF( 0.0f, 0.707f, -0.707f ) );
446}
447
448// Expose the class and functions to the console.
449IMPLEMENT_CONOBJECT(GuiMaterialPreview);
450
451ConsoleDocClass( GuiMaterialPreview,
452   "@brief Visual preview of a specified Material\n\n"
453   "Editor use only.\n\n"
454   "@internal"
455);
456
457// Set the model.
458DefineEngineMethod(GuiMaterialPreview, setModel, void, ( const char* shapeName ),,
459   "Sets the model to be displayed in this control\n\n"
460   "@param shapeName Name of the model to display.\n")
461{
462   object->setObjectModel(shapeName);
463}
464
465DefineEngineMethod(GuiMaterialPreview, deleteModel, void, (),,
466   "Deletes the preview model.\n")
467{
468   object->deleteModel();
469}
470
471// Set orbit distance around the model.
472DefineEngineMethod(GuiMaterialPreview, setOrbitDistance, void, ( F32 distance ),,
473   "Sets the distance at which the camera orbits the object. Clamped to the "
474   "acceptable range defined in the class by min and max orbit distances.\n\n"
475   "@param distance The distance to set the orbit to (will be clamped).")
476{
477   object->setOrbitDistance(distance);
478}
479
480// Reset control to default values. Meant to be used with a button.
481DefineEngineMethod(GuiMaterialPreview, reset, void, (),,
482   "Resets the viewport to default zoom, pan, rotate and lighting.")
483{
484   object->resetViewport();
485}
486
487// This function allows the user to change the light's color.
488DefineEngineMethod(GuiMaterialPreview, setLightColor, void, ( LinearColorF color ),,
489   "Sets the color of the light in the scene.\n")
490{
491   object->setLightColor( color.red, color.green, color.blue );
492}
493
494// This function allows the user to change the viewports's ambient color.
495DefineEngineMethod(GuiMaterialPreview, setAmbientLightColor, void, ( LinearColorF color ),,
496   "Sets the color of the ambient light in the scene.\n")
497{
498   object->setAmbientLightColor( color.red, color.green, color.blue );
499}
500