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