@@ -37,14 +37,6 @@ function processTuple(val) {
3737
3838}
3939
40- // take a vector "x y z" and process it into
41- // a THREE.Vector3
42- function processVector ( val ) {
43-
44- return new THREE . Vector3 ( ...processTuple ( val ) ) ;
45-
46- }
47-
4840// applies a rotation a threejs object in URDF order
4941function applyRotation ( obj , rpy , additive = false ) {
5042
@@ -413,35 +405,36 @@ class URDFLoader {
413405 target . urdfName = target . name ;
414406 target . urdfNode = link ;
415407
416- // Extract the attributes
417- children . forEach ( n => {
408+ // Parse inertial properties
409+ const inertialNode = children . find ( n => n . nodeName . toLowerCase ( ) === 'inertial' ) ;
410+ if ( inertialNode ) {
418411
419- const type = n . nodeName . toLowerCase ( ) ;
420- if ( type === 'inertial' ) {
421- const subNodes = [ ...n . children ] ;
422- const origin = subNodes . find ( sn => sn . nodeName . toLowerCase ( ) === 'origin' ) ;
423- const xyz = origin ? origin . getAttribute ( 'xyz' ) : null ;
424- const rpy = origin ? origin . getAttribute ( 'rpy' ) : null ;
425- const mass = subNodes . find ( sn => sn . nodeName . toLowerCase ( ) === 'mass' ) ;
426- const inertia = subNodes . find ( sn => sn . nodeName . toLowerCase ( ) === 'inertia' ) ;
427- target . inertial = origin || mass || inertia ? {
428- origin : xyz || rpy ? {
429- xyz : xyz ? processVector ( xyz ) : null ,
430- rpy : rpy ? processVector ( rpy ) : null ,
431- } : null ,
432- mass : mass ? parseFloat ( mass . getAttribute ( 'value' ) || 0 ) : null ,
433- inertia : inertia ? {
434- ixx : parseFloat ( inertia . getAttribute ( 'ixx' ) || 0 ) ,
435- ixy : parseFloat ( inertia . getAttribute ( 'ixy' ) || 0 ) ,
436- ixz : parseFloat ( inertia . getAttribute ( 'ixz' ) || 0 ) ,
437- iyy : parseFloat ( inertia . getAttribute ( 'iyy' ) || 0 ) ,
438- iyz : parseFloat ( inertia . getAttribute ( 'iyz' ) || 0 ) ,
439- izz : parseFloat ( inertia . getAttribute ( 'izz' ) || 0 ) ,
440- } : null ,
441- } : null ;
412+ [ ...inertialNode . children ] . forEach ( n => {
442413
443- }
444- } ) ;
414+ const type = n . nodeName . toLowerCase ( ) ;
415+ if ( type === 'origin' ) {
416+
417+ target . inertial . origin . xyz = processTuple ( n . getAttribute ( 'xyz' ) ) ;
418+ target . inertial . origin . rpy = processTuple ( n . getAttribute ( 'rpy' ) ) ;
419+
420+ } else if ( type === 'mass' ) {
421+
422+ target . inertial . mass = parseFloat ( n . getAttribute ( 'value' ) ) || 0 ;
423+
424+ } else if ( type === 'inertia' ) {
425+
426+ target . inertial . inertia . ixx = parseFloat ( n . getAttribute ( 'ixx' ) ) || 0 ;
427+ target . inertial . inertia . ixy = parseFloat ( n . getAttribute ( 'ixy' ) ) || 0 ;
428+ target . inertial . inertia . ixz = parseFloat ( n . getAttribute ( 'ixz' ) ) || 0 ;
429+ target . inertial . inertia . iyy = parseFloat ( n . getAttribute ( 'iyy' ) ) || 0 ;
430+ target . inertial . inertia . iyz = parseFloat ( n . getAttribute ( 'iyz' ) ) || 0 ;
431+ target . inertial . inertia . izz = parseFloat ( n . getAttribute ( 'izz' ) ) || 0 ;
432+
433+ }
434+
435+ } ) ;
436+
437+ }
445438
446439 if ( parseVisual ) {
447440
0 commit comments