@@ -104,6 +104,7 @@ void CurveEditor::refreshPoint( unsigned int pointIndex, const Vector3& newPoint
104104 auto pointComponent = m_pointEntities[pointIndex];
105105 auto pointColor = pointComponent->m_color ;
106106 auto pointCurve = pointComponent->m_curveId ;
107+ auto pointState = pointComponent->m_state ;
107108 Vector3 point;
108109 if ( newPoint == Vector3::Zero () )
109110 point = pointComponent->m_point ;
@@ -112,6 +113,7 @@ void CurveEditor::refreshPoint( unsigned int pointIndex, const Vector3& newPoint
112113 removeComponent ( m_pointEntities[pointIndex]->getName () );
113114 auto pointEntity =
114115 PointFactory::createPointComponent ( this , point, pointCurve, pointName, pointColor );
116+ pointEntity->m_state = pointState;
115117 m_pointEntities[pointIndex] = pointEntity;
116118}
117119
@@ -152,11 +154,14 @@ void CurveEditor::updateCurves( bool onRelease ) {
152154}
153155
154156Transform CurveEditor::computePointTransform ( PointComponent* pointCmp,
155- const Vector3& midPoint ,
157+ PointComponent* midPointCmp ,
156158 const Vector3& worldPos ) {
157159 auto transform = Transform::Identity ();
160+ auto midPoint = midPointCmp->m_point ;
158161 Vector3 diff = ( midPoint - worldPos );
159- if ( m_symetry ) { transform.translate ( ( midPoint + diff ) - pointCmp->m_defaultPoint ); }
162+ if ( midPointCmp->m_state == PointComponent::SYMETRIC ) {
163+ transform.translate ( ( midPoint + diff ) - pointCmp->m_defaultPoint );
164+ }
160165 else {
161166 diff.normalize ();
162167 auto actualdiff = diff * ( midPoint - pointCmp->m_point ).norm ();
@@ -335,6 +340,12 @@ bool CurveEditor::processHover( std::shared_ptr<Rendering::RenderObject> ro ) {
335340 }
336341 if ( m_currentPoint < 0 ) return false ;
337342
343+ if ( m_currentPoint % 3 == 0 )
344+ m_savedPoint = m_currentPoint;
345+ else if ( m_savedPoint >= 0 && m_savedPoint - 1 != m_currentPoint &&
346+ m_savedPoint + 1 != m_currentPoint )
347+ m_savedPoint = -1 ;
348+
338349 ro->getMaterial ()->getParameters ().addParameter ( " material.color" , Color::Red () );
339350 m_selectedRo = ro;
340351 return true ;
@@ -379,22 +390,22 @@ void CurveEditor::processPicking( const Vector3& worldPos ) {
379390 m_tangentPoints.push_back ( m_currentPoint + 1 );
380391 }
381392 }
382- else if ( m_smooth ) {
383- if ( m_currentPoint % 3 == 2 ) {
384- auto pointMid = m_pointEntities[m_currentPoint + 1 ];
385- pointComponent = m_pointEntities[m_currentPoint + 2 ];
386- auto symTransform =
387- computePointTransform ( pointComponent, pointMid->m_point , worldPos );
393+ else if ( m_currentPoint % 3 == 2 ) {
394+ auto pointMid = m_pointEntities[m_currentPoint + 1 ];
395+ if ( !( pointMid->m_state == PointComponent::DEFAULT ) ) {
396+ pointComponent = m_pointEntities[m_currentPoint + 2 ];
397+ auto symTransform = computePointTransform ( pointComponent, pointMid, worldPos );
388398 auto ro = m_roMgr->getRenderObject ( pointComponent->getRenderObjects ()[0 ] );
389399 ro->setLocalTransform ( symTransform );
390400
391401 if ( m_tangentPoints.empty () ) { m_tangentPoints.push_back ( m_currentPoint + 2 ); }
392402 }
393- else if ( m_currentPoint % 3 == 1 ) {
394- auto pointMid = m_pointEntities[m_currentPoint - 1 ];
395- pointComponent = m_pointEntities[m_currentPoint - 2 ];
396- auto symTransform =
397- computePointTransform ( pointComponent, pointMid->m_point , worldPos );
403+ }
404+ else if ( m_currentPoint % 3 == 1 ) {
405+ auto pointMid = m_pointEntities[m_currentPoint - 1 ];
406+ if ( !( pointMid->m_state == PointComponent::DEFAULT ) ) {
407+ pointComponent = m_pointEntities[m_currentPoint - 2 ];
408+ auto symTransform = computePointTransform ( pointComponent, pointMid, worldPos );
398409 auto ro = m_roMgr->getRenderObject ( pointComponent->getRenderObjects ()[0 ] );
399410 ro->setLocalTransform ( symTransform );
400411
@@ -404,3 +415,112 @@ void CurveEditor::processPicking( const Vector3& worldPos ) {
404415 }
405416 updateCurves ();
406417}
418+
419+ void CurveEditor::setSmooth ( bool smooth ) {
420+ if ( m_savedPoint >= 0 ) {
421+ if ( smooth ) {
422+ m_pointEntities[m_savedPoint]->m_state = PointComponent::SMOOTH ;
423+ smoothify ( m_savedPoint );
424+ }
425+ else
426+ m_pointEntities[m_savedPoint]->m_state = PointComponent::DEFAULT ;
427+ }
428+ }
429+
430+ void CurveEditor::setSymetry ( bool symetry ) {
431+ if ( m_savedPoint >= 0 ) {
432+ if ( symetry ) {
433+ m_pointEntities[m_savedPoint]->m_state = PointComponent::SYMETRIC ;
434+ symmetrize ( m_savedPoint );
435+ }
436+ else
437+ m_pointEntities[m_savedPoint]->m_state = PointComponent::SMOOTH ;
438+ }
439+ }
440+
441+ void CurveEditor::smoothify ( int pointId ) {
442+ if ( ( pointId == 0 || pointId == 1 || pointId == m_pointEntities.size () - 2 ||
443+ pointId == m_pointEntities.size () - 1 ) )
444+ return ;
445+
446+ m_viewer->makeCurrent ();
447+ Vector3 backPoint = m_pointEntities[pointId - 1 ]->m_point ;
448+ Vector3 back = backPoint - m_pointEntities[pointId]->m_point ;
449+ Vector3 frontPoint = m_pointEntities[pointId + 1 ]->m_point ;
450+ Vector3 front = frontPoint - m_pointEntities[pointId]->m_point ;
451+
452+ Vector3 newPointDir = back - front;
453+ newPointDir.normalize ();
454+ newPointDir = newPointDir * back.norm ();
455+ Vector3 newBackPoint = m_pointEntities[pointId]->m_point + newPointDir;
456+
457+ auto transform = Transform::Identity ();
458+ transform.translate ( newBackPoint - m_pointEntities[pointId - 1 ]->m_point );
459+ auto roIdx = m_pointEntities[pointId - 1 ]->getRenderObjects ()[0 ];
460+ auto ro = m_roMgr->getRenderObject ( roIdx );
461+ ro->setLocalTransform ( transform );
462+ m_pointEntities[pointId - 1 ]->m_point = newBackPoint;
463+
464+ newPointDir.normalize ();
465+ newPointDir = newPointDir * front.norm ();
466+ Vector3 newFrontPoint = m_pointEntities[pointId]->m_point - newPointDir;
467+
468+ transform = Transform::Identity ();
469+ transform.translate ( newFrontPoint - m_pointEntities[pointId + 1 ]->m_point );
470+ roIdx = m_pointEntities[pointId + 1 ]->getRenderObjects ()[0 ];
471+ ro = m_roMgr->getRenderObject ( roIdx );
472+ ro->setLocalTransform ( transform );
473+ m_pointEntities[pointId + 1 ]->m_point = newFrontPoint;
474+
475+ m_currentPoint = pointId - 1 ;
476+ updateCurves ( true );
477+ m_currentPoint = pointId + 1 ;
478+ updateCurves ( true );
479+ m_currentPoint = -1 ;
480+
481+ m_viewer->doneCurrent ();
482+ m_viewer->getRenderer ()->buildAllRenderTechniques ();
483+ m_viewer->needUpdate ();
484+ }
485+
486+ void CurveEditor::symmetrize ( int pointId ) {
487+ if ( ( pointId == 0 || pointId == 1 || pointId == m_pointEntities.size () - 2 ||
488+ pointId == m_pointEntities.size () - 1 ) )
489+ return ;
490+
491+ m_viewer->makeCurrent ();
492+
493+ Vector3 backPoint = m_pointEntities[pointId - 1 ]->m_point ;
494+ Vector3 back = backPoint - m_pointEntities[pointId]->m_point ;
495+ Vector3 frontPoint = m_pointEntities[pointId + 1 ]->m_point ;
496+ Vector3 front = frontPoint - m_pointEntities[pointId]->m_point ;
497+
498+ auto transform = Transform::Identity ();
499+ Index roIdx = -1 ;
500+ if ( std::min ( back.norm (), front.norm () ) == back.norm () ) {
501+ front.normalize ();
502+ front = front * back.norm ();
503+ Vector3 newPoint = m_pointEntities[pointId]->m_point + front;
504+ transform.translate ( newPoint - m_pointEntities[pointId + 1 ]->m_point );
505+ roIdx = m_pointEntities[pointId + 1 ]->getRenderObjects ()[0 ];
506+ m_pointEntities[pointId + 1 ]->m_point = newPoint;
507+ m_currentPoint = pointId + 1 ;
508+ }
509+ else {
510+ back.normalize ();
511+ back = back * front.norm ();
512+ Vector3 newPoint = m_pointEntities[pointId]->m_point + back;
513+ transform.translate ( newPoint - m_pointEntities[pointId - 1 ]->m_point );
514+ roIdx = m_pointEntities[pointId - 1 ]->getRenderObjects ()[0 ];
515+ m_pointEntities[pointId - 1 ]->m_point = newPoint;
516+ m_currentPoint = pointId - 1 ;
517+ }
518+ auto ro = m_roMgr->getRenderObject ( roIdx );
519+ ro->setLocalTransform ( transform );
520+ updateCurves ( true );
521+ m_currentPoint = -1 ;
522+
523+ m_viewer->doneCurrent ();
524+ m_viewer->getRenderer ()->buildAllRenderTechniques ();
525+ m_viewer->needUpdate ();
526+ }
0 commit comments