|
|
|
@ -11,11 +11,9 @@ import java.util.logging.Logger; |
|
|
|
|
|
|
|
|
|
import com.jme3.animation.AnimControl; |
|
|
|
|
import com.jme3.animation.Animation; |
|
|
|
|
import com.jme3.animation.Bone; |
|
|
|
|
import com.jme3.animation.BoneTrack; |
|
|
|
|
import com.jme3.animation.Skeleton; |
|
|
|
|
import com.jme3.animation.SkeletonControl; |
|
|
|
|
import com.jme3.math.Matrix4f; |
|
|
|
|
import com.jme3.scene.Geometry; |
|
|
|
|
import com.jme3.scene.Mesh; |
|
|
|
|
import com.jme3.scene.Node; |
|
|
|
@ -27,7 +25,6 @@ import com.jme3.scene.plugins.blender.BlenderContext; |
|
|
|
|
import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType; |
|
|
|
|
import com.jme3.scene.plugins.blender.animations.ArmatureHelper; |
|
|
|
|
import com.jme3.scene.plugins.blender.constraints.Constraint; |
|
|
|
|
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper; |
|
|
|
|
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; |
|
|
|
|
import com.jme3.scene.plugins.blender.file.FileBlockHeader; |
|
|
|
|
import com.jme3.scene.plugins.blender.file.Pointer; |
|
|
|
@ -91,34 +88,17 @@ import com.jme3.util.BufferUtils; |
|
|
|
|
Pointer pArmatureObject = (Pointer) modifierStructure.getFieldValue("object"); |
|
|
|
|
if (pArmatureObject.isNotNull()) { |
|
|
|
|
ArmatureHelper armatureHelper = blenderContext.getHelper(ArmatureHelper.class); |
|
|
|
|
|
|
|
|
|
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class); |
|
|
|
|
|
|
|
|
|
Structure armatureObject = pArmatureObject.fetchData(blenderContext.getInputStream()).get(0); |
|
|
|
|
|
|
|
|
|
// load skeleton
|
|
|
|
|
Structure armatureStructure = ((Pointer) armatureObject.getFieldValue("data")).fetchData(blenderContext.getInputStream()).get(0); |
|
|
|
|
|
|
|
|
|
Structure pose = ((Pointer) armatureObject.getFieldValue("pose")).fetchData(blenderContext.getInputStream()).get(0); |
|
|
|
|
List<Structure> chanbase = ((Structure) pose.getFieldValue("chanbase")).evaluateListBase(blenderContext); |
|
|
|
|
|
|
|
|
|
Map<Long, Structure> bonesPoseChannels = new HashMap<Long, Structure>(chanbase.size()); |
|
|
|
|
for (Structure poseChannel : chanbase) { |
|
|
|
|
Pointer pBone = (Pointer) poseChannel.getFieldValue("bone"); |
|
|
|
|
bonesPoseChannels.put(pBone.getOldMemoryAddress(), poseChannel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class); |
|
|
|
|
Matrix4f armatureObjectMatrix = objectHelper.getMatrix(armatureObject, "obmat", true); |
|
|
|
|
Matrix4f inverseMeshObjectMatrix = objectHelper.getMatrix(objectStructure, "obmat", true).invertLocal(); |
|
|
|
|
Matrix4f objectToArmatureTransformation = armatureObjectMatrix.multLocal(inverseMeshObjectMatrix); |
|
|
|
|
|
|
|
|
|
List<Structure> bonebase = ((Structure) armatureStructure.getFieldValue("bonebase")).evaluateListBase(blenderContext); |
|
|
|
|
List<Bone> bonesList = new ArrayList<Bone>(); |
|
|
|
|
for (int i = 0; i < bonebase.size(); ++i) { |
|
|
|
|
armatureHelper.buildBones(bonebase.get(i), null, bonesList, objectToArmatureTransformation, bonesPoseChannels, blenderContext); |
|
|
|
|
} |
|
|
|
|
bonesList.add(0, new Bone("")); |
|
|
|
|
Skeleton skeleton = new Skeleton(bonesList.toArray(new Bone[bonesList.size()])); |
|
|
|
|
|
|
|
|
|
//load the skeleton and its bones first
|
|
|
|
|
objectHelper.toObject(armatureObject, blenderContext); |
|
|
|
|
Skeleton skeleton = blenderContext.getSkeleton(armatureObject.getOldMemoryAddress()); |
|
|
|
|
|
|
|
|
|
// read mesh indexes
|
|
|
|
|
this.meshOMA = meshStructure.getOldMemoryAddress(); |
|
|
|
|
this.readVerticesWeightsData(objectStructure, meshStructure, skeleton, blenderContext); |
|
|
|
@ -153,10 +133,6 @@ import com.jme3.util.BufferUtils; |
|
|
|
|
for (Structure boneStructure : bonebase) { |
|
|
|
|
blenderContext.setAnimData(boneStructure.getOldMemoryAddress(), animData); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// loading constraints connected with this object
|
|
|
|
|
ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class); |
|
|
|
|
constraintHelper.loadConstraints(armatureObject, blenderContext); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|