}
-typedef const Plane3* PlanePointer;
-typedef PlanePointer* PlanesIterator;
-
class VectorLightList : public LightList
{
typedef std::vector<const RendererLight*> Lights;
}
}
-void selectPlane( Selector& selector, const Line& line, PlanesIterator first, PlanesIterator last, const PlaneCallback& selectedPlaneCallback ){
+void selectPlane( Selector& selector, const Line& line, const PlaneCallback& selectedPlaneCallback ){
for ( Winding::const_iterator i = getFace().getWinding().begin(); i != getFace().getWinding().end(); ++i )
{
Vector3 v( vector3_subtracted( line_closest_point( line, ( *i ).vertex ), ( *i ).vertex ) );
}
}
+bool trySelectPlane( const Line& line ){
+ for ( Winding::const_iterator i = getFace().getWinding().begin(); i != getFace().getWinding().end(); ++i ){
+ Vector3 v( vector3_subtracted( line_closest_point( line, ( *i ).vertex ), ( *i ).vertex ) );
+ double dot = vector3_dot( getFace().plane3().normal(), v );
+ if ( dot <= 0 ) {
+ return false;
+ }
+ }
+ return true;
+}
+
void transformComponents( const Matrix4& matrix ){
if ( isSelected() ) {
m_face->transform( matrix, false );
Selector_add( selector, *this, best );
}
}
+
+void selectVerticesOnPlanes( SelectionTest& test ){
+ Line line( test.getNear(), test.getFar() );
+ FaceVertexId faceVertex = m_vertex->m_faceVertex;
+ do
+ {
+ if( m_faceInstances[faceVertex.getFace()].trySelectPlane( line ) ){
+ //m_faceInstances[faceVertex.getFace()].select_vertex( faceVertex.getVertex(), true );
+ setSelected( true );
+ }
+ faceVertex = next_vertex( m_vertex->m_faces, faceVertex );
+ }
+ while ( faceVertex.getFace() != m_vertex->m_faceVertex.getFace() );
+}
};
class BrushInstanceVisitor
void selectPlanes( Selector& selector, SelectionTest& test, const PlaneCallback& selectedPlaneCallback ){
test.BeginMesh( localToWorld() );
- PlanePointer brushPlanes[c_brush_maxFaces];
- PlanesIterator j = brushPlanes;
-
- for ( Brush::const_iterator i = m_brush.begin(); i != m_brush.end(); ++i )
- {
- *j++ = &( *i )->plane3();
- }
-
for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i )
{
- ( *i ).selectPlane( selector, Line( test.getNear(), test.getFar() ), brushPlanes, j, selectedPlaneCallback );
+ ( *i ).selectPlane( selector, Line( test.getNear(), test.getFar() ), selectedPlaneCallback );
}
}
void selectReversedPlanes( Selector& selector, const SelectedPlanes& selectedPlanes ){
}
+void selectVerticesOnPlanes( SelectionTest& test ){
+ test.BeginMesh( localToWorld() );
+
+ for ( VertexInstances::iterator i = m_vertexInstances.begin(); i != m_vertexInstances.end(); ++i ){
+ ( *i ).selectVerticesOnPlanes( test );
+ }
+}
+
+
void transformComponents( const Matrix4& matrix ){
for ( FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i )
{
return !selectedPlanes.empty();
}
+
+#include "brush.h"
+/*
+class TestedBrushPlanesSelectVeritces : public scene::Graph::Walker
+{
+SelectionTest& m_test;
+public:
+TestedBrushPlanesSelectVeritces( SelectionTest& test )
+ : m_test( test ){
+}
+bool pre( const scene::Path& path, scene::Instance& instance ) const {
+ if ( path.top().get().visible() ) {
+ Selectable* selectable = Instance_getSelectable( instance );
+ if ( selectable != 0 && selectable->isSelected() ) {
+ BrushInstance* brushInstance = Instance_getBrush( instance );
+ if ( brushInstance != 0 ) {
+ brushInstance->selectVerticesOnPlanes( m_test );
+ }
+ }
+ }
+ return true;
+}
+};
+
+void Scene_forEachTestedBrushPlane_selectVertices( scene::Graph& graph, SelectionTest& test ){
+ graph.traverse( TestedBrushPlanesSelectVeritces( test ) );
+}
+*/
+class BrushPlanesSelectVeritces : public scene::Graph::Walker
+{
+SelectionTest& m_test;
+public:
+BrushPlanesSelectVeritces( SelectionTest& test )
+ : m_test( test ){
+}
+bool pre( const scene::Path& path, scene::Instance& instance ) const {
+ if ( path.top().get().visible() ) {
+ Selectable* selectable = Instance_getSelectable( instance );
+ if ( selectable != 0 && selectable->isSelected() ) {
+ BrushInstance* brushInstance = Instance_getBrush( instance );
+ if ( brushInstance != 0 ) {
+ brushInstance->selectVerticesOnPlanes( m_test );
+ }
+ }
+ }
+ return true;
+}
+};
+
+void Scene_forEachBrushPlane_selectVertices( scene::Graph& graph, SelectionTest& test ){
+ graph.traverse( BrushPlanesSelectVeritces( test ) );
+}
+
void Scene_Translate_Component_Selected( scene::Graph& graph, const Vector3& translation );
void Scene_Translate_Selected( scene::Graph& graph, const Vector3& translation );
void Scene_TestSelect_Primitive( Selector& selector, SelectionTest& test, const VolumeTest& volume );
}
};
+class DeepBestSelector : public Selector
+{
+SelectionIntersection m_intersection;
+Selectable* m_selectable;
+SelectionIntersection m_bestIntersection;
+std::list<Selectable*> m_bestSelectable;
+public:
+DeepBestSelector() : m_bestIntersection( SelectionIntersection() ), m_bestSelectable( 0 ){
+}
+
+void pushSelectable( Selectable& selectable ){
+ m_intersection = SelectionIntersection();
+ m_selectable = &selectable;
+}
+void popSelectable(){
+ if ( m_intersection.equalEpsilon( m_bestIntersection, 0.25f, 2.f ) ) {
+ m_bestSelectable.push_back( m_selectable );
+ m_bestIntersection = m_intersection;
+ }
+ else if ( m_intersection < m_bestIntersection ) {
+ m_bestSelectable.clear();
+ m_bestSelectable.push_back( m_selectable );
+ m_bestIntersection = m_intersection;
+ }
+ m_intersection = SelectionIntersection();
+}
+void addIntersection( const SelectionIntersection& intersection ){
+ assign_if_closer( m_intersection, intersection );
+}
+
+std::list<Selectable*>& best(){
+ return m_bestSelectable;
+}
+};
+
+bool g_bAltDragManipulatorResize = false;
+
class DragManipulator : public Manipulator
{
TranslateFree m_freeResize;
TranslateFree m_freeDrag;
ResizeTranslatable m_resize;
DragTranslatable m_drag;
-SelectableBool m_dragSelectable;
+SelectableBool m_dragSelectable; //drag already selected stuff
public:
-bool m_selected;
+bool m_selected; //selected temporally for drag
DragManipulator() : m_freeResize( m_resize ), m_freeDrag( m_drag ), m_selected( false ){
}
Manipulatable* GetManipulatable(){
- //globalOutputStream() << ( m_dragSelectable.isSelected() ? "m_freeDrag\n" : "m_freeResize\n" );
return m_dragSelectable.isSelected() ? &m_freeDrag : &m_freeResize;
}
Scene_TestSelect_Primitive( booleanSelector, test, view );
if ( booleanSelector.isSelected() ) {
- selector.addSelectable( SelectionIntersection( 0, 0 ), &m_dragSelectable );
- m_selected = false;
+ if( g_bAltDragManipulatorResize ){
+ DeepBestSelector deepSelector;
+ Scene_TestSelect_Component_Selected( deepSelector, test, view, SelectionSystem::eVertex );
+ for ( std::list<Selectable*>::iterator i = deepSelector.best().begin(); i != deepSelector.best().end(); ++i )
+ {
+ if ( !( *i )->isSelected() ) {
+ GlobalSelectionSystem().setSelectedAllComponents( false );
+ }
+ selector.addSelectable( SelectionIntersection( 0, 0 ), ( *i ) );
+ m_selected = true;
+ m_dragSelectable.setSelected( false );
+ }
+ if( deepSelector.best().empty() ){
+ //Scene_forEachTestedBrushPlane_selectVertices( GlobalSceneGraph(), test ); //todo? drag clicked face
+ Scene_forEachBrushPlane_selectVertices( GlobalSceneGraph(), test );
+ m_selected = true;
+ }
+ }
+ else{
+ selector.addSelectable( SelectionIntersection( 0, 0 ), &m_dragSelectable );
+ m_selected = false;
+ }
}
else
{
- m_selected = Scene_forEachPlaneSelectable_selectPlanes( GlobalSceneGraph(), selector, test );
+ if( g_bAltDragManipulatorResize ){
+ Scene_forEachBrushPlane_selectVertices( GlobalSceneGraph(), test );
+ m_selected = true;
+ }
+ else{
+ m_selected = Scene_forEachPlaneSelectable_selectPlanes( GlobalSceneGraph(), selector, test );
+ }
}
}
else
if ( Mode() == ePrimitive ) {
if ( ManipulatorMode() == eDrag ) {
- Scene_SelectAll_Component( false, SelectionSystem::eFace );
+ if( g_bAltDragManipulatorResize ){
+ Scene_SelectAll_Component( false, SelectionSystem::eVertex );
+ }
+ else{
+ Scene_SelectAll_Component( false, SelectionSystem::eFace );
+ }
}
}
//m_selector.m_mouseMoved = false;
DeviceVector devicePosition( window_to_normalised_device( position, m_width, m_height ) );
- if ( modifiers == c_modifier_manipulator && m_manipulator.mouseDown( devicePosition ) ) {
+ g_bAltDragManipulatorResize = ( modifiers == c_modifierAlt ) ? true : false;
+ if ( ( modifiers == c_modifier_manipulator || modifiers == c_modifierAlt ) && m_manipulator.mouseDown( devicePosition ) ) {
g_mouseMovedCallback.insert( MouseEventCallback( Manipulator_::MouseMovedCaller( m_manipulator ) ) );
g_mouseUpCallback.insert( MouseEventCallback( Manipulator_::MouseUpCaller( m_manipulator ) ) );
}