more csg tool refactoring
This commit is contained in:
parent
53676dcf31
commit
abcc47ad64
101
radiant/csg.cpp
101
radiant/csg.cpp
|
|
@ -77,11 +77,11 @@ public:
|
|||
// true = exclude by axis strategy, false = m_excludeSelectedFaces by 'selected' property
|
||||
bool m_excludeByAxis;
|
||||
Vector3 m_exclusionAxis;
|
||||
double m_mindot;
|
||||
double m_maxdot;
|
||||
mutable double m_mindot;
|
||||
mutable double m_maxdot;
|
||||
// true = exclude selected faces, false = exclude unselected faces
|
||||
bool m_excludeSelectedFaces;
|
||||
std::vector<DoubleVector3> m_exclude_vec; // list of excluded normals per brush
|
||||
mutable std::vector<DoubleVector3> m_exclude_vec; // list of excluded normals per brush
|
||||
|
||||
bool m_caulk;
|
||||
bool m_removeInner;
|
||||
|
|
@ -94,33 +94,28 @@ public:
|
|||
return std::find( m_exclude_vec.begin(), m_exclude_vec.end(), face.getPlane().plane3().normal() ) != m_exclude_vec.end();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class FaceExcludeByAxis {
|
||||
HollowSettings& m_settings;
|
||||
public:
|
||||
FaceExcludeByAxis( HollowSettings& settings ) : m_settings( settings ) {
|
||||
void excludeFaces( BrushInstance& brushInstance ){
|
||||
if( m_excludeByAxis ) {
|
||||
m_mindot = m_maxdot = 0;
|
||||
Brush_forEachFace( brushInstance.getBrush(), *this );
|
||||
}
|
||||
else{
|
||||
m_exclude_vec.clear();
|
||||
Brush_ForEachFaceInstance( brushInstance, *this );
|
||||
}
|
||||
}
|
||||
void operator()( Face& face ) const {
|
||||
double dot = vector3_dot( face.getPlane().plane3().normal(), m_settings.m_exclusionAxis );
|
||||
if( dot < m_settings.m_mindot ) {
|
||||
m_settings.m_mindot = dot;
|
||||
const double dot = vector3_dot( face.getPlane().plane3().normal(), m_exclusionAxis );
|
||||
if( dot < m_mindot ) {
|
||||
m_mindot = dot;
|
||||
}
|
||||
else if( dot > m_settings.m_maxdot ) {
|
||||
m_settings.m_maxdot = dot;
|
||||
else if( dot > m_maxdot ) {
|
||||
m_maxdot = dot;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class FaceExcludeSelected {
|
||||
HollowSettings& m_settings;
|
||||
public:
|
||||
FaceExcludeSelected( HollowSettings& settings ) : m_settings( settings ) {
|
||||
}
|
||||
void operator()( FaceInstance& face ) const {
|
||||
if( m_settings.m_excludeSelectedFaces == face.isSelected() ) {
|
||||
m_settings.m_exclude_vec.push_back( face.getFace().getPlane().plane3().normal() );
|
||||
if( m_excludeSelectedFaces == face.isSelected() ) {
|
||||
m_exclude_vec.push_back( face.getFace().getPlane().plane3().normal() );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -208,10 +203,8 @@ public:
|
|||
Winding& winding = face.getWinding();
|
||||
TextureProjection projection;
|
||||
TexDef_Construct_Default( projection );
|
||||
for( Winding::iterator j = winding.begin(); j != winding.end(); ++j ) {
|
||||
std::size_t index = std::distance( winding.begin(), j );
|
||||
std::size_t next = Winding_next( winding, index );
|
||||
|
||||
for( std::size_t index = 0; index < winding.numpoints; ++index ){
|
||||
const std::size_t next = Winding_next( winding, index );
|
||||
m_out.back()->addPlane( winding[index].vertex,
|
||||
winding[next].vertex,
|
||||
winding[next].vertex + face.getPlane().plane3().normal() * m_settings.m_offset,
|
||||
|
|
@ -240,29 +233,27 @@ public:
|
|||
newFace->planeChanged();
|
||||
}
|
||||
|
||||
Winding& winding = face.getWinding();
|
||||
const Winding& winding = face.getWinding();
|
||||
TextureProjection projection;
|
||||
TexDef_Construct_Default( projection );
|
||||
for( Winding::iterator i = winding.begin(); i != winding.end(); ++i ) {
|
||||
std::size_t index = std::distance( winding.begin(), i );
|
||||
std::size_t next = Winding_next( winding, index );
|
||||
for( std::size_t index = 0; index < winding.numpoints; ++index ){
|
||||
const std::size_t next = Winding_next( winding, index );
|
||||
Vector3 BestPoint;
|
||||
float bestdist = 999999;
|
||||
|
||||
Face* parallel_face = 0;
|
||||
for( Brush::const_iterator j = m_brush.begin(); j != m_brush.end(); ++j ) {
|
||||
if( vector3_equal_epsilon( face.getPlane().plane3().normal(), ( *j )->getPlane().plane3().normal(), 1e-6 ) ){
|
||||
parallel_face = ( *j );
|
||||
const Face* parallel_face = nullptr;
|
||||
for( const Face* f : m_brush ) {
|
||||
if( vector3_equal_epsilon( face.getPlane().plane3().normal(), f->getPlane().plane3().normal(), c_PLANE_NORMAL_EPSILON ) ){
|
||||
parallel_face = f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( parallel_face ){
|
||||
Winding& winding2 = parallel_face->getWinding();
|
||||
if( parallel_face != nullptr ){
|
||||
const Winding& winding2 = parallel_face->getWinding();
|
||||
float bestdot = -1;
|
||||
for( Winding::iterator k = winding2.begin(); k != winding2.end(); ++k ) {
|
||||
std::size_t index2 = std::distance( winding2.begin(), k );
|
||||
float dot = vector3_dot(
|
||||
for( std::size_t index2 = 0; index2 < winding2.numpoints; ++index2 ){
|
||||
const float dot = vector3_dot(
|
||||
vector3_normalised(
|
||||
vector3_cross(
|
||||
winding[index].vertex - winding[next].vertex,
|
||||
|
|
@ -278,11 +269,10 @@ public:
|
|||
}
|
||||
}
|
||||
else{
|
||||
for( Brush::const_iterator j = m_brush.begin(); j != m_brush.end(); ++j ) {
|
||||
Winding& winding2 = ( *j )->getWinding();
|
||||
for( Winding::iterator k = winding2.begin(); k != winding2.end(); ++k ) {
|
||||
std::size_t index2 = std::distance( winding2.begin(), k );
|
||||
float testdist = vector3_length( winding[index].vertex - winding2[index2].vertex );
|
||||
for( const Face* f : m_brush ) {
|
||||
const Winding& winding2 = f->getWinding();
|
||||
for( std::size_t index2 = 0; index2 < winding2.numpoints; ++index2 ){
|
||||
const float testdist = vector3_length( winding[index].vertex - winding2[index2].vertex );
|
||||
if( testdist < bestdist ) {
|
||||
bestdist = testdist;
|
||||
BestPoint = winding2[index2].vertex;
|
||||
|
|
@ -332,16 +322,8 @@ public:
|
|||
Brush* brush = Node_getBrush( path.top() );
|
||||
if( brush != 0
|
||||
&& ( Instance_isSelected( instance ) || Instance_isSelectedComponents( instance ) ) ) {
|
||||
m_settings.excludeFaces( *Instance_getBrush( instance ) );
|
||||
brush_vector_t out;
|
||||
m_settings.m_exclude_vec.clear();
|
||||
m_settings.m_mindot = m_settings.m_maxdot = 0;
|
||||
|
||||
if( m_settings.m_excludeByAxis ) {
|
||||
Brush_forEachFace( *brush, FaceExcludeByAxis( m_settings ) );
|
||||
}
|
||||
else {
|
||||
Brush_ForEachFaceInstance( *Instance_getBrush( instance ), FaceExcludeSelected( m_settings ) );
|
||||
}
|
||||
|
||||
if( m_settings.m_hollowType == ePull ) {
|
||||
if( !m_settings.m_removeInner && m_settings.m_caulk ) {
|
||||
|
|
@ -1366,14 +1348,7 @@ public:
|
|||
}
|
||||
void operator()( BrushInstance& brush ) const {
|
||||
if( brush.isSelected() || brush.isSelectedComponents() ){
|
||||
m_settings.m_mindot = m_settings.m_maxdot = 0;
|
||||
m_settings.m_exclude_vec.clear();
|
||||
if( m_settings.m_excludeByAxis ) {
|
||||
Brush_forEachFace( brush, FaceExcludeByAxis( m_settings ) );
|
||||
}
|
||||
else {
|
||||
Brush_ForEachFaceInstance( brush, FaceExcludeSelected( m_settings ) );
|
||||
}
|
||||
m_settings.excludeFaces( brush );
|
||||
Brush_forEachFace( brush, FaceOffset( m_settings ) );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user