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