@Override public void onAction(String name, boolean isPressed, float tpf) { if (isPressed) { composer.reset(); armature.applyBindPose(); } else { composer.setCurrentAction("anim"); } } }, "bind");
private void controlRenderHardware() { offsetMatrices = armature.computeSkinningMatrices(); jointMatricesParam.setValue(offsetMatrices); }
/** * 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(); } }
armature = new Armature(joints); armature.saveBindPose(); } else if (qName.equals("animation")) { animClips.add(animClip);
Armature armature = new Armature(joints); skinnedSpatials.put(skinData, new ArrayList<Spatial>()); armature.update(); armature.saveInitialPose();
@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(); }
@Override protected void controlUpdate(float tpf) { wasMeshUpdated = false; armature.update(); }
/** * Access the attachments node of the named bone. If the bone doesn't * already have an attachments node, create one and attach it to the scene * graph. Models and effects attached to the attachments node will follow * the bone's motions. * * @param jointName the name of the joint * @return the attachments node of the joint */ public Node getAttachmentsNode(String jointName) { Joint b = armature.getJoint(jointName); if (b == null) { throw new IllegalArgumentException("Given bone name does not exist " + "in the armature."); } updateTargetsAndMaterials(spatial); int boneIndex = armature.getJointIndex(b); Node n = b.getAttachmentsNode(boneIndex, targets); /* * Select a node to parent the attachments node. */ Node parent; if (spatial instanceof Node) { parent = (Node) spatial; // the usual case } else { parent = spatial.getParent(); } parent.attachChild(n); return n; }
private Joint findJoint(Armature armature, String jointName) { Joint joint = armature.getJoint(jointName); if (joint == null) { throw new IllegalArgumentException("Cannot find joint " + jointName); } return joint; }
private boolean testHardwareSupported(RenderManager rm) { //Only 255 bones max supported with hardware skinning if (armature.getJointCount() > 255) { return false; } switchToHardware(); try { rm.preloadScene(spatial); return true; } catch (RendererException e) { logger.log(Level.WARNING, "Could not enable HW skinning due to shader compile error:", e); return false; } }
Armature armature = new Armature(joints); armature.saveBindPose(); skeletonArmatureMap.put(skeleton, armature);
/** * Saves the current Armature state as its bind pose. * Note that the bind pose is supposed to be the one where the armature is aligned with the mesh to deform. * Saving this pose will affect how skinning works. */ public void saveBindPose() { //make sure all bones are updated update(); //Save the current pose as bind pose for (Joint joint : jointList) { joint.saveBindPose(); } }
public static ArmatureMask createMask(Armature armature, String... joints) { ArmatureMask mask = new ArmatureMask(); mask.addBones(armature, joints); for (String joint : joints) { mask.affectedJoints.set(armature.getJoint(joint).getId()); } return mask; }
private void switchToHardware() { numberOfJointsParam.setEnabled(true); jointMatricesParam.setEnabled(true); // Next full 10 bones (e.g. 30 on 24 bones) int numBones = ((armature.getJointCount() / 10) + 1) * 10; numberOfJointsParam.setValue(numBones); for (Geometry geometry : targets) { Mesh mesh = geometry.getMesh(); if (mesh != null && mesh.isAnimated()) { mesh.prepareForAnim(false); } } }
Joint[] joints = new Joint[]{root, j1, j2, j3}; armature = new Armature(joints); armature.saveBindPose();
super(name); this.armature = armature; armature.update();
private void controlRenderSoftware() { resetToBind(); // reset morph meshes to bind pose offsetMatrices = armature.computeSkinningMatrices(); for (Geometry geometry : targets) { Mesh mesh = geometry.getMesh(); // NOTE: This assumes code higher up has // already ensured this mesh is animated. // Otherwise a crash will happen in skin update. softwareSkinUpdate(mesh, offsetMatrices); } }
@Override public void onAction(String name, boolean isPressed, float tpf) { if (isPressed) { composer.reset(); armature.applyBindPose(); } else { composer.setCurrentAction("anim"); } } }, "bind");
Joint[] joints = new Joint[]{root, j1, j2, j3}; final Armature armature = new Armature(joints); armature.saveBindPose();