public Node findByName(String targetName) { Node result = null; if (this.name.equals(targetName)) { result = this; } else { for (Node child : children) { result = child.findByName(targetName); if (result != null) { break; } } } return result; }
public Node findByName(String targetName) { Node result = null; if (this.name.equals(targetName)) { result = this; } else { for (Node child : children) { result = child.findByName(targetName); if (result != null) { break; } } } return result; }
private static List<AnimatedFrame> buildAnimationFrames(List<Bone> boneList, Node rootNode, Matrix4f rootTransformation) { int numFrames = rootNode.getAnimationFrames(); List<AnimatedFrame> frameList = new ArrayList<>(); for (int i = 0; i < numFrames; i++) { AnimatedFrame frame = new AnimatedFrame(); frameList.add(frame); int numBones = boneList.size(); for (int j = 0; j < numBones; j++) { Bone bone = boneList.get(j); Node node = rootNode.findByName(bone.getBoneName()); Matrix4f boneMatrix = Node.getParentTransforms(node, i); boneMatrix.mul(bone.getOffsetMatrix()); boneMatrix = new Matrix4f(rootTransformation).mul(boneMatrix); frame.setMatrix(j, boneMatrix); } } return frameList; }
private static List<AnimatedFrame> buildAnimationFrames(List<Bone> boneList, Node rootNode, Matrix4f rootTransformation) { int numFrames = rootNode.getAnimationFrames(); List<AnimatedFrame> frameList = new ArrayList<>(); for (int i = 0; i < numFrames; i++) { AnimatedFrame frame = new AnimatedFrame(); frameList.add(frame); int numBones = boneList.size(); for (int j = 0; j < numBones; j++) { Bone bone = boneList.get(j); Node node = rootNode.findByName(bone.getBoneName()); Matrix4f boneMatrix = Node.getParentTransforms(node, i); boneMatrix.mul(bone.getOffsetMatrix()); boneMatrix = new Matrix4f(rootTransformation).mul(boneMatrix); frame.setMatrix(j, boneMatrix); } } return frameList; }
private static Map<String, Animation> processAnimations(AIScene aiScene, List<Bone> boneList, Node rootNode, Matrix4f rootTransformation) { Map<String, Animation> animations = new HashMap<>(); // Process all animations int numAnimations = aiScene.mNumAnimations(); PointerBuffer aiAnimations = aiScene.mAnimations(); for (int i = 0; i < numAnimations; i++) { AIAnimation aiAnimation = AIAnimation.create(aiAnimations.get(i)); // Calculate transformation matrices for each node int numChanels = aiAnimation.mNumChannels(); PointerBuffer aiChannels = aiAnimation.mChannels(); for (int j = 0; j < numChanels; j++) { AINodeAnim aiNodeAnim = AINodeAnim.create(aiChannels.get(j)); String nodeName = aiNodeAnim.mNodeName().dataString(); Node node = rootNode.findByName(nodeName); buildTransFormationMatrices(aiNodeAnim, node); } List<AnimatedFrame> frames = buildAnimationFrames(boneList, rootNode, rootTransformation); Animation animation = new Animation(aiAnimation.mName().dataString(), frames, aiAnimation.mDuration()); animations.put(animation.getName(), animation); } return animations; }
private static Map<String, Animation> processAnimations(AIScene aiScene, List<Bone> boneList, Node rootNode, Matrix4f rootTransformation) { Map<String, Animation> animations = new HashMap<>(); // Process all animations int numAnimations = aiScene.mNumAnimations(); PointerBuffer aiAnimations = aiScene.mAnimations(); for (int i = 0; i < numAnimations; i++) { AIAnimation aiAnimation = AIAnimation.create(aiAnimations.get(i)); // Calculate transformation matrices for each node int numChanels = aiAnimation.mNumChannels(); PointerBuffer aiChannels = aiAnimation.mChannels(); for (int j = 0; j < numChanels; j++) { AINodeAnim aiNodeAnim = AINodeAnim.create(aiChannels.get(j)); String nodeName = aiNodeAnim.mNodeName().dataString(); Node node = rootNode.findByName(nodeName); buildTransFormationMatrices(aiNodeAnim, node); } List<AnimatedFrame> frames = buildAnimationFrames(boneList, rootNode, rootTransformation); Animation animation = new Animation(aiAnimation.mName().dataString(), frames, aiAnimation.mDuration()); animations.put(animation.getName(), animation); } return animations; }