Torque3D/Engine/source/T3D/guiObjectView.h

286 lines
7.7 KiB
C
Raw Normal View History

2012-09-19 15:15:01 +00:00
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GUIOBJECTVIEW_H_
#define _GUIOBJECTVIEW_H_
#ifndef _GUITSCONTROL_H_
#include "gui/3d/guiTSControl.h"
#endif
#ifndef _TSSHAPEINSTANCE_H_
#include "ts/tsShapeInstance.h"
#endif
#include "T3D/assets/ShapeAsset.h"
2012-09-19 15:15:01 +00:00
class LightInfo;
/// A control that displays a TSShape in its view.
2025-06-19 15:27:16 +00:00
class GuiObjectView : public GuiTSCtrl, protected AssetPtrCallback
2012-09-19 15:15:01 +00:00
{
public:
typedef GuiTSCtrl Parent;
DECLARE_CALLBACK( void, onMouseEnter, ());
DECLARE_CALLBACK( void, onMouseLeave, ());
protected:
/// @name Mouse Control
/// @{
enum MouseState
{
None,
Rotating,
Zooming
};
/// Current mouse operation.
MouseState mMouseState;
/// Last mouse position during tracked mouse operations.
Point2I mLastMousePoint;
/// @}
/// @name Model
/// @{
///Model loaded for display.
2025-06-19 15:27:16 +00:00
DECLARE_SHAPEASSET_REFACTOR(GuiObjectView, Model)
TSShapeInstance* mModelInstance;
2012-09-19 15:15:01 +00:00
/// Name of skin to use on model.
String mSkinName;
/// @}
/// @name Camera State
/// @{
Point3F mCameraPos;
MatrixF mCameraMatrix;
EulerF mCameraRot;
Point3F mOrbitPos;
F32 mMaxOrbitDist;
F32 mMinOrbitDist;
EulerF mCameraRotation;
2012-09-19 15:15:01 +00:00
///
F32 mOrbitDist;
/// Multiplier for camera mouse operations (rotation and zooming).
F32 mCameraSpeed;
/// @}
/// @name Mounting
/// @{
///Model to mount to the primary model.
2025-06-19 15:27:16 +00:00
DECLARE_SHAPEASSET_REFACTOR(GuiObjectView, MountedModel)
TSShapeInstance* mMountedModelInstance;
2012-09-19 15:15:01 +00:00
///
String mMountSkinName;
/// Index of the node to mount the secondary model to. -1 (disabled) by default.
S32 mMountNode;
/// Name of node to mount the secondary model to. Unset by default.
String mMountNodeName;
///
MatrixF mMountTransform;
/// @}
/// @name Animation
/// @{
/// Index of the animation sequence to play on the model. -1 (disabled) by default.
S32 mAnimationSeq;
/// Name of the animation sequence to play on the model. Unset by default.
String mAnimationSeqName;
/// Animation thread on the model.
TSThread* mRunThread;
/// Last time we rendered the model. Used for animation.
S32 mLastRenderTime;
/// @}
/// @name Lighting
/// @{
/// Light object used as sun during rendering.
LightInfo* mLight;
///
LinearColorF mLightColor;
2012-09-19 15:15:01 +00:00
///
LinearColorF mLightAmbient;
2012-09-19 15:15:01 +00:00
///
Point3F mLightDirection;
/// @}
///
void _initAnimation();
///
void _initMount();
///
void onStaticModified( StringTableEntry slotName, const char* newValue ) override;
2012-09-19 15:15:01 +00:00
public:
GuiObjectView();
~GuiObjectView();
/// @name Model
/// @{
2012-09-19 15:15:01 +00:00
/// Return the name of the skin used on the primary model.
const String& getSkin() const { return mSkinName; }
/// Set the skin to use on the primary model.
void setSkin( const String& name );
/// Set the model to show in this view.
bool setObjectModel( const String& modelName );
2012-09-19 15:15:01 +00:00
/// @}
/// @name Animation
/// @{
/// Set the animation sequence to play on the model.
/// @param seqIndex Index of sequence to play.
void setObjectAnimation( S32 seqIndex );
/// Set the animation sequence to play on the model.
/// @param seqIndex Name of sequence to play.
void setObjectAnimation( const String& sequenceName );
/// @}
/// @name Mounting
/// @{
2012-09-19 15:15:01 +00:00
/// Return the name of the skin used on the mounted model.
const String& getMountSkin() const { return mMountSkinName; }
/// Set the skin to use on the mounted model.
void setMountSkin( const String& name );
///
void setMountNode( S32 index );
///
void setMountNode( const String& nodeName );
///
bool setMountedObject( const String& modelName );
2012-09-19 15:15:01 +00:00
/// @}
/// @name Camera
/// @{
/// Return the current camera speed multiplier.
F32 getCameraSpeed() const { return mCameraSpeed; }
/// Set the multiplier to apply to camera rotation and zooming.
void setCameraSpeed( F32 factor );
///
F32 getOrbitDistance() const { return mOrbitDist; }
/// Sets the distance at which the camera orbits the object. Clamped to the
/// acceptable range defined in the class by min and max orbit distances.
///
/// @param distance The distance to set the orbit to (will be clamped).
void setOrbitDistance( F32 distance );
/// Sets the angle of the camera on it's orbit in relation to the object.
void setCameraRotation( const EulerF& rotation );
2012-09-19 15:15:01 +00:00
/// @}
/// @name Lighting
/// @{
///
void setLightColor( const LinearColorF& color );
2012-09-19 15:15:01 +00:00
///
void setLightAmbient( const LinearColorF& color );
2012-09-19 15:15:01 +00:00
///
void setLightDirection( const Point3F& direction );
/// @}
// GuiTsCtrl.
bool onWake() override;
2012-09-19 15:15:01 +00:00
void onMouseEnter( const GuiEvent& event ) override;
void onMouseLeave( const GuiEvent& event ) override;
void onMouseDown( const GuiEvent& event ) override;
void onMouseUp( const GuiEvent& event ) override;
void onMouseDragged( const GuiEvent& event ) override;
void onRightMouseDown( const GuiEvent& event ) override;
void onRightMouseUp( const GuiEvent& event ) override;
void onRightMouseDragged( const GuiEvent& event ) override;
2012-09-19 15:15:01 +00:00
bool processCameraQuery( CameraQuery* query ) override;
void renderWorld( const RectI& updateRect ) override;
2012-09-19 15:15:01 +00:00
static void initPersistFields();
DECLARE_CONOBJECT( GuiObjectView );
2025-06-19 15:27:16 +00:00
DECLARE_DESCRIPTION( "A control that shows a TSShape model." );
protected:
void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override
{
if (getModel())
2025-06-19 15:27:16 +00:00
setObjectModel(_getModelAssetId());
if (getMountedModel())
2025-06-19 15:27:16 +00:00
setMountedObject(_getMountedModelAssetId());
}
2012-09-19 15:15:01 +00:00
};
#endif // !_GUIOBJECTVIEW_H_