private boolean testHardwareSupported(RenderManager rm) { //Only 255 bones max supported with hardware skinning if (skeleton.getBoneCount() > 255) { return false; } switchToHardware(); try { rm.preloadScene(spatial); return true; } catch (RendererException e) { Logger.getLogger(SkeletonControl.class.getName()).log(Level.WARNING, "Could not enable HW skinning due to shader compile error:", e); return false; } }
/** * Add a single bone to be influenced by this animation channel. */ public void addBone(Bone bone) { int boneIndex = control.getSkeleton().getBoneIndex(bone); if(affectedBones == null) { affectedBones = new BitSet(control.getSkeleton().getBoneCount()); } affectedBones.set(boneIndex); }
@Override public void apply(Node node, BlenderContext blenderContext) { if (invalid) { LOGGER.log(Level.WARNING, "Armature modifier is invalid! Cannot be applied to: {0}", node.getName()); } if (modifying) { TemporalMesh temporalMesh = this.getTemporalMesh(node); if (temporalMesh != null) { LOGGER.log(Level.FINE, "Applying armature modifier to: {0}", temporalMesh); LOGGER.fine("Creating map between bone name and its index."); for (int i = 0; i < skeleton.getBoneCount(); ++i) { Bone bone = skeleton.getBone(i); temporalMesh.addBoneIndex(bone.getName(), i); } temporalMesh.applyAfterMeshCreate(this); } else { LOGGER.log(Level.WARNING, "Cannot find temporal mesh for node: {0}. The modifier will NOT be applied!", node); } } } }
/** * Remove any bones without vertices from the boneList, so that every hull * shape will contain at least 1 vertex. */ private void filterBoneList(SkeletonControl skeletonControl) { Mesh[] targets = skeletonControl.getTargets(); Skeleton skel = skeletonControl.getSkeleton(); for (int boneI = 0; boneI < skel.getBoneCount(); boneI++) { String boneName = skel.getBone(boneI).getName(); if (boneList.contains(boneName)) { boolean hasVertices = RagdollUtils.hasVertices(boneI, targets, weightThreshold); if (!hasVertices) { boneList.remove(boneName); } } } }
for (int i = 0; i < skeleton.getBoneCount(); ++i) { String boneName = skeleton.getBone(i).getName(); if (boneName != null && boneName.length() > 0) {
/** * Remove any bones without vertices from the boneList, so that every hull * shape will contain at least 1 vertex. */ private void filterBoneList(SkeletonControl skeletonControl) { Mesh[] targets = skeletonControl.getTargets(); Skeleton skel = skeletonControl.getSkeleton(); for (int boneI = 0; boneI < skel.getBoneCount(); boneI++) { String boneName = skel.getBone(boneI).getName(); if (boneList.contains(boneName)) { boolean hasVertices = RagdollUtils.hasVertices(boneI, targets, weightThreshold); if (!hasVertices) { boneList.remove(boneName); } } } }
private void switchToHardware() { numberOfBonesParam.setEnabled(true); boneMatricesParam.setEnabled(true); // Next full 10 bones (e.g. 30 on 24 bones) int numBones = ((skeleton.getBoneCount() / 10) + 1) * 10; numberOfBonesParam.setValue(numBones); for (Geometry geometry : targets) { Mesh mesh = geometry.getMesh(); if (mesh != null && mesh.isAnimated()) { mesh.prepareForAnim(false); } } }
/** * The method updates the geometry according to the poitions of the bones. */ public void updateGeometry() { VertexBuffer vb = this.getBuffer(Type.Position); FloatBuffer posBuf = this.getFloatBuffer(Type.Position); posBuf.clear(); for (int i = 0; i < skeleton.getBoneCount(); ++i) { Bone bone = skeleton.getBone(i); Vector3f head = bone.getModelSpacePosition(); posBuf.put(head.getX()).put(head.getY()).put(head.getZ()); if (boneLengths != null) { Vector3f tail = head.add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i)))); posBuf.put(tail.getX()).put(tail.getY()).put(tail.getZ()); } } posBuf.flip(); vb.updateData(posBuf); this.updateBound(); }
/** * The method updates the geometry according to the positions of the bones. */ public void updateGeometry() { VertexBuffer vb = this.getBuffer(Type.Position); FloatBuffer posBuf = this.getFloatBuffer(Type.Position); posBuf.clear(); for (int i = 0; i < skeleton.getBoneCount(); ++i) { Bone bone = skeleton.getBone(i); Vector3f head = bone.getModelSpacePosition(); posBuf.put(head.getX()).put(head.getY()).put(head.getZ()); if (boneLengths != null) { Vector3f tail = head.add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i)))); posBuf.put(tail.getX()).put(tail.getY()).put(tail.getZ()); } } posBuf.flip(); vb.updateData(posBuf); this.updateBound(); } }
@Override public void visit(Spatial spatial) { SkeletonControl control = spatial.getControl(SkeletonControl.class); if (control != null) { Armature armature = skeletonArmatureMap.get(control.getSkeleton()); SkinningControl skinningControl = new SkinningControl(armature); Map<String, List<Spatial>> attachedSpatials = new HashMap<>(); for (int i = 0; i < control.getSkeleton().getBoneCount(); i++) { Bone b = control.getSkeleton().getBone(i); Node n = control.getAttachmentsNode(b.getName()); n.removeFromParent(); if (!n.getChildren().isEmpty()) { attachedSpatials.put(b.getName(), n.getChildren()); } } spatial.removeControl(control); spatial.addControl(skinningControl); for (String name : attachedSpatials.keySet()) { List<Spatial> spatials = attachedSpatials.get(name); for (Spatial child : spatials) { skinningControl.getAttachmentsNode(name).attachChild(child); } } } }
/** * Creates a points with bone lengths data. If the data is supplied then the points will show both head and tail of each bone. * @param skeleton * the skeleton that will be shown * @param boneLengths * a map between the bone's index and the bone's length */ public SkeletonPoints(Skeleton skeleton, Map<Integer, Float> boneLengths) { this.skeleton = skeleton; this.setMode(Mode.Points); int pointsCount = skeleton.getBoneCount(); if (boneLengths != null) { this.boneLengths = boneLengths; pointsCount *= 2; } VertexBuffer pb = new VertexBuffer(Type.Position); FloatBuffer fpb = BufferUtils.createFloatBuffer(pointsCount * 3); pb.setupData(Usage.Stream, 3, Format.Float, fpb); this.setBuffer(pb); this.updateCounts(); }
Joint[] joints = new Joint[skeleton.getBoneCount()]; for (int i = 0; i < skeleton.getBoneCount(); i++) { Bone b = skeleton.getBone(i); Joint j = joints[i];
for (int i = 0; i < skeleton.getBoneCount(); ++i) { Bone bone = skeleton.getBone(i); boneStartTransforms.put(bone, new Transform(bone.getBindPosition(), bone.getBindRotation(), bone.getBindScale()));
/** * The method updates the geometry according to the poitions of the bones. */ public void updateGeometry() { VertexBuffer vb = this.getBuffer(Type.Position); FloatBuffer posBuf = this.getFloatBuffer(Type.Position); posBuf.clear(); for (int i = 0; i < skeleton.getBoneCount(); ++i) { Bone bone = skeleton.getBone(i); Vector3f parentTail = bone.getModelSpacePosition().add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i)))); for (Bone child : bone.getChildren()) { Vector3f childHead = child.getModelSpacePosition(); Vector3f v = childHead.subtract(parentTail); float pointDelta = v.length() / POINT_AMOUNT; v.normalizeLocal().multLocal(pointDelta); Vector3f pointPosition = parentTail.clone(); for (int j = 0; j < POINT_AMOUNT; ++j) { posBuf.put(pointPosition.getX()).put(pointPosition.getY()).put(pointPosition.getZ()); pointPosition.addLocal(v); } } } posBuf.flip(); vb.updateData(posBuf); this.updateBound(); }
for (int boneI = 0; boneI < skeleton.getBoneCount(); boneI++) { String boneName = skeleton.getBone(boneI).getName(); boneList.add(boneName);
for (int boneI = 0; boneI < skeleton.getBoneCount(); boneI++) { String boneName = skeleton.getBone(boneI).getName(); boneList.add(boneName);
int lineVerticesCount = skeleton.getBoneCount(); if (boneLengths != null) { this.boneLengths = boneLengths;
private Animation[] createAnimations(DAENode animationsNode, Skeleton skeleton) { List<Animation> list = new ArrayList<Animation>(); for (int i = 0; i < skeleton.getBoneCount(); i++) { Bone bone = skeleton.getBone(i); List<Animation> animations = createAnimationList(animationsNode, bone, skeleton); list.addAll(animations); } return list.toArray(new Animation[list.size()]); }
/** * Add a single bone to be influenced by this animation channel. */ public void addBone(Bone bone) { int boneIndex = control.getSkeleton().getBoneIndex(bone); if(affectedBones == null) { affectedBones = new BitSet(control.getSkeleton().getBoneCount()); } affectedBones.set(boneIndex); }
/** * Add a single bone to be influenced by this animation channel. */ public void addBone(Bone bone) { int boneIndex = control.getSkeleton().getBoneIndex(bone); if(affectedBones == null) { affectedBones = new BitSet(control.getSkeleton().getBoneCount()); } affectedBones.set(boneIndex); }