/** * Creates an armature from a joint list. * The root joints are found automatically. * <p> * Note that using this constructor will cause the joints in the list * to have their bind pose recomputed based on their local transforms. * * @param jointList The list of joints to manage by this Armature */ public Armature(Joint[] jointList) { this.jointList = jointList; List<Joint> rootJointList = new ArrayList<>(); for (int i = jointList.length - 1; i >= 0; i--) { Joint joint = jointList[i]; joint.setId(i); instanciateJointModelTransform(joint); if (joint.getParent() == null) { rootJointList.add(joint); } } rootJoints = rootJointList.toArray(new Joint[rootJointList.size()]); createSkinningMatrices(); for (int i = rootJoints.length - 1; i >= 0; i--) { Joint rootJoint = rootJoints[i]; rootJoint.update(); } }
@Override public void read(JmeImporter im) throws IOException { InputCapsule input = im.getCapsule(this); Savable[] jointRootsAsSavable = input.readSavableArray("rootJoints", null); rootJoints = new Joint[jointRootsAsSavable.length]; System.arraycopy(jointRootsAsSavable, 0, rootJoints, 0, jointRootsAsSavable.length); Savable[] jointListAsSavable = input.readSavableArray("jointList", null); jointList = new Joint[jointListAsSavable.length]; System.arraycopy(jointListAsSavable, 0, jointList, 0, jointListAsSavable.length); String className = input.readString("modelTransformClass", MatrixJointModelTransform.class.getCanonicalName()); try { modelTransformClass = (Class<? extends JointModelTransform>) Class.forName(className); } catch (ClassNotFoundException e) { throw new AssetLoadException("Cannnot find class for name " + className); } int i = 0; for (Joint joint : jointList) { joint.setId(i++); instanciateJointModelTransform(joint); } createSkinningMatrices(); for (Joint rootJoint : rootJoints) { rootJoint.update(); } applyInitialPose(); }