From 30277762436a37ddd0e38ce820ef18759770570d Mon Sep 17 00:00:00 2001 From: Mateos81 Date: Wed, 11 Nov 2015 11:56:29 +0100 Subject: [PATCH] Make NULL models rendered as a box, and selectable (were already editable) TODO: - Handle the case "Model not found". - Add relevant console prints. - Fix glitchy-looking selected box. --- include/imodel.h | 1 + plugins/entity/entity_entitymodel.h | 2 ++ plugins/model/cpicomodel.h | 1 + plugins/model/remap.cpp | 6 ++++++ plugins/spritemodel/spritemodel.h | 1 + radiant/brush.cpp | 3 ++- radiant/camwindow.cpp | 16 ++++++++++++++-- 7 files changed, 27 insertions(+), 3 deletions(-) diff --git a/include/imodel.h b/include/imodel.h index 65d88678..2ae1e631 100644 --- a/include/imodel.h +++ b/include/imodel.h @@ -77,6 +77,7 @@ virtual ~IRender() { } virtual void IncRef() = 0; // increments the reference counter for this object virtual void DecRef() = 0; // decrements the reference counter for this object, deletes the object if reference count is zero virtual void Draw( int state, int rflags ) const = 0; // render the object - state = the opengl state +virtual const bool IsModelNotNull() const = 0; virtual const aabb_t *GetAABB() const = 0; }; diff --git a/plugins/entity/entity_entitymodel.h b/plugins/entity/entity_entitymodel.h index f523630b..f3b49324 100644 --- a/plugins/entity/entity_entitymodel.h +++ b/plugins/entity/entity_entitymodel.h @@ -40,6 +40,7 @@ void DecRef() { // IRender void Draw( int state, int rflags ) const; +const bool IsModelNotNull() const { return m_model && m_model->pRender; } const aabb_t *GetAABB() const { return &m_BBox; } // ISelect @@ -105,6 +106,7 @@ void DecRef() { // IRender void Draw( int state, int rflags ) const; +const bool IsModelNotNull() const { return m_model && m_model->pRender; } const aabb_t *GetAABB() const { return &m_BBox; } // ISelect diff --git a/plugins/model/cpicomodel.h b/plugins/model/cpicomodel.h index a5556f24..6432eb9d 100644 --- a/plugins/model/cpicomodel.h +++ b/plugins/model/cpicomodel.h @@ -66,6 +66,7 @@ void Reload( void ); void Draw( int state, vector shaders, int rflags ) const; //IRender virtual void Draw( int state, int rflags ) const; +virtual const bool IsModelNotNull() const { return true; } virtual const aabb_t *GetAABB() const { return &m_BBox; } //ISelect diff --git a/plugins/model/remap.cpp b/plugins/model/remap.cpp index 5e313222..69683eae 100644 --- a/plugins/model/remap.cpp +++ b/plugins/model/remap.cpp @@ -141,6 +141,9 @@ virtual void DecRef(){ virtual void Draw( int state, int rflags ) const { m_model->Draw( state, m_shaders, rflags ); } +virtual const bool IsModelNotNull() const { + return m_model != NULL; +} virtual const aabb_t *GetAABB() const { return m_model->GetAABB(); } @@ -300,6 +303,9 @@ virtual void DecRef(){ virtual void Draw( int state, int rflags ) const { m_model->Draw( state, rflags ); } +virtual const bool IsModelNotNull() const { + return m_model != NULL; +} virtual const aabb_t *GetAABB() const { return m_model->GetAABB(); } diff --git a/plugins/spritemodel/spritemodel.h b/plugins/spritemodel/spritemodel.h index d9be5152..34015df5 100644 --- a/plugins/spritemodel/spritemodel.h +++ b/plugins/spritemodel/spritemodel.h @@ -45,6 +45,7 @@ void DecRef() { //IRender void Draw( int state, int rflags ) const; +const bool IsModelNotNull() const { return true; } const aabb_t *GetAABB() const { return &m_BBox; } //ISelect diff --git a/radiant/brush.cpp b/radiant/brush.cpp index 05ec12fb..6b3d3bbf 100644 --- a/radiant/brush.cpp +++ b/radiant/brush.cpp @@ -2223,7 +2223,8 @@ face_t *Brush_Ray( vec3_t origin, vec3_t dir, brush_t *b, float *dist, int nFlag if ( b->owner->eclass->fixedsize && b->owner->model.pSelect && !( !IsBrushSelected( b ) && ( g_PrefsDlg.m_nEntityShowState & ENTITY_SELECTED_ONLY ) ) - && g_PrefsDlg.m_nEntityShowState != ENTITY_BOX ) { + && g_PrefsDlg.m_nEntityShowState != ENTITY_BOX + && b->owner->model.pRender->IsModelNotNull()) { ray_t ray_local; vec_t dist_local = FLT_MAX; ray_construct_for_vec3( &ray_local, origin, dir ); diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index 8a952be0..466fa612 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -922,12 +922,24 @@ void CamWnd::Cam_DrawBrush( brush_t *b, int mode ){ if ( !( nGLState & DRAW_GL_TEXTURE_2D ) ) { qglColor4fv( material ); } - else{ qglColor4fv( identity ); } + else { + qglColor4fv( identity ); + } + if ( nGLState & DRAW_GL_LIGHTING ) { qglShadeModel( GL_SMOOTH ); } - b->owner->model.pRender->Draw( nGLState, DRAW_RF_CAM ); + // Check model validity + // If the model is NULL or invalid, draw a box instead + bool temp = b->owner->model.pRender->IsModelNotNull(); + if ( temp ) { + b->owner->model.pRender->Draw(nGLState, DRAW_RF_CAM); + } + else { + qglColor4fv( material ); + aabb_draw( b->owner->model.pRender->GetAABB(), DRAW_GL_WIRE ); + } } break; case DRAW_WIRE: