@ -25,6 +25,7 @@ import com.jme3.scene.plugins.blender.animations.IpoHelper;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException ;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException ;
import com.jme3.scene.plugins.blender.file.Pointer ;
import com.jme3.scene.plugins.blender.file.Pointer ;
import com.jme3.scene.plugins.blender.file.Structure ;
import com.jme3.scene.plugins.blender.file.Structure ;
import com.jme3.scene.plugins.blender.objects.ObjectHelper ;
/ * *
/ * *
* This class should be used for constraint calculations .
* This class should be used for constraint calculations .
@ -195,7 +196,7 @@ public class ConstraintHelper extends AbstractBlenderHelper {
while ( spatial . getParent ( ) ! = null ) {
while ( spatial . getParent ( ) ! = null ) {
spatial = spatial . getParent ( ) ;
spatial = spatial . getParent ( ) ;
}
}
simulationRootNodes . add ( new SimulationNode ( ( Long ) spatial . getUserData ( "oma" ) , blenderContext ) ) ;
simulationRootNodes . add ( new SimulationNode ( ( Long ) blenderContext . getMarkerValue ( ObjectHelper . OMA_MARKER , spatial ) , blenderContext ) ) ;
} else {
} else {
throw new IllegalStateException ( "Unsupported constraint type: " + constraint ) ;
throw new IllegalStateException ( "Unsupported constraint type: " + constraint ) ;
}
}
@ -220,7 +221,7 @@ public class ConstraintHelper extends AbstractBlenderHelper {
* /
* /
public Transform getTransform ( Long oma , String subtargetName , Space space ) {
public Transform getTransform ( Long oma , String subtargetName , Space space ) {
Spatial feature = ( Spatial ) blenderContext . getLoadedFeature ( oma , LoadedFeatureDataType . LOADED_FEATURE ) ;
Spatial feature = ( Spatial ) blenderContext . getLoadedFeature ( oma , LoadedFeatureDataType . LOADED_FEATURE ) ;
boolean isArmature = feature . getUserData ( ArmatureHelper . ARMATURE_NODE_MARKER ) ! = null ;
boolean isArmature = blenderContext . getMarkerValue ( ArmatureHelper . ARMATURE_NODE_MARKER , feature ) ! = null ;
if ( isArmature ) {
if ( isArmature ) {
BoneContext targetBoneContext = blenderContext . getBoneByName ( subtargetName ) ;
BoneContext targetBoneContext = blenderContext . getBoneByName ( subtargetName ) ;
Bone bone = targetBoneContext . getBone ( ) ;
Bone bone = targetBoneContext . getBone ( ) ;
@ -269,9 +270,9 @@ public class ConstraintHelper extends AbstractBlenderHelper {
} else {
} else {
switch ( space ) {
switch ( space ) {
case CONSTRAINT_SPACE_LOCAL :
case CONSTRAINT_SPACE_LOCAL :
return ( ( Spatial ) feature ) . getLocalTransform ( ) ;
return feature . getLocalTransform ( ) ;
case CONSTRAINT_SPACE_WORLD :
case CONSTRAINT_SPACE_WORLD :
return ( ( Spatial ) feature ) . getWorldTransform ( ) ;
return feature . getWorldTransform ( ) ;
case CONSTRAINT_SPACE_PARLOCAL :
case CONSTRAINT_SPACE_PARLOCAL :
case CONSTRAINT_SPACE_POSE :
case CONSTRAINT_SPACE_POSE :
throw new IllegalStateException ( "Nodes can have only Local and World spaces applied!" ) ;
throw new IllegalStateException ( "Nodes can have only Local and World spaces applied!" ) ;
@ -297,7 +298,7 @@ public class ConstraintHelper extends AbstractBlenderHelper {
* /
* /
public void applyTransform ( Long oma , String subtargetName , Space space , Transform transform ) {
public void applyTransform ( Long oma , String subtargetName , Space space , Transform transform ) {
Spatial feature = ( Spatial ) blenderContext . getLoadedFeature ( oma , LoadedFeatureDataType . LOADED_FEATURE ) ;
Spatial feature = ( Spatial ) blenderContext . getLoadedFeature ( oma , LoadedFeatureDataType . LOADED_FEATURE ) ;
boolean isArmature = feature . getUserData ( ArmatureHelper . ARMATURE_NODE_MARKER ) ! = null ;
boolean isArmature = blenderContext . getMarkerValue ( ArmatureHelper . ARMATURE_NODE_MARKER , feature ) ! = null ;
if ( isArmature ) {
if ( isArmature ) {
Skeleton skeleton = blenderContext . getSkeleton ( oma ) ;
Skeleton skeleton = blenderContext . getSkeleton ( oma ) ;
BoneContext targetBoneContext = blenderContext . getBoneByName ( subtargetName ) ;
BoneContext targetBoneContext = blenderContext . getBoneByName ( subtargetName ) ;
@ -354,17 +355,16 @@ public class ConstraintHelper extends AbstractBlenderHelper {
default :
default :
throw new IllegalStateException ( "Invalid space type for target object: " + space . toString ( ) ) ;
throw new IllegalStateException ( "Invalid space type for target object: " + space . toString ( ) ) ;
}
}
} else if ( feature instanceof Spatial ) {
} else {
Spatial spatial = ( Spatial ) feature ;
switch ( space ) {
switch ( space ) {
case CONSTRAINT_SPACE_LOCAL :
case CONSTRAINT_SPACE_LOCAL :
spatial . getLocalTransform ( ) . set ( transform ) ;
feature . getLocalTransform ( ) . set ( transform ) ;
break ;
break ;
case CONSTRAINT_SPACE_WORLD :
case CONSTRAINT_SPACE_WORLD :
if ( spatial . getParent ( ) = = null ) {
if ( feature . getParent ( ) = = null ) {
spatial . setLocalTransform ( transform ) ;
feature . setLocalTransform ( transform ) ;
} else {
} else {
Transform parentWorldTransform = spatial . getParent ( ) . getWorldTransform ( ) ;
Transform parentWorldTransform = feature . getParent ( ) . getWorldTransform ( ) ;
Matrix4f parentMatrix = this . toMatrix ( parentWorldTransform ) . invertLocal ( ) ;
Matrix4f parentMatrix = this . toMatrix ( parentWorldTransform ) . invertLocal ( ) ;
Matrix4f m = this . toMatrix ( transform ) ;
Matrix4f m = this . toMatrix ( transform ) ;
@ -374,14 +374,12 @@ public class ConstraintHelper extends AbstractBlenderHelper {
transform . setRotation ( m . toRotationQuat ( ) ) ;
transform . setRotation ( m . toRotationQuat ( ) ) ;
transform . setScale ( m . toScaleVector ( ) ) ;
transform . setScale ( m . toScaleVector ( ) ) ;
spatial . setLocalTransform ( transform ) ;
feature . setLocalTransform ( transform ) ;
}
}
break ;
break ;
default :
default :
throw new IllegalStateException ( "Invalid space type for spatial object: " + space . toString ( ) ) ;
throw new IllegalStateException ( "Invalid space type for spatial object: " + space . toString ( ) ) ;
}
}
} else {
throw new IllegalStateException ( "Constrained transformation can be applied only to Bone or Spatial feature!" ) ;
}
}
}
}