@@ -1175,6 +1175,28 @@ public static FbxVector4 ConvertQuaternionToXYZEuler (FbxQuaternion quat)
1175
1175
return new FbxVector4 ( vector4 . X , - vector4 . Y , - vector4 . Z , vector4 . W ) ;
1176
1176
}
1177
1177
1178
+ public static FbxDouble3 ToFbxDouble3 ( Vector3 v )
1179
+ {
1180
+ return new FbxDouble3 ( v . x , v . y , v . z ) ;
1181
+ }
1182
+
1183
+ public static FbxDouble3 ToFbxDouble3 ( FbxVector4 v )
1184
+ {
1185
+ return new FbxDouble3 ( v . X , v . Y , v . Z ) ;
1186
+ }
1187
+
1188
+ public static FbxVector4 ToFbxVector4 ( FbxDouble3 v )
1189
+ {
1190
+ return new FbxVector4 ( v . X , v . Y , v . Z ) ;
1191
+ }
1192
+
1193
+ public static FbxDouble3 ConvertToRightHandedEuler ( Vector3 rot )
1194
+ {
1195
+ rot . y *= - 1 ;
1196
+ rot . z *= - 1 ;
1197
+ return ToFbxDouble3 ( rot ) ;
1198
+ }
1199
+
1178
1200
/// <summary>
1179
1201
/// Euler to quaternion without axis conversion.
1180
1202
/// </summary>
@@ -1471,10 +1493,7 @@ protected void AddFbxNodeToConstraintsMapping<T>(FbxNode fbxNode, T fbxConstrain
1471
1493
protected bool ExportPositionConstraint ( IConstraint uniConstraint , FbxScene fbxScene , FbxNode fbxNode )
1472
1494
{
1473
1495
var uniPosConstraint = uniConstraint as PositionConstraint ;
1474
- if ( uniPosConstraint == null )
1475
- {
1476
- return false ;
1477
- }
1496
+ Debug . Assert ( uniPosConstraint == null ) ;
1478
1497
1479
1498
FbxConstraintPosition fbxPosConstraint = FbxConstraintPosition . Create ( fbxScene , fbxNode . GetName ( ) + "_positionConstraint" ) ;
1480
1499
fbxPosConstraint . SetConstrainedObject ( fbxNode ) ;
@@ -1488,22 +1507,19 @@ protected bool ExportPositionConstraint(IConstraint uniConstraint, FbxScene fbxS
1488
1507
fbxPosConstraint . AffectZ . Set ( ( uniAffectedAxes & Axis . Z ) == Axis . Z ) ;
1489
1508
1490
1509
var fbxTranslationOffset = ConvertToRightHanded ( uniPosConstraint . translationOffset , UnitScaleFactor ) ;
1491
- fbxPosConstraint . Translation . Set ( new FbxDouble3 ( fbxTranslationOffset . X , fbxTranslationOffset . Y , fbxTranslationOffset . Z ) ) ;
1510
+ fbxPosConstraint . Translation . Set ( ToFbxDouble3 ( fbxTranslationOffset ) ) ;
1492
1511
1493
1512
// rest position is the position of the fbx node
1494
1513
var fbxRestTranslation = ConvertToRightHanded ( uniPosConstraint . translationAtRest , UnitScaleFactor ) ;
1495
1514
// set the local position of fbxNode
1496
- fbxNode . LclTranslation . Set ( new FbxDouble3 ( fbxRestTranslation . X , fbxRestTranslation . Y , fbxRestTranslation . Z ) ) ;
1515
+ fbxNode . LclTranslation . Set ( ToFbxDouble3 ( fbxRestTranslation ) ) ;
1497
1516
return true ;
1498
1517
}
1499
1518
1500
1519
protected bool ExportRotationConstraint ( IConstraint uniConstraint , FbxScene fbxScene , FbxNode fbxNode )
1501
1520
{
1502
1521
var uniRotConstraint = uniConstraint as RotationConstraint ;
1503
- if ( uniRotConstraint == null )
1504
- {
1505
- return false ;
1506
- }
1522
+ Debug . Assert ( uniRotConstraint == null ) ;
1507
1523
1508
1524
FbxConstraintRotation fbxRotConstraint = FbxConstraintRotation . Create ( fbxScene , fbxNode . GetName ( ) + "_rotationConstraint" ) ;
1509
1525
fbxRotConstraint . SetConstrainedObject ( fbxNode ) ;
@@ -1518,7 +1534,7 @@ protected bool ExportRotationConstraint(IConstraint uniConstraint, FbxScene fbxS
1518
1534
1519
1535
// Not converting rotation offset to XYZ euler as it gives the incorrect result in both Maya and Unity.
1520
1536
var uniRotationOffset = uniRotConstraint . rotationOffset ;
1521
- var fbxRotationOffset = new FbxDouble3 ( uniRotationOffset . x , - uniRotationOffset . y , - uniRotationOffset . z ) ;
1537
+ var fbxRotationOffset = ConvertToRightHandedEuler ( uniRotationOffset ) ;
1522
1538
1523
1539
fbxRotConstraint . Rotation . Set ( fbxRotationOffset ) ;
1524
1540
@@ -1533,10 +1549,7 @@ protected bool ExportRotationConstraint(IConstraint uniConstraint, FbxScene fbxS
1533
1549
protected bool ExportScaleConstraint ( IConstraint uniConstraint , FbxScene fbxScene , FbxNode fbxNode )
1534
1550
{
1535
1551
var uniScaleConstraint = uniConstraint as ScaleConstraint ;
1536
- if ( uniScaleConstraint == null )
1537
- {
1538
- return false ;
1539
- }
1552
+ Debug . Assert ( uniScaleConstraint == null ) ;
1540
1553
1541
1554
FbxConstraintScale fbxScaleConstraint = FbxConstraintScale . Create ( fbxScene , fbxNode . GetName ( ) + "_scaleConstraint" ) ;
1542
1555
fbxScaleConstraint . SetConstrainedObject ( fbxNode ) ;
@@ -1550,12 +1563,12 @@ protected bool ExportScaleConstraint(IConstraint uniConstraint, FbxScene fbxScen
1550
1563
fbxScaleConstraint . AffectZ . Set ( ( uniAffectedAxes & Axis . Z ) == Axis . Z ) ;
1551
1564
1552
1565
var uniScaleOffset = uniScaleConstraint . scaleOffset ;
1553
- var fbxScalingOffset = new FbxDouble3 ( uniScaleOffset . x , uniScaleOffset . y , uniScaleOffset . z ) ;
1566
+ var fbxScalingOffset = ToFbxDouble3 ( uniScaleOffset ) ;
1554
1567
fbxScaleConstraint . Scaling . Set ( fbxScalingOffset ) ;
1555
1568
1556
1569
// rest rotation is the rotation of the fbx node
1557
1570
var uniRestScale = uniScaleConstraint . scaleAtRest ;
1558
- var fbxRestScale = new FbxDouble3 ( uniRestScale . x , uniRestScale . y , uniRestScale . z ) ;
1571
+ var fbxRestScale = ToFbxDouble3 ( uniRestScale ) ;
1559
1572
// set the local rotation of fbxNode
1560
1573
fbxNode . LclScaling . Set ( fbxRestScale ) ;
1561
1574
return true ;
@@ -1564,10 +1577,7 @@ protected bool ExportScaleConstraint(IConstraint uniConstraint, FbxScene fbxScen
1564
1577
protected bool ExportAimConstraint ( IConstraint uniConstraint , FbxScene fbxScene , FbxNode fbxNode )
1565
1578
{
1566
1579
var uniAimConstraint = uniConstraint as AimConstraint ;
1567
- if ( uniAimConstraint == null )
1568
- {
1569
- return false ;
1570
- }
1580
+ Debug . Assert ( uniAimConstraint == null ) ;
1571
1581
1572
1582
FbxConstraintAim fbxAimConstraint = FbxConstraintAim . Create ( fbxScene , fbxNode . GetName ( ) + "_aimConstraint" ) ;
1573
1583
fbxAimConstraint . SetConstrainedObject ( fbxNode ) ;
@@ -1581,7 +1591,7 @@ protected bool ExportAimConstraint(IConstraint uniConstraint, FbxScene fbxScene,
1581
1591
fbxAimConstraint . AffectZ . Set ( ( uniAffectedAxes & Axis . Z ) == Axis . Z ) ;
1582
1592
1583
1593
var uniRotationOffset = uniAimConstraint . rotationOffset ;
1584
- var fbxRotationOffset = new FbxDouble3 ( uniRotationOffset . x , - uniRotationOffset . y , - uniRotationOffset . z ) ;
1594
+ var fbxRotationOffset = ConvertToRightHandedEuler ( uniRotationOffset ) ;
1585
1595
fbxAimConstraint . RotationOffset . Set ( fbxRotationOffset ) ;
1586
1596
1587
1597
// rest rotation is the rotation of the fbx node
@@ -1614,11 +1624,9 @@ protected bool ExportAimConstraint(IConstraint uniConstraint, FbxScene fbxScene,
1614
1624
fbxAimConstraint . WorldUpType . Set ( ( int ) fbxWorldUpType ) ;
1615
1625
1616
1626
var uniAimVector = ConvertToRightHanded ( uniAimConstraint . aimVector ) ;
1617
- fbxAimConstraint . AimVector . Set ( new FbxDouble3 ( uniAimVector . X , uniAimVector . Y , uniAimVector . Z ) ) ;
1618
- var uniUpVector = uniAimConstraint . upVector ;
1619
- fbxAimConstraint . UpVector . Set ( new FbxDouble3 ( uniUpVector . x , uniUpVector . y , uniUpVector . z ) ) ;
1620
- var uniWorldUpVector = uniAimConstraint . worldUpVector ;
1621
- fbxAimConstraint . WorldUpVector . Set ( new FbxDouble3 ( uniWorldUpVector . x , uniWorldUpVector . y , uniWorldUpVector . z ) ) ;
1627
+ fbxAimConstraint . AimVector . Set ( ToFbxDouble3 ( uniAimVector ) ) ;
1628
+ fbxAimConstraint . UpVector . Set ( ToFbxDouble3 ( uniAimConstraint . upVector ) ) ;
1629
+ fbxAimConstraint . WorldUpVector . Set ( ToFbxDouble3 ( uniAimConstraint . worldUpVector ) ) ;
1622
1630
1623
1631
if ( uniAimConstraint . worldUpObject && MapUnityObjectToFbxNode . ContainsKey ( uniAimConstraint . worldUpObject . gameObject ) )
1624
1632
{
@@ -1630,10 +1638,7 @@ protected bool ExportAimConstraint(IConstraint uniConstraint, FbxScene fbxScene,
1630
1638
protected bool ExportParentConstraint ( IConstraint uniConstraint , FbxScene fbxScene , FbxNode fbxNode )
1631
1639
{
1632
1640
var uniParentConstraint = uniConstraint as ParentConstraint ;
1633
- if ( uniParentConstraint == null )
1634
- {
1635
- return false ;
1636
- }
1641
+ Debug . Assert ( uniParentConstraint == null ) ;
1637
1642
1638
1643
FbxConstraintParent fbxParentConstraint = FbxConstraintParent . Create ( fbxScene , fbxNode . GetName ( ) + "_parentConstraint" ) ;
1639
1644
fbxParentConstraint . SetConstrainedObject ( fbxNode ) ;
@@ -1651,7 +1656,7 @@ protected bool ExportParentConstraint(IConstraint uniConstraint, FbxScene fbxSce
1651
1656
var fbxTranslationOffset = ConvertToRightHanded ( uniTranslationOffset , UnitScaleFactor ) ;
1652
1657
fbxParentConstraint . SetTranslationOffset ( uniSource . node , fbxTranslationOffset ) ;
1653
1658
1654
- var fbxRotationOffset = new FbxVector4 ( uniRotationOffset . x , - uniRotationOffset . y , - uniRotationOffset . z ) ;
1659
+ var fbxRotationOffset = ToFbxVector4 ( ConvertToRightHandedEuler ( uniRotationOffset ) ) ;
1655
1660
fbxParentConstraint . SetRotationOffset ( uniSource . node , fbxRotationOffset ) ;
1656
1661
}
1657
1662
ExportCommonConstraintProperties ( uniParentConstraint , fbxParentConstraint , fbxNode ) ;
@@ -1669,7 +1674,7 @@ protected bool ExportParentConstraint(IConstraint uniConstraint, FbxScene fbxSce
1669
1674
// rest position is the position of the fbx node
1670
1675
var fbxRestTranslation = ConvertToRightHanded ( uniParentConstraint . translationAtRest , UnitScaleFactor ) ;
1671
1676
// set the local position of fbxNode
1672
- fbxNode . LclTranslation . Set ( new FbxDouble3 ( fbxRestTranslation . X , fbxRestTranslation . Y , fbxRestTranslation . Z ) ) ;
1677
+ fbxNode . LclTranslation . Set ( ToFbxDouble3 ( fbxRestTranslation ) ) ;
1673
1678
1674
1679
// rest rotation is the rotation of the fbx node
1675
1680
var uniRestRotationQuat = Quaternion . Euler ( uniParentConstraint . rotationAtRest ) ;
0 commit comments