|
|
|
@ -3,12 +3,14 @@ package com.jme3.scene.plugins.blender.modifiers; |
|
|
|
|
import com.jme3.animation.Animation; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.logging.Logger; |
|
|
|
|
|
|
|
|
|
import com.jme3.animation.Bone; |
|
|
|
|
import com.jme3.animation.BoneAnimation; |
|
|
|
|
import com.jme3.animation.BoneTrack; |
|
|
|
|
import com.jme3.animation.Skeleton; |
|
|
|
|
import com.jme3.math.Transform; |
|
|
|
|
import com.jme3.scene.Node; |
|
|
|
|
import com.jme3.scene.plugins.blender.DataRepository; |
|
|
|
|
import com.jme3.scene.plugins.blender.animations.Ipo; |
|
|
|
|
import com.jme3.scene.plugins.blender.animations.IpoHelper; |
|
|
|
@ -24,7 +26,13 @@ import com.jme3.scene.plugins.ogre.AnimData; |
|
|
|
|
* |
|
|
|
|
* @author Marcin Roguski (Kaelthas) |
|
|
|
|
*/ |
|
|
|
|
/* package */class ObjectAnimationModifier extends ArmatureModifier { |
|
|
|
|
/* package */class ObjectAnimationModifier extends Modifier { |
|
|
|
|
private static final Logger LOGGER = Logger.getLogger(ObjectAnimationModifier.class.getName()); |
|
|
|
|
|
|
|
|
|
/** Loaded animation data. */ |
|
|
|
|
private AnimData animData; |
|
|
|
|
/** Old memory address of the object structure that will have the modifier applied. */ |
|
|
|
|
private Long objectOMA; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This constructor reads animation of the object itself (without bones) and |
|
|
|
@ -44,8 +52,7 @@ import com.jme3.scene.plugins.ogre.AnimData; |
|
|
|
|
* this exception is thrown when the blender file is somehow |
|
|
|
|
* corrupted |
|
|
|
|
*/ |
|
|
|
|
public ObjectAnimationModifier(Structure objectStructure, |
|
|
|
|
DataRepository dataRepository) throws BlenderFileException { |
|
|
|
|
public ObjectAnimationModifier(Structure objectStructure, DataRepository dataRepository) throws BlenderFileException { |
|
|
|
|
Pointer pIpo = (Pointer) objectStructure.getFieldValue("ipo"); |
|
|
|
|
if (pIpo.isNotNull()) { |
|
|
|
|
// check if there is an action name connected with this ipo
|
|
|
|
@ -54,13 +61,9 @@ import com.jme3.scene.plugins.ogre.AnimData; |
|
|
|
|
.getFileBlocks(Integer.valueOf(FileBlockHeader.BLOCK_AC00)); |
|
|
|
|
for (FileBlockHeader actionBlock : actionBlocks) { |
|
|
|
|
Structure action = actionBlock.getStructure(dataRepository); |
|
|
|
|
List<Structure> actionChannels = ((Structure) action |
|
|
|
|
.getFieldValue("chanbase")) |
|
|
|
|
.evaluateListBase(dataRepository); |
|
|
|
|
if (actionChannels.size() == 1) {// object's animtion action has
|
|
|
|
|
// only one channel
|
|
|
|
|
Pointer pChannelIpo = (Pointer) actionChannels.get(0) |
|
|
|
|
.getFieldValue("ipo"); |
|
|
|
|
List<Structure> actionChannels = ((Structure) action.getFieldValue("chanbase")).evaluateListBase(dataRepository); |
|
|
|
|
if (actionChannels.size() == 1) {// object's animtion action has only one channel
|
|
|
|
|
Pointer pChannelIpo = (Pointer) actionChannels.get(0).getFieldValue("ipo"); |
|
|
|
|
if (pChannelIpo.equals(pIpo)) { |
|
|
|
|
objectAnimationName = action.getName(); |
|
|
|
|
break; |
|
|
|
@ -69,20 +72,15 @@ import com.jme3.scene.plugins.ogre.AnimData; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String objectName = objectStructure.getName(); |
|
|
|
|
if (objectAnimationName == null) {// set the object's animation name
|
|
|
|
|
// to object's name
|
|
|
|
|
if (objectAnimationName == null) {// set the object's animation name to object's name
|
|
|
|
|
objectAnimationName = objectName; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
IpoHelper ipoHelper = dataRepository.getHelper(IpoHelper.class); |
|
|
|
|
Structure ipoStructure = pIpo.fetchData( |
|
|
|
|
dataRepository.getInputStream()).get(0); |
|
|
|
|
Structure ipoStructure = pIpo.fetchData(dataRepository.getInputStream()).get(0); |
|
|
|
|
Ipo ipo = ipoHelper.createIpo(ipoStructure, dataRepository); |
|
|
|
|
int[] animationFrames = dataRepository.getBlenderKey() |
|
|
|
|
.getAnimationFrames(objectName, objectAnimationName); |
|
|
|
|
if (animationFrames == null) {// if the name was created here there
|
|
|
|
|
// are no frames set for the
|
|
|
|
|
// animation
|
|
|
|
|
int[] animationFrames = dataRepository.getBlenderKey().getAnimationFrames(objectName, objectAnimationName); |
|
|
|
|
if (animationFrames == null) {// if the name was created here there are no frames set for the animation
|
|
|
|
|
animationFrames = new int[] { 1, ipo.getLastFrame() }; |
|
|
|
|
} |
|
|
|
|
int fps = dataRepository.getBlenderKey().getFps(); |
|
|
|
@ -91,31 +89,30 @@ import com.jme3.scene.plugins.ogre.AnimData; |
|
|
|
|
|
|
|
|
|
// calculating track for the only bone in this skeleton
|
|
|
|
|
BoneTrack[] tracks = new BoneTrack[1]; |
|
|
|
|
tracks[0] = ipo.calculateTrack(0, animationFrames[0], |
|
|
|
|
animationFrames[1], fps); |
|
|
|
|
tracks[0] = ipo.calculateTrack(0, animationFrames[0], animationFrames[1], fps); |
|
|
|
|
|
|
|
|
|
BoneAnimation boneAnimation = new BoneAnimation( |
|
|
|
|
objectAnimationName, stop - start); |
|
|
|
|
BoneAnimation boneAnimation = new BoneAnimation(objectAnimationName, stop - start); |
|
|
|
|
boneAnimation.setTracks(tracks); |
|
|
|
|
ArrayList<Animation> animations = new ArrayList<Animation>( |
|
|
|
|
1); |
|
|
|
|
ArrayList<Animation> animations = new ArrayList<Animation>(1); |
|
|
|
|
animations.add(boneAnimation); |
|
|
|
|
|
|
|
|
|
// preparing the object's bone
|
|
|
|
|
ObjectHelper objectHelper = dataRepository |
|
|
|
|
.getHelper(ObjectHelper.class); |
|
|
|
|
Transform t = objectHelper.getTransformation(objectStructure, |
|
|
|
|
dataRepository); |
|
|
|
|
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); |
|
|
|
|
Transform t = objectHelper.getTransformation(objectStructure, dataRepository); |
|
|
|
|
Bone bone = new Bone(null); |
|
|
|
|
bone.setBindTransforms(t.getTranslation(), t.getRotation(), |
|
|
|
|
t.getScale()); |
|
|
|
|
bone.setBindTransforms(t.getTranslation(), t.getRotation(), t.getScale()); |
|
|
|
|
|
|
|
|
|
jmeModifierRepresentation = new AnimData(new Skeleton( |
|
|
|
|
new Bone[] { bone }), animations); |
|
|
|
|
additionalData = objectStructure.getOldMemoryAddress(); |
|
|
|
|
animData = new AnimData(new Skeleton(new Bone[] { bone }), animations); |
|
|
|
|
objectOMA = objectStructure.getOldMemoryAddress(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Node apply(Node node, DataRepository dataRepository) { |
|
|
|
|
LOGGER.warning("Object animation modifier not yet implemented!"); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String getType() { |
|
|
|
|
return Modifier.OBJECT_ANIMATION_MODIFIER_DATA; |
|
|
|
|