summaryrefslogtreecommitdiffstats
path: root/tools/trackeditor/code/main
diff options
context:
space:
mode:
authorSvxy <aidan61605@gmail.com>2023-05-31 23:31:32 +0200
committerSvxy <aidan61605@gmail.com>2023-05-31 23:31:32 +0200
commiteb4b3404aa00220d659e532151dab13d642c17a3 (patch)
tree7e1107c4995489a26c4007e41b53ea8d00ab2134 /tools/trackeditor/code/main
downloadThe-Simpsons-Hit-and-Run-TSH&R-PC.tar
The-Simpsons-Hit-and-Run-TSH&R-PC.tar.gz
The-Simpsons-Hit-and-Run-TSH&R-PC.tar.bz2
The-Simpsons-Hit-and-Run-TSH&R-PC.tar.lz
The-Simpsons-Hit-and-Run-TSH&R-PC.tar.xz
The-Simpsons-Hit-and-Run-TSH&R-PC.tar.zst
The-Simpsons-Hit-and-Run-TSH&R-PC.zip
Diffstat (limited to 'tools/trackeditor/code/main')
-rw-r--r--tools/trackeditor/code/main/constants.h21
-rw-r--r--tools/trackeditor/code/main/pluginMain.cpp164
-rw-r--r--tools/trackeditor/code/main/pluginMain.h47
-rw-r--r--tools/trackeditor/code/main/shapeconstants.h34
-rw-r--r--tools/trackeditor/code/main/trackeditor.cpp350
-rw-r--r--tools/trackeditor/code/main/trackeditor.h85
6 files changed, 701 insertions, 0 deletions
diff --git a/tools/trackeditor/code/main/constants.h b/tools/trackeditor/code/main/constants.h
new file mode 100644
index 0000000..b9bcc25
--- /dev/null
+++ b/tools/trackeditor/code/main/constants.h
@@ -0,0 +1,21 @@
+#ifndef TE_CONSTANTS
+#define TE_CONSTANTS
+
+namespace TEConstants
+{
+ const unsigned int TypeIDPrefix = 0x00040200;
+ const float Scale = 100.0f;
+
+ namespace NodeIDs
+ {
+ const unsigned int WallLocator = 0xc0;
+ const unsigned int FenceLine = 0xc1;
+ const unsigned int TileDisplay = 0xc2;
+ const unsigned int Intersection = 0xc3;
+ const unsigned int Road = 0xc4;
+ const unsigned int TreeLine = 0xc5;
+ const unsigned int PedPath = 0xc6;
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/tools/trackeditor/code/main/pluginMain.cpp b/tools/trackeditor/code/main/pluginMain.cpp
new file mode 100644
index 0000000..190ea4d
--- /dev/null
+++ b/tools/trackeditor/code/main/pluginMain.cpp
@@ -0,0 +1,164 @@
+//
+// Copyright (C) 2002 Radical Entertainment
+//
+// File: pluginMain.cpp
+//
+// Author: Maya SDK Wizard
+//
+#include "precompiled/PCH.h"
+
+#include <maya/MFnPlugin.h>
+
+//This is a warning provided by the STL... It seems that toollib gets whacky when there
+//is other templates made... Sigh...
+#pragma warning(disable:4786)
+
+#include "pluginmain.h"
+#include "trackeditor.h"
+
+#include "utility/mayahandles.h"
+#include "utility/mext.h"
+
+//Nodes
+#include "nodes/walllocator.h"
+#include "nodes/fenceline.h"
+#include "nodes/tiledisplay.h"
+#include "nodes/intersection.h"
+#include "nodes/road.h"
+#include "nodes/treelineshapenode.h"
+#include "nodes/pedpath.h"
+
+//Contexts
+#include "contexts/bvcontext.h"
+#include "contexts/intersectioncontext.h"
+#include "contexts/treelinecontext.h"
+#include "contexts/ppcontext.h"
+
+//Commands
+#include "commands/export.h"
+#include "commands/trackeditorcommands.h"
+#include "commands/intersectioncommands.h"
+#include "commands/treelinecommand.h"
+
+
+TrackEditor* gTE = 0;
+
+MStatus initializePlugin( MObject obj )
+//
+// Description:
+// this method is called when the plug-in is loaded into Maya. It
+// registers all of the services that this plug-in provides with
+// Maya.
+//
+// Arguments:
+// obj - a handle to the plug-in object (use MFnPlugin to access it)
+//
+{
+ MStatus status;
+
+
+ MayaHandles::SetHInstance( (void*)(MhInstPlugin) );
+
+ MFnPlugin plugin( obj, "Radical Entertainment", "4.0.1", "Any");
+
+ // Add plug-in feature registration here
+ //
+
+ //Register Nodes
+ REGISTER_LOCATOR( plugin, WallLocatorNode );
+ REGISTER_LOCATOR( plugin, FenceLineNode );
+ REGISTER_LOCATOR( plugin, TileDisplayNode );
+ REGISTER_LOCATOR( plugin, IntersectionLocatorNode );
+ REGISTER_LOCATOR( plugin, RoadNode );
+ REGISTER_LOCATOR( plugin, PedPathNode );
+
+ REGISTER_SHAPE( plugin, TETreeLine::TreelineShapeNode );
+
+ //Register Contexts
+ REGISTER_CONTEXT( plugin, BVContext );
+ REGISTER_CONTEXT( plugin, IntersectionContext );
+ REGISTER_CONTEXT( plugin, TreeLineContext );
+ REGISTER_CONTEXT( plugin, PPContext );
+
+ //Register Commands
+ REGISTER_COMMAND( plugin, PPSplitCmd );
+ REGISTER_COMMAND( plugin, BVSplitCmd );
+ REGISTER_COMMAND( plugin, ExportCommand );
+ REGISTER_COMMAND( plugin, TEStateChangeCommand );
+ REGISTER_COMMAND( plugin, TEGetSelectedVertexPosition );
+ REGISTER_COMMAND( plugin, TEGetSelectedVertexIndex );
+ REGISTER_COMMAND( plugin, CreateRoadCmd );
+ REGISTER_COMMAND( plugin, AddIntersectionToRoadCmd );
+ REGISTER_COMMAND( plugin, ShowRoadCmd );
+ REGISTER_COMMAND( plugin, DestroyRoadCmd );
+ REGISTER_COMMAND( plugin, SnapSelectedTreelines );
+ REGISTER_COMMAND( plugin, ConvertTreelineToGeometry );
+ REGISTER_COMMAND( plugin, SetDeleteTreeline );
+
+
+ //Create the TrackEditor.
+ gTE = new TrackEditor();
+
+ //Run any startup scripts.
+ MGlobal::sourceFile( MString( "te_main.mel" ) );
+
+ return status;
+}
+
+MStatus uninitializePlugin( MObject obj )
+//
+// Description:
+// this method is called when the plug-in is unloaded from Maya. It
+// deregisters all of the services that it was providing.
+//
+// Arguments:
+// obj - a handle to the plug-in object (use MFnPlugin to access it)
+//
+{
+ MStatus status;
+ MFnPlugin plugin( obj );
+
+ // Add plug-in feature deregistration here
+ //
+
+ //Run any cleanup scripts.
+ MGlobal::sourceFile( MString( "te_cleanup.mel" ) );
+
+ if ( gTE )
+ {
+ delete gTE;
+ }
+
+ //Unregister Commands
+ DEREGISTER_COMMAND( plugin, SetDeleteTreeline );
+ DEREGISTER_COMMAND( plugin, ConvertTreelineToGeometry );
+ DEREGISTER_COMMAND( plugin, SnapSelectedTreelines );
+ DEREGISTER_COMMAND( plugin, DestroyRoadCmd );
+ DEREGISTER_COMMAND( plugin, ShowRoadCmd );
+ DEREGISTER_COMMAND( plugin, AddIntersectionToRoadCmd );
+ DEREGISTER_COMMAND( plugin, CreateRoadCmd );
+ DEREGISTER_COMMAND( plugin, TEGetSelectedVertexIndex );
+ DEREGISTER_COMMAND( plugin, TEGetSelectedVertexPosition );
+ DEREGISTER_COMMAND( plugin, TEStateChangeCommand );
+ DEREGISTER_COMMAND( plugin, ExportCommand );
+ DEREGISTER_COMMAND( plugin, BVSplitCmd );
+
+ //Unregister Contexts
+ DEREGISTER_CONTEXT( plugin, PPContext );
+ DEREGISTER_CONTEXT( plugin, TreeLineContext );
+ DEREGISTER_CONTEXT( plugin, IntersectionContext );
+ DEREGISTER_CONTEXT( plugin, BVContext );
+ DEREGISTER_CONTEXT( plugin, PPContext );
+
+ //Unregister Nodes
+ DEREGISTER_NODE( plugin, PedPathNode );
+ DEREGISTER_NODE( plugin, TETreeLine::TreelineShapeNode );
+ DEREGISTER_NODE( plugin, RoadNode );
+ DEREGISTER_NODE( plugin, IntersectionLocatorNode );
+ DEREGISTER_NODE( plugin, TileDisplayNode );
+ DEREGISTER_NODE( plugin, FenceLineNode );
+ DEREGISTER_NODE( plugin, WallLocatorNode );
+
+ return status;
+}
+
diff --git a/tools/trackeditor/code/main/pluginMain.h b/tools/trackeditor/code/main/pluginMain.h
new file mode 100644
index 0000000..7ed6ee6
--- /dev/null
+++ b/tools/trackeditor/code/main/pluginMain.h
@@ -0,0 +1,47 @@
+#include "precompiled/PCH.h"
+
+//----------------------------------------
+// MACROS
+//----------------------------------------
+
+#define REGISTER_COMMAND( p, c ) if ( ! ( ( p ).registerCommand( c##::stringId, \
+ c##::creator ) \
+ ) \
+ ) return MS::kFailure
+
+#define REGISTER_CONTEXT( p, c ) if ( ! ( ( p ).registerContextCommand( c##::stringId, \
+ c##Cmd::creator ) \
+ ) \
+ ) return MS::kFailure
+
+
+#define REGISTER_LOCATOR( p, n ) if ( ! ( ( p ).registerNode( n##::stringId, \
+ n##::id, \
+ n##::creator, \
+ n##::initialize, \
+ MPxNode::kLocatorNode ) \
+ ) \
+ ) return MS::kFailure
+
+#define REGISTER_NODE( p, n ) if ( ! ( ( p ).registerNode( n##::stringId, \
+ n##::id, \
+ n##::creator, \
+ n##::initialize ) \
+ ) \
+ ) return MS::kFailure
+
+#define REGISTER_SHAPE( p, n ) if ( ! ( ( p ).registerShape( n##::stringId, \
+ n##::id, \
+ n##::creator, \
+ n##::initialize, \
+ n##UI::creator ) \
+ ) \
+ ) return MS::kFailure
+
+#define DEREGISTER_COMMAND( p, c ) ( p ).deregisterCommand( c##::stringId )
+
+#define DEREGISTER_CONTEXT( p, c ) ( p ).deregisterContextCommand( c##::stringId )
+
+
+#define DEREGISTER_NODE( p, n ) ( p ).deregisterNode( n##::id )
+
diff --git a/tools/trackeditor/code/main/shapeconstants.h b/tools/trackeditor/code/main/shapeconstants.h
new file mode 100644
index 0000000..c6c777d
--- /dev/null
+++ b/tools/trackeditor/code/main/shapeconstants.h
@@ -0,0 +1,34 @@
+#ifndef SHAPE_CONSTANTS_H
+#define SHAPE_CONSTANTS_H
+
+#define LEAD_COLOR 1 // green
+#define ACTIVE_COLOR 1 // white
+#define ACTIVE_AFFECTED_COLOR 1 // purple
+#define DORMANT_COLOR 1 // blue
+#define HILITE_COLOR 1 // pale blue
+
+#define P3D_BILLBOARD_QUAD_ID 0x040260
+#define P3D_BILLBOARD_QUAD_GROUP_ID 0x040261
+#define MAYA_LAMBERT_ID 1380729165
+#define MAYA_PHONG_ID 1380993103
+#define MAYA_LAYERED_SHADER_ID 1280922195
+
+namespace TETreeLine
+{
+
+const float MIN_DISPLAY_SIZE=0.001f;
+
+enum {
+ WIREFRAME,
+ WIREFRAME_SHADED,
+ SMOOTH_SHADED,
+ FLAT_SHADED,
+ VERTICES,
+ LAST_TOKEN
+};
+
+}; //namespace TETreeLine
+
+
+#endif //SHAPE_CONSTANTS_H
+
diff --git a/tools/trackeditor/code/main/trackeditor.cpp b/tools/trackeditor/code/main/trackeditor.cpp
new file mode 100644
index 0000000..0b0ccc2
--- /dev/null
+++ b/tools/trackeditor/code/main/trackeditor.cpp
@@ -0,0 +1,350 @@
+#include "precompiled/PCH.h"
+
+#include "trackeditor.h"
+#include "utility/mext.h"
+
+#include "nodes/tiledisplay.h"
+#include "nodes/fenceline.h"
+#include "nodes/intersection.h"
+#include "nodes/walllocator.h"
+#include "nodes/road.h"
+#include "nodes/treelineshapenode.h"
+#include "nodes/pedpath.h"
+
+const char* TrackEditor::Name = "TrackEditorNode";
+TrackEditor::EditMode TrackEditor::sEditMode = TrackEditor::OFF;
+unsigned int TrackEditor::sNodeAddedbackID = 0;
+unsigned int TrackEditor::sWindowClosedCallbackID = 0;
+bool TrackEditor::sDeleteTreelines = true;
+
+
+//==============================================================================
+// TrackEditor::TrackEditor
+//==============================================================================
+// Description: Comment
+//
+// Parameters: ()
+//
+// Return: TrackEditor
+//
+//==============================================================================
+TrackEditor::TrackEditor()
+{
+// sNodeAddedbackID = MDGMessage::addNodeAddedCallback ( NodeAddedCB,
+// MString( "surfaceShape" ) );
+};
+
+//==============================================================================
+// TrackEditor::~TrackEditor
+//==============================================================================
+// Description: Comment
+//
+// Parameters: ()
+//
+// Return: TrackEditor
+//
+//==============================================================================
+TrackEditor::~TrackEditor()
+{
+ if ( sNodeAddedbackID )
+ {
+ MDGMessage::removeCallback( sNodeAddedbackID );
+ }
+
+ if ( sWindowClosedCallbackID )
+ {
+ MUiMessage::removeCallback( sWindowClosedCallbackID );
+ }
+
+ RemoveTileDisplayNode();
+};
+
+//==============================================================================
+// TrackEditor::Exists
+//==============================================================================
+// Description: Comment
+//
+// Parameters: ()
+//
+// Return: bool
+//
+//==============================================================================
+bool TrackEditor::Exists()
+{
+ MDagPath pathToTrackEditor;
+ return MExt::FindDagNodeByName( &pathToTrackEditor, MString( TrackEditor::Name ) );
+}
+
+//==============================================================================
+// TrackEditor::AddChild
+//==============================================================================
+// Description: Comment
+//
+// Parameters: ( MObject& obj )
+//
+// Return: MStatus
+//
+//==============================================================================
+MStatus TrackEditor::AddChild( MObject& obj )
+{
+ //Make sure this exists.
+ CreateTrackEditorNode();
+
+ MDagPath pathToTrackEditor;
+
+ bool good = false;
+
+ if ( MExt::FindDagNodeByName( &pathToTrackEditor, MString( TrackEditor::Name ) ) )
+ {
+ good = true;
+ }
+ else
+ {
+ MGlobal::sourceFile( MString( "te_setup.mel" ) );
+
+ if ( MExt::FindDagNodeByName( &pathToTrackEditor, MString( TrackEditor::Name ) ) )
+ {
+ good = true;
+ }
+ }
+
+ if ( good )
+ {
+ MFnDagNode fnDagNodeTE;
+
+ //Which type?
+ MFnDagNode fnDagNodeObj( obj );
+
+ if ( fnDagNodeObj.typeId() == FenceLineNode::id )
+ {
+ //This is a fenceline, parent to the "Fences" node.
+ MDagPath dagPath;
+ if ( MExt::FindDagNodeByName( &dagPath, MString("Fences"), pathToTrackEditor.node() ) )
+ {
+ fnDagNodeTE.setObject( dagPath.node() );
+ }
+ else
+ {
+ MExt::DisplayError( "Someone has deleted Terrain Edit nodes!!" );
+ }
+ }
+ if ( fnDagNodeObj.typeId() == PedPathNode::id )
+ {
+ //This is a ped path, parent to the "PedPaths" node.
+ MDagPath dagPath;
+ if ( MExt::FindDagNodeByName( &dagPath, MString("PedPaths"), pathToTrackEditor.node() ) )
+ {
+ fnDagNodeTE.setObject( dagPath.node() );
+ }
+ else
+ {
+ MExt::DisplayError( "Someone has deleted Terrain Edit nodes!!" );
+ }
+ }
+ else if ( fnDagNodeObj.typeId() == IntersectionLocatorNode::id )
+ {
+ //This is a fenceline, parent to the "Intersections" node.
+ MDagPath dagPath;
+ if ( MExt::FindDagNodeByName( &dagPath, MString("Intersections"), pathToTrackEditor.node() ) )
+ {
+ fnDagNodeTE.setObject( dagPath.node() );
+ }
+ else
+ {
+ MExt::DisplayError( "Someone has deleted Terrain Edit nodes!!" );
+ }
+ }
+ else if ( fnDagNodeObj.typeId() == RoadNode::id )
+ {
+ //This is a fenceline, parent to the "Roads" node.
+ MDagPath dagPath;
+ if ( MExt::FindDagNodeByName( &dagPath, MString("Roads"), pathToTrackEditor.node() ) )
+ {
+ fnDagNodeTE.setObject( dagPath.node() );
+ }
+ else
+ {
+ MExt::DisplayError( "Someone has deleted Terrain Edit nodes!!" );
+ }
+ }
+ else if ( fnDagNodeObj.typeId() == TETreeLine::TreelineShapeNode::id )
+ {
+ //This is a tree line, add to the "Treelines" node
+ MDagPath dagPath;
+ if ( MExt::FindDagNodeByName( &dagPath, MString("Treelines"), pathToTrackEditor.node() ) )
+ {
+ fnDagNodeTE.setObject( dagPath.node() );
+ }
+ else
+ {
+ MExt::DisplayError( "Someone has deleted Terrain Edit nodes!!" );
+ }
+ }
+ else
+ {
+ fnDagNodeTE.setObject( pathToTrackEditor.node() );
+ }
+
+ MObject objT = fnDagNodeObj.parent( 0 );
+
+ return fnDagNodeTE.addChild( objT );
+ }
+
+ return MS::kFailure;
+}
+
+//Edit mode stuff.
+//==============================================================================
+// TrackEditor::GetEditMode
+//==============================================================================
+// Description: Comment
+//
+// Parameters: ()
+//
+// Return: TrackEditor
+//
+//==============================================================================
+TrackEditor::EditMode TrackEditor::GetEditMode()
+{
+ //Test the track editor radio buttons for their state.
+
+ return sEditMode;
+};
+
+//==============================================================================
+// TrackEditor::SetEditMode
+//==============================================================================
+// Description: Comment
+//
+// Parameters: ( TrackEditor::EditMode mode )
+//
+// Return: void
+//
+//==============================================================================
+void TrackEditor::SetEditMode( TrackEditor::EditMode mode )
+{
+ //Setup whatever needs setting up for the given mode.
+ switch( mode )
+ {
+ case OFF:
+ {
+ RemoveTileDisplayNode();
+
+ MGlobal::executeCommand( MString("teCloseEditorWindow()") );
+ }
+ break;
+ case EDIT:
+ {
+ //Make sure this exists;
+ CreateTileDisplayNode();
+
+ MGlobal::executeCommand( MString("teOpenEditorWindow()") );
+
+ //We should register a callback for when the window is closed.
+ sWindowClosedCallbackID = MUiMessage::addUiDeletedCallback( MString( "TE_TileEditor" ), WindowClosedCB );
+ }
+ break;
+ case DISPLAY:
+ {
+ //Make sure this exists;
+ CreateTileDisplayNode();
+
+ MGlobal::executeCommand( MString("teCloseEditorWindow()") );
+ }
+ break;
+ default:
+ {
+ break;
+ }
+ }
+
+ sEditMode = mode;
+}
+
+//==============================================================================
+// TrackEditor::NodeAddedCB
+//==============================================================================
+// Description: Comment
+//
+// Parameters: ( MObject& node, void* data )
+//
+// Return: void
+//
+//==============================================================================
+void TrackEditor::NodeAddedCB( MObject& node, void* data )
+{
+// assert( false );
+}
+
+//==============================================================================
+// TrackEditor::WindowClosedCB
+//==============================================================================
+// Description: Comment
+//
+// Parameters: ( void* data )
+//
+// Return: void
+//
+//==============================================================================
+void TrackEditor::WindowClosedCB( void* data )
+{
+ SetEditMode( OFF );
+
+ MUiMessage::removeCallback( sWindowClosedCallbackID );
+}
+
+//==============================================================================
+// TrackEditor::CreateTrackEditorNode
+//==============================================================================
+// Description: Comment
+//
+// Parameters: ()
+//
+// Return: void
+//
+//==============================================================================
+void TrackEditor::CreateTrackEditorNode()
+{
+ MGlobal::executeCommand( "te_Create_TrackEditorNode()" );
+}
+
+//==============================================================================
+// TrackEditor::CreateTileDisplayNode
+//==============================================================================
+// Description: Comment
+//
+// Parameters: ()
+//
+// Return: void
+//
+//==============================================================================
+void TrackEditor::CreateTileDisplayNode()
+{
+ if ( !MExt::FindDagNodeByName( NULL, MString( TileDisplayNode::stringId ) ) )
+ {
+ MExt::CreateNode( 0, 0, MString( TileDisplayNode::stringId ) );
+ }
+}
+
+//==============================================================================
+// TrackEditor::RemoveTileDisplayNode
+//==============================================================================
+// Description: Comment
+//
+// Parameters: ()
+//
+// Return: void
+//
+//==============================================================================
+void TrackEditor::RemoveTileDisplayNode()
+{
+ MDagPath dagPath;
+
+ if ( MExt::FindDagNodeByName( &dagPath, MString( TileDisplayNode::stringId ) ) )
+ {
+ MFnDagNode fnDagNode( dagPath );
+
+ MExt::DeleteNode( fnDagNode.object(), true );
+ }
+}
+
diff --git a/tools/trackeditor/code/main/trackeditor.h b/tools/trackeditor/code/main/trackeditor.h
new file mode 100644
index 0000000..d48cba1
--- /dev/null
+++ b/tools/trackeditor/code/main/trackeditor.h
@@ -0,0 +1,85 @@
+#include "precompiled/PCH.h"
+
+#ifndef TRACK_EDITOR
+#define TRACK_EDITOR
+
+//This node exists as the top node of all the other TrackEditor types.
+//See te_setup.mel for more details of how this is a node.
+//There should only ever be one of these in the Hypergraph.
+
+//This is the place where options will be stored also.
+
+class TrackEditor
+{
+public:
+ TrackEditor();
+ ~TrackEditor();
+
+ static const char* Name;
+
+ static bool Exists();
+ static MStatus AddChild( MObject& obj );
+
+ //These are the Track Editing functions and state.
+ enum EditMode
+ {
+ OFF,
+ EDIT,
+ DISPLAY
+ };
+
+ static EditMode GetEditMode();
+
+ static void SetDeleteTreelines( bool del );
+ static bool GetDeleteTreelines();
+
+protected:
+
+ friend class TEStateChangeCommand;
+ static EditMode sEditMode;
+ static void SetEditMode( EditMode mode );
+
+ static bool sDeleteTreelines;
+
+private:
+ static unsigned int sNodeAddedbackID;
+ static unsigned int sWindowClosedCallbackID;
+
+ static void NodeAddedCB( MObject& node, void* data );
+ static void WindowClosedCB( void* data );
+ static void CreateTrackEditorNode();
+ static void CreateTileDisplayNode();
+ static void RemoveTileDisplayNode();
+};
+
+//=============================================================================
+// TrackEditor::SetDeleteTreelines
+//=============================================================================
+// Description: Comment
+//
+// Parameters: ( bool del )
+//
+// Return: void
+//
+//=============================================================================
+inline void TrackEditor::SetDeleteTreelines( bool del )
+{
+ sDeleteTreelines = del;
+}
+
+//=============================================================================
+// TrackEditor::GetDeleteTreelines
+//=============================================================================
+// Description: Comment
+//
+// Parameters: ()
+//
+// Return: bool
+//
+//=============================================================================
+inline bool TrackEditor::GetDeleteTreelines()
+{
+ return sDeleteTreelines;
+}
+
+#endif \ No newline at end of file