private static Joint fromBone(Bone b) { Joint j = new Joint(b.getName()); j.setLocalTranslation(b.getBindPosition()); j.setLocalRotation(b.getBindRotation()); j.setLocalScale(b.getBindScale()); return j; }
public static void padJointTracks(List<TransformTrack> tracks, Joint staticJoint) { Joint j = staticJoint; if (j != null) { // joint has no track , we create one with the default pose float[] times = new float[]{0}; Vector3f[] translations = new Vector3f[]{j.getLocalTranslation()}; Quaternion[] rotations = new Quaternion[]{j.getLocalRotation()}; Vector3f[] scales = new Vector3f[]{j.getLocalScale()}; TransformTrack track = new TransformTrack(j, times, translations, rotations, scales); tracks.add(track); } }
/** * returns the joint index of the joint that has the given name * * @param name * @return */ public int getJointIndex(String name) { for (int i = 0; i < jointList.length; i++) { if (jointList[i].getName().equals(name)) { return i; } } return -1; }
/** * Sets the local transform with the initial transform */ protected void applyInitialPose() { setLocalTransform(initialTransform); updateModelTransforms(); for (Joint child : children.getArray()) { child.applyInitialPose(); } }
/** * Sets the local transform with the bind transforms */ protected void applyBindPose() { jointModelTransform.applyBindPose(localTransform, inverseModelBindMatrix, parent); updateModelTransforms(); for (Joint child : children.getArray()) { child.applyBindPose(); } }
selectedBones.put(ad.getArmature(), selectedjoint); System.err.println("-----------------------"); System.err.println("Selected Joint : " + selectedjoint.getName() + " in armature " + ad.getName()); System.err.println("Root Bone : " + (selectedjoint.getParent() == null)); System.err.println("-----------------------"); System.err.println("Local translation: " + selectedjoint.getLocalTranslation()); System.err.println("Local rotation: " + selectedjoint.getLocalRotation()); System.err.println("Local scale: " + selectedjoint.getLocalScale()); System.err.println("---"); System.err.println("Model translation: " + selectedjoint.getModelTransform().getTranslation()); System.err.println("Model rotation: " + selectedjoint.getModelTransform().getRotation()); System.err.println("Model scale: " + selectedjoint.getModelTransform().getScale()); System.err.println("---"); System.err.println("Bind inverse Transform: "); System.err.println(selectedjoint.getInverseModelBindMatrix()); return;
Joint root = new Joint("Root_Joint"); j1 = new Joint("Joint_1"); j2 = new Joint("Joint_2"); Joint j3 = new Joint("Joint_3"); root.addChild(j1); j1.addChild(j2); j2.addChild(j3); root.setLocalTranslation(new Vector3f(0, 0, 0.5f)); j1.setLocalTranslation(new Vector3f(0, 0.0f, -0.5f)); j2.setLocalTranslation(new Vector3f(0, 0.0f, -0.3f)); j3.setLocalTranslation(new Vector3f(0, 0, -0.2f)); Joint[] joints = new Joint[]{root, j1, j2, j3};
Joint joint = nameToJoint.get(jointName); Joint parent = nameToJoint.get(parentName); parent.addChild(joint); } else if (qName.equals("bone")) { assert elementStack.peek().equals("bones"); joint = new Joint(attribs.getValue("name")); int id = SAXUtil.parseInt(attribs.getValue("id")); indexToJoint.put(id, joint); nameToJoint.put(joint.getName(), joint); } else if (qName.equals("tracks")) { assert elementStack.peek().equals("animation");
logger.log(Level.WARNING, "Animation " + animationIndex + " (" + name + ") applies to joints that are not from the same skin: skin " + skinIndex + ", joint " + jw.joint.getName() + " from skin " + jw.skinIndex); continue; Vector3f[] translations = new Vector3f[]{joint.getLocalTranslation()}; Quaternion[] rotations = new Quaternion[]{joint.getLocalRotation()}; Vector3f[] scales = new Vector3f[]{joint.getLocalScale()}; TransformTrack track = new TransformTrack(joint, times, translations, rotations, scales); aTracks.add(track);
axis = null; } else if (qName.equals("bone")) { joint.getLocalTransform().setTranslation(position); joint.getLocalTransform().setRotation(rotation); if (scale != null) { joint.getLocalTransform().setScale(scale); translations.add(position.addLocal(joint.getLocalTranslation())); rotations.add(joint.getLocalRotation().mult(rotation, rotation)); if (scale != null) { scales.add(scale.multLocal(joint.getLocalScale())); }else{ scales.add(new Vector3f(1,1,1));
public Joint readNodeAsBone(int nodeIndex, int jointIndex, int skinIndex, Matrix4f inverseModelBindMatrix) throws IOException { JointWrapper jointWrapper = fetchFromCache("nodes", nodeIndex, JointWrapper.class); if (jointWrapper != null) { return jointWrapper.joint; } JsonObject nodeData = nodes.get(nodeIndex).getAsJsonObject(); String name = getAsString(nodeData, "name"); if (name == null) { name = "Joint_" + nodeIndex; } Joint joint = new Joint(name); Transform boneTransforms = null; boneTransforms = readTransforms(nodeData); joint.setLocalTransform(boneTransforms); joint.setInverseModelBindMatrix(inverseModelBindMatrix); addToCache("nodes", nodeIndex, new JointWrapper(joint, jointIndex, skinIndex), nodes.size()); return joint; }
private void findChildren(int nodeIndex) throws IOException { JointWrapper jw = fetchFromCache("nodes", nodeIndex, JointWrapper.class); JsonObject nodeData = nodes.get(nodeIndex).getAsJsonObject(); JsonArray children = nodeData.getAsJsonArray("children"); if (children != null) { for (JsonElement child : children) { int childIndex = child.getAsInt(); if (jw.children.contains(childIndex)) { //bone already has the child in its children continue; } JointWrapper cjw = fetchFromCache("nodes", childIndex, JointWrapper.class); if (cjw != null) { jw.joint.addChild(cjw.joint); jw.children.add(childIndex); } else { //The child might be a Node //Creating a dummy node to read the subgraph Node n = new Node(); readChild(n, child); Spatial s = n.getChild(0); //removing the spatial from the dummy node, it will be attached to the attachment node of the bone s.removeFromParent(); jw.attachedSpatial = s; } } } }
protected final void createSkeletonGeoms(Joint joint, Node joints, Node wires, Node outlines, List<Joint> deformingJoints) { Vector3f start = joint.getModelTransform().getTranslation().clone(); if (!joint.getChildren().isEmpty()) { ends = new Vector3f[joint.getChildren().size()]; for (int i = 0; i < joint.getChildren().size(); i++) { ends[i] = joint.getChildren().get(i).getModelTransform().getTranslation().clone(); Geometry jGeom = new Geometry(joint.getName() + "Joint", new JointShape()); jGeom.setLocalTranslation(start); attach(joints, deforms, jGeom); outlinesAttach = null; bGeom = new Geometry(joint.getName() + "Bone", m); setColor(bGeom, outlinesAttach == null ? outlineColor : baseColor); geomToJoint.put(bGeom, joint); attach(wireAttach, deforms, bGeom); if (outlinesAttach != null) { bGeomO = new Geometry(joint.getName() + "BoneOutline", mO); setColor(bGeomO, outlineColor); attach(outlinesAttach, deforms, bGeomO); for (Joint child : joint.getChildren()) { createSkeletonGeoms(child, joints, wires, outlines, deformingJoints);
/** * This methods sets this armature in its bind pose (aligned with the mesh to deform) * Note that this is only useful for debugging purpose. */ public void applyBindPose() { for (Joint joint : rootJoints) { joint.applyBindPose(); } }
Joint root = new Joint("Root_Joint"); j1 = new Joint("Joint_1"); j2 = new Joint("Joint_2"); Joint j3 = new Joint("Joint_3"); root.addChild(j1); j1.addChild(j2); j2.addChild(j3); root.setLocalTranslation(new Vector3f(0, 0, 0.5f)); j1.setLocalTranslation(new Vector3f(0, 0.0f, -0.5f)); j2.setLocalTranslation(new Vector3f(0, 0.0f, -0.3f)); j3.setLocalTranslation(new Vector3f(0, 0, -0.2f)); Joint[] joints = new Joint[]{root, j1, j2, j3};
@Override @SuppressWarnings("unchecked") public void read(JmeImporter im) throws IOException { InputCapsule input = im.getCapsule(this); name = input.readString("name", null); attachedNode = (Node) input.readSavable("attachedNode", null); targetGeometry = (Geometry) input.readSavable("targetGeometry", null); initialTransform = (Transform) input.readSavable("initialTransform", new Transform()); inverseModelBindMatrix = (Matrix4f) input.readSavable("inverseModelBindMatrix", inverseModelBindMatrix); ArrayList<Joint> childList = input.readSavableArrayList("children", null); for (int i = childList.size() - 1; i >= 0; i--) { this.addChild(childList.get(i)); } }
joint = fromBone(bone); j.addChild(joint); joints[index] = joint;
/** * returns the joint with the given name * * @param name * @return */ public Joint getJoint(String name) { for (int i = 0; i < jointList.length; i++) { if (jointList[i].getName().equals(name)) { return jointList[i]; } } return null; }
skinData.skinningControl.getAttachmentsNode(bw.joint.getName()).attachChild(bw.attachedSpatial);