Joint joint = nameToJoint.get(jointName); Joint parent = nameToJoint.get(parentName); parent.addChild(joint); } else if (qName.equals("bone")) { assert elementStack.peek().equals("bones");
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; } } } }
@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;