From 492f00b729e30f1894095fba17e60da477c8df38 Mon Sep 17 00:00:00 2001 From: Garux Date: Wed, 2 Aug 2017 09:44:51 +0300 Subject: [PATCH] Radiant: misc... * fix scaling for doom3 brush format * Pointfile function: try to also load .pts leak line file (q1), if .lin isn't found * snap transform origin for flip commands * change light intensity save format from %f to %g to prevent .99999 on transforms * support 'stupid quake bug' (invert pitch in angles)(generic and miscmodel ents)(cfg: entities="quake" in .game) * clipper: place 1st and 2nd points far, 3rd near to ease 3 points clipping --- contrib/camera/dialogs.cpp | 3 +++ include/iselection.h | 4 ++-- plugins/entity/angles.h | 8 +++++--- plugins/entity/entity.cpp | 7 +++++++ plugins/entity/entity.h | 3 +++ plugins/entity/light.cpp | 2 +- plugins/entity/plugin.cpp | 28 +++++++++++++++++++++++++++ radiant/brush.h | 8 ++++++-- radiant/brush_primit.cpp | 8 +++++++- radiant/points.cpp | 9 ++++++++- radiant/select.cpp | 10 +++++----- radiant/selection.cpp | 9 +++++++-- radiant/url.cpp | 1 + radiant/xywindow.cpp | 11 ++++++++--- tools/quake3/q3map2/lightmaps_ydnar.c | 1 + 15 files changed, 92 insertions(+), 20 deletions(-) diff --git a/contrib/camera/dialogs.cpp b/contrib/camera/dialogs.cpp index acd2fbd4..2c5be6c2 100644 --- a/contrib/camera/dialogs.cpp +++ b/contrib/camera/dialogs.cpp @@ -602,6 +602,9 @@ static gint ci_add_target( GtkWidget *widget, gpointer data ){ else if ( gtk_toggle_button_get_active( (GtkToggleButton*)spline ) ) { type = 2; } + else{ + break; + } // Add the target GetCurrentCam()->GetCam()->addTarget( str, static_cast( type ) ); diff --git a/include/iselection.h b/include/iselection.h index a62a2843..99310d91 100644 --- a/include/iselection.h +++ b/include/iselection.h @@ -120,8 +120,8 @@ virtual void addSelectionChangeCallback( const SelectionChangeHandler& handler ) virtual void NudgeManipulator( const Vector3& nudge, const Vector3& view ) = 0; virtual void translateSelected( const Vector3& translation ) = 0; -virtual void rotateSelected( const Quaternion& rotation, bool snapOrigin ) = 0; -virtual void scaleSelected( const Vector3& scaling ) = 0; +virtual void rotateSelected( const Quaternion& rotation, bool snapOrigin = false ) = 0; +virtual void scaleSelected( const Vector3& scaling, bool snapOrigin = false ) = 0; virtual void pivotChanged() const = 0; virtual void setCustomPivotOrigin( Vector3& point ) const = 0; diff --git a/plugins/entity/angles.h b/plugins/entity/angles.h index 12fee419..3cfa4e25 100644 --- a/plugins/entity/angles.h +++ b/plugins/entity/angles.h @@ -30,6 +30,8 @@ #include "angle.h" +#include "entity.h" + const Vector3 ANGLESKEY_IDENTITY = Vector3( 0, 0, 0 ); inline void default_angles( Vector3& angles ){ @@ -57,7 +59,7 @@ inline void read_angles( Vector3& angles, const char* value ){ } else { - angles = Vector3( angles[2], angles[0], angles[1] ); + angles = Vector3( angles[2], g_stupidQuakeBug? -angles[0] : angles[0], angles[1] ); normalise_angles( angles ); } } @@ -71,14 +73,14 @@ inline void write_angles( const Vector3& angles, Entity* entity ){ else { if ( angles[0] == 0 && angles[1] == 0 ) { - float yaw = angles[2]; + const float yaw = angles[2]; entity->setKeyValue( "angles", "" ); write_angle( yaw, entity ); } else { char value[64]; - sprintf( value, "%g %g %g", angles[1], angles[2], angles[0] ); + sprintf( value, "%g %g %g", g_stupidQuakeBug? -angles[1] : angles[1], angles[2], angles[0] ); entity->setKeyValue( "angle", "" ); entity->setKeyValue( "angles", value ); } diff --git a/plugins/entity/entity.cpp b/plugins/entity/entity.cpp index 6d81463e..b721c45c 100644 --- a/plugins/entity/entity.cpp +++ b/plugins/entity/entity.cpp @@ -120,6 +120,9 @@ bool g_showTargetNames = false; bool g_showAngles = true; bool g_lightRadii = true; +bool g_stupidQuakeBug = false; + + class ConnectEntities { public: @@ -400,6 +403,10 @@ void Entity_Construct( EGameType gameType ){ Static::instance().m_nameKey = "targetname"; } + if( g_gameType == eGameTypeQuake1 ){ + g_stupidQuakeBug = true; + } + GlobalPreferenceSystem().registerPreference( "SI_ShowNames", BoolImportStringCaller( g_showNames ), BoolExportStringCaller( g_showNames ) ); GlobalPreferenceSystem().registerPreference( "SI_ShowBboxes", BoolImportStringCaller( g_showBboxes ), BoolExportStringCaller( g_showBboxes ) ); GlobalPreferenceSystem().registerPreference( "SI_ShowNamesDist", IntImportStringCaller( g_showNamesDist ), IntExportStringCaller( g_showNamesDist ) ); diff --git a/plugins/entity/entity.h b/plugins/entity/entity.h index a27e4e86..3a748494 100644 --- a/plugins/entity/entity.h +++ b/plugins/entity/entity.h @@ -28,6 +28,7 @@ EntityCreator& GetEntityCreator(); enum EGameType { eGameTypeQuake3, + eGameTypeQuake1, eGameTypeRTCW, eGameTypeDoom3, }; @@ -46,4 +47,6 @@ extern bool g_showTargetNames; extern bool g_showAngles; extern bool g_lightRadii; +extern bool g_stupidQuakeBug; + #endif diff --git a/plugins/entity/light.cpp b/plugins/entity/light.cpp index a34d92b1..91ca3ba9 100644 --- a/plugins/entity/light.cpp +++ b/plugins/entity/light.cpp @@ -673,7 +673,7 @@ void light_draw( const AABB& aabb_light, RenderStateFlags state ){ inline void write_intensity( const float intensity, Entity* entity ){ char value[64]; - sprintf( value, "%f", intensity ); + sprintf( value, "%g", intensity ); //primaryIntensity if( !string_empty( entity->getKeyValue( "_light" ) ) ){ diff --git a/plugins/entity/plugin.cpp b/plugins/entity/plugin.cpp index e8131e0b..6aacecd5 100644 --- a/plugins/entity/plugin.cpp +++ b/plugins/entity/plugin.cpp @@ -86,6 +86,33 @@ typedef SingletonModule EntityQ3Module; EntityQ3Module g_EntityQ3Module; +class EntityQ1API : public TypeSystemRef +{ +EntityCreator* m_entityq1; +public: +typedef EntityCreator Type; +STRING_CONSTANT( Name, "quake" ); + +EntityQ1API(){ + Entity_Construct( eGameTypeQuake1); + + m_entityq1 = &GetEntityCreator(); + + GlobalReferenceCache().setEntityCreator( *m_entityq1 ); +} +~EntityQ1API(){ + Entity_Destroy(); +} +EntityCreator* getTable(){ + return m_entityq1; +} +}; + +typedef SingletonModule EntityQ1Module; + +EntityQ1Module g_EntityQ1Module; + + class EntityWolfAPI : public TypeSystemRef { EntityCreator* m_entitywolf; @@ -144,6 +171,7 @@ extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server initialiseModule( server ); g_EntityQ3Module.selfRegister(); + g_EntityQ1Module.selfRegister(); g_EntityWolfModule.selfRegister(); g_EntityDoom3Module.selfRegister(); Doom3ModelSkinCacheModule_selfRegister( server ); diff --git a/radiant/brush.h b/radiant/brush.h index 877300a6..ec122141 100644 --- a/radiant/brush.h +++ b/radiant/brush.h @@ -632,8 +632,12 @@ inline Plane3 Plane3_applyTranslation( const Plane3& plane, const Vector3& trans } inline Plane3 Plane3_applyTransform( const Plane3& plane, const Matrix4& matrix ){ - Plane3 tmp( plane3_transformed( Plane3( plane.normal(), -plane.dist() ), matrix ) ); - return Plane3( tmp.normal(), -tmp.dist() ); + //Plane3 tmp( plane3_transformed( Plane3( plane.normal(), -plane.dist() ), matrix ) ); + //return Plane3( tmp.normal(), -tmp.dist() ); + Vector4 anchor = matrix4_transformed_vector4( matrix, Vector4( plane.normal() * plane.dist(), 1 ) ); + Matrix4 mat = matrix4_transposed( matrix4_full_inverse( matrix ) ); + Vector4 normal = matrix4_transformed_vector4( mat, Vector4( plane.normal(), 0 ) ); + return plane3_normalised( Plane3( vector4_to_vector3( normal ), vector3_dot( vector4_to_vector3( normal ), vector4_to_vector3( anchor ) ) ) ); } class FacePlane diff --git a/radiant/brush_primit.cpp b/radiant/brush_primit.cpp index a002358d..db7aee12 100644 --- a/radiant/brush_primit.cpp +++ b/radiant/brush_primit.cpp @@ -1305,8 +1305,14 @@ void Texdef_transformLocked( TextureProjection& projection, std::size_t width, s //globalOutputStream() << "identity2transformed: " << identity2transformed << "\n"; //globalOutputStream() << "plane.normal(): " << plane.normal() << "\n"; - +#if 1 Vector3 normalTransformed( matrix4_transformed_direction( identity2transformed, plane.normal() ) ); +#else //preserves scale in BP while scaling, but not shift + Matrix4 maa( matrix4_affine_inverse( identity2transformed ) ); + matrix4_transpose( maa ); + Vector4 vec4 = matrix4_transformed_vector4( maa, Vector4( plane.normal(), 0 ) ); + Vector3 normalTransformed = vector3_normalised( vector4_to_vector3( vec4 ) ); +#endif //globalOutputStream() << "normalTransformed: " << normalTransformed << "\n"; diff --git a/radiant/points.cpp b/radiant/points.cpp index eb60e6b0..70feea2a 100644 --- a/radiant/points.cpp +++ b/radiant/points.cpp @@ -272,7 +272,14 @@ void Pointfile_Parse( CPointfile& pointfile ){ size = LoadFile( name.c_str(), (void**)&data ); if ( size == -1 ) { globalErrorStream() << "Pointfile " << name.c_str() << " not found\n"; - return; + /* try .pts (q1) */ + name.clear(); + name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".pts"; + size = LoadFile( name.c_str(), (void**)&data ); + if ( size == -1 ) { + globalErrorStream() << "Pointfile " << name.c_str() << " not found\n"; + return; + } } // store a pointer diff --git a/radiant/select.cpp b/radiant/select.cpp index d23aaca3..19ee8be6 100644 --- a/radiant/select.cpp +++ b/radiant/select.cpp @@ -548,7 +548,7 @@ void Select_GetMid( Vector3& mid ){ void Select_FlipAxis( int axis ){ Vector3 flip( 1, 1, 1 ); flip[axis] = -1; - GlobalSelectionSystem().scaleSelected( flip ); + GlobalSelectionSystem().scaleSelected( flip, true ); } @@ -652,13 +652,13 @@ void Select_RotateAxis( int axis, float deg ){ switch ( axis ) { case 0: - GlobalSelectionSystem().rotateSelected( quaternion_for_matrix4_rotation( matrix4_rotation_for_x_degrees( deg ) ), false ); + GlobalSelectionSystem().rotateSelected( quaternion_for_matrix4_rotation( matrix4_rotation_for_x_degrees( deg ) ) ); break; case 1: - GlobalSelectionSystem().rotateSelected( quaternion_for_matrix4_rotation( matrix4_rotation_for_y_degrees( deg ) ), false ); + GlobalSelectionSystem().rotateSelected( quaternion_for_matrix4_rotation( matrix4_rotation_for_y_degrees( deg ) ) ); break; case 2: - GlobalSelectionSystem().rotateSelected( quaternion_for_matrix4_rotation( matrix4_rotation_for_z_degrees( deg ) ), false ); + GlobalSelectionSystem().rotateSelected( quaternion_for_matrix4_rotation( matrix4_rotation_for_z_degrees( deg ) ) ); break; } } @@ -1190,7 +1190,7 @@ static gboolean rotatedlg_apply( GtkWidget *widget, RotateDialog* rotateDialog ) command << "rotateSelectedEulerXYZ -x " << eulerXYZ[0] << " -y " << eulerXYZ[1] << " -z " << eulerXYZ[2]; UndoableCommand undo( command.c_str() ); - GlobalSelectionSystem().rotateSelected( quaternion_for_euler_xyz_degrees( eulerXYZ ), false ); + GlobalSelectionSystem().rotateSelected( quaternion_for_euler_xyz_degrees( eulerXYZ ) ); return TRUE; } diff --git a/radiant/selection.cpp b/radiant/selection.cpp index 71c6e5b8..6681c37e 100644 --- a/radiant/selection.cpp +++ b/radiant/selection.cpp @@ -3459,7 +3459,7 @@ void outputScale( TextOutputStream& ostream ){ ostream << " -scale " << m_scale.x() << " " << m_scale.y() << " " << m_scale.z(); } -void rotateSelected( const Quaternion& rotation, bool snapOrigin ){ +void rotateSelected( const Quaternion& rotation, bool snapOrigin = false ){ if( snapOrigin && !m_pivotIsCustom ){ m_pivot2world.tx() = float_snapped( m_pivot2world.tx(), GetSnapGridSize() ); m_pivot2world.ty() = float_snapped( m_pivot2world.ty(), GetSnapGridSize() ); @@ -3474,7 +3474,12 @@ void translateSelected( const Vector3& translation ){ translate( translation ); freezeTransforms(); } -void scaleSelected( const Vector3& scaling ){ +void scaleSelected( const Vector3& scaling, bool snapOrigin = false ){ + if( snapOrigin && !m_pivotIsCustom ){ + m_pivot2world.tx() = float_snapped( m_pivot2world.tx(), GetSnapGridSize() ); + m_pivot2world.ty() = float_snapped( m_pivot2world.ty(), GetSnapGridSize() ); + m_pivot2world.tz() = float_snapped( m_pivot2world.tz(), GetSnapGridSize() ); + } startMove(); scale( scaling ); freezeTransforms(); diff --git a/radiant/url.cpp b/radiant/url.cpp index e5abc077..3f46768c 100644 --- a/radiant/url.cpp +++ b/radiant/url.cpp @@ -36,6 +36,7 @@ bool open_url( const char* url ){ #include bool open_url( const char* url ){ // \todo FIXME: the way we open URLs on *nix should be improved. A script is good (see how I do on RTCW) + //Fedora 25: Help > Manual leads to "sh: firefox: command not found" error on terminal, while xdg-open http://some/url/ works just fine (and opens up the URL in the web browser) char command[2 * PATH_MAX]; snprintf( command, sizeof( command ), "firefox -remote \"openURL(%s,new-window)\" || firefox \"%s\" &", url, url ); diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index cc9c4d64..15eebf5e 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -970,11 +970,16 @@ void XYWnd::DropClipPoint( int pointx, int pointy ){ XY_ToPoint( pointx, pointy, point ); - Vector3 mid; - Select_GetMid( mid ); + Vector3 mins, maxs; + Select_GetBounds( mins, maxs ); g_clip_viewtype = GetViewType(); const int nDim = ( g_clip_viewtype == YZ ) ? 0 : ( ( g_clip_viewtype == XZ ) ? 1 : 2 ); - point[nDim] = mid[nDim]; + if( g_Clip2.Set() && !g_Clip3.Set() ){ + point[nDim] = maxs[nDim]; + } + else{ + point[nDim] = mins[nDim]; + } vector3_snap( point, GetSnapGridSize() ); NewClipPoint( point ); } diff --git a/tools/quake3/q3map2/lightmaps_ydnar.c b/tools/quake3/q3map2/lightmaps_ydnar.c index f8b52105..76cad9ac 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.c +++ b/tools/quake3/q3map2/lightmaps_ydnar.c @@ -1382,6 +1382,7 @@ void StitchSurfaceLightmaps( void ){ /* add luxel */ //% VectorSet( luxel2, 255, 0, 255 ); + numLuxels++; VectorAdd( average, luxel2, average ); totalColor += luxel2[ 3 ]; }