@@ -49,9 +49,7 @@ public bool Value
4949 {
5050 get
5151 {
52- if ( m_isDirty ) // nothing to do
53- GetValueImpl ( ) ;
54-
52+ GetValueImpl ( ) ;
5553 return m_value ;
5654 }
5755
@@ -136,9 +134,7 @@ public int Value
136134 {
137135 get
138136 {
139- if ( m_isDirty ) // nothing to do
140- GetValueImpl ( ) ;
141-
137+ GetValueImpl ( ) ;
142138 return m_value ;
143139 }
144140
@@ -229,9 +225,7 @@ public float Value
229225 {
230226 get
231227 {
232- if ( m_isDirty ) // nothing to do
233- GetValueImpl ( ) ;
234-
228+ GetValueImpl ( ) ;
235229 return m_value ;
236230 }
237231
@@ -311,9 +305,7 @@ public float Value
311305 {
312306 get
313307 {
314- if ( m_isDirty ) // nothing to do
315- GetValueImpl ( ) ;
316-
308+ GetValueImpl ( ) ;
317309 return m_value ;
318310 }
319311
@@ -879,4 +871,134 @@ protected override bool GetValueImpl()
879871 }
880872 }
881873
874+
875+ /// <summary>
876+ /// Specialization of the class SofaBaseData to handle SOFA Data<Vec4f> and Data<Vec4d>
877+ /// float or double info will be stored @sa m_isDouble
878+ /// </summary>
879+ [ System . Serializable ]
880+ public class SofaRigidData : SofaBaseData
881+ {
882+ [ SerializeField ]
883+ protected Vector3 m_position ;
884+
885+ [ SerializeField ]
886+ protected Quaternion m_orientation ;
887+
888+ /// Internal info to know if storing float or double
889+ [ SerializeField ]
890+ protected bool m_isDouble ;
891+
892+ private float [ ] m_buff = new float [ 7 ] ;
893+
894+ ////////////////////////////////////////////
895+ ////// SofaVec3Data API /////
896+ ////////////////////////////////////////////
897+
898+ /// Default constructor taking the value, the component owner and its name. Will set the type internally
899+ public SofaRigidData ( SofaBaseComponent owner , string dataName , bool isDouble )
900+ : base ( owner , dataName , "Vec3" )
901+ {
902+ m_position = Vector3 . zero ;
903+ m_orientation = Quaternion . identity ;
904+ m_isDouble = isDouble ;
905+
906+ for ( int i = 0 ; i < 6 ; i ++ )
907+ m_buff [ i ] = 0 ;
908+ m_buff [ 6 ] = 1 ;
909+
910+ GetValueImpl ( ) ;
911+ }
912+
913+ /// Getter/Setter of the @sa m_value. Will call @sa SetValueImpl and @sa GetValueImpl internally for Sofa communication
914+ public Vector3 Position
915+ {
916+ get
917+ {
918+ if ( m_isDirty ) // nothing to do
919+ GetValueImpl ( ) ;
920+
921+ return m_position ;
922+ }
923+
924+ set
925+ {
926+ if ( m_position != value )
927+ {
928+ m_position = value ;
929+ if ( SetValueImpl ( ) )
930+ {
931+ m_owner . m_impl . ReinitComponent ( ) ;
932+ m_isEdited = true ;
933+ }
934+ }
935+ }
936+ }
937+
938+
939+ public Vector3 Angles
940+ {
941+ get
942+ {
943+ if ( m_isDirty ) // nothing to do
944+ GetValueImpl ( ) ;
945+
946+ Vector3 angles = new Vector3 ( m_orientation . eulerAngles [ 0 ] , - m_orientation . eulerAngles [ 1 ] , - m_orientation . eulerAngles [ 2 ] ) ;
947+ return angles ;
948+ }
949+
950+ set
951+ {
952+ //if (m_orientation != value)
953+ //{
954+ // m_orientation = value;
955+ // if (SetValueImpl())
956+ // {
957+ // m_owner.m_impl.ReinitComponent();
958+ // m_isEdited = true;
959+ // }
960+ //}
961+ }
962+ }
963+
964+ /// Log Method for Debug info
965+ public void Log ( )
966+ {
967+ Debug . Log ( m_owner . UniqueNameId + "{" + m_dataType + "}: " + m_dataName + " => " + m_position + " | " + m_orientation ) ;
968+ }
969+
970+
971+ ////////////////////////////////////////////
972+ ////// SofaVec3Data internal API /////
973+ ////////////////////////////////////////////
974+
975+ /// Internal Method to set value inside Sofa simulation
976+ protected override bool SetValueImpl ( )
977+ {
978+ if ( m_owner . m_impl == null )
979+ return false ;
980+
981+ //m_owner.m_impl.SetVector3Value(m_dataName, m_value, m_isDouble);
982+ return true ;
983+ }
984+
985+ /// Internal Method to get value from Sofa simulation
986+ protected override bool GetValueImpl ( )
987+ {
988+ if ( m_owner . m_impl == null )
989+ return false ;
990+
991+ int res = m_owner . m_impl . GetRigidValue ( m_dataName , m_buff , m_isDouble ) ;
992+ if ( res == 0 )
993+ {
994+ // Getting raw values from SOFA, need to inverse left-right hand coordinate system
995+ m_position = new Vector3 ( - m_buff [ 0 ] , m_buff [ 1 ] , m_buff [ 2 ] ) ;
996+ m_orientation = new Quaternion ( m_buff [ 3 ] , m_buff [ 4 ] , m_buff [ 5 ] , m_buff [ 6 ] ) ;
997+ }
998+
999+ m_isDirty = false ;
1000+ return true ;
1001+ }
1002+ }
1003+
8821004}
0 commit comments