com.jme3.math.Transform Java Examples
The following examples show how to use
com.jme3.math.Transform.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BoneLink.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Begin blending this link to a purely kinematic mode. * * @param submode enum value (not null) * @param blendInterval the duration of the blend interval (in seconds, * ≥0) */ public void blendToKinematicMode(KinematicSubmode submode, float blendInterval) { super.blendToKinematicMode(blendInterval); this.submode = submode; /* * Save initial bone transforms for blending. */ int numManagedBones = managedBones.length; for (int mbIndex = 0; mbIndex < numManagedBones; ++mbIndex) { Transform transform; if (prevBoneTransforms == null) { // this link not updated yet Joint managedBone = managedBones[mbIndex]; transform = managedBone.getLocalTransform().clone(); } else { transform = prevBoneTransforms[mbIndex]; } startBoneTransforms[mbIndex].set(transform); } }
Example #2
Source File: RagdollUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Updates a bone position and rotation. if the child bones are not in the * bone list this means, they are not associated with a physics shape. So * they have to be updated * * @param bone the bone * @param pos the position * @param rot the rotation * @param restoreBoneControl true → user-control flag should be set * @param boneList the names of all bones without collision shapes (not * null, unaffected) */ public static void setTransform(Bone bone, Vector3f pos, Quaternion rot, boolean restoreBoneControl, Set<String> boneList) { //we ensure that we have the control if (restoreBoneControl) { bone.setUserControl(true); } //we set te user transforms of the bone bone.setUserTransformsInModelSpace(pos, rot); for (Bone childBone : bone.getChildren()) { //each child bone that is not in the list is updated if (!boneList.contains(childBone.getName())) { Transform t = childBone.getCombinedTransform(pos, rot); setTransform(childBone, t.getTranslation(), t.getRotation(), restoreBoneControl, boneList); } } //we give back the control to the keyframed animation if (restoreBoneControl) { bone.setUserControl(false); } }
Example #3
Source File: FbxNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void setWorldBindPose(Matrix4f worldBindPose) { if (cachedWorldBindPose != null) { if (!cachedWorldBindPose.equals(worldBindPose)) { throw new UnsupportedOperationException("Bind poses don't match"); } } cachedWorldBindPose = worldBindPose; this.jmeWorldBindPose = new Transform(); this.jmeWorldBindPose.setTranslation(worldBindPose.toTranslationVector()); this.jmeWorldBindPose.setRotation(worldBindPose.toRotationQuat()); this.jmeWorldBindPose.setScale(worldBindPose.toScaleVector()); System.out.println("\tBind Pose for " + getName()); System.out.println(jmeWorldBindPose); float[] angles = new float[3]; jmeWorldBindPose.getRotation().toAngles(angles); System.out.println("Angles: " + angles[0] * FastMath.RAD_TO_DEG + ", " + angles[1] * FastMath.RAD_TO_DEG + ", " + angles[2] * FastMath.RAD_TO_DEG); }
Example #4
Source File: GeometryBatchFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Optimizes a scene by combining Geometry with the same material. * All Geometries found in the scene are detached from their parent and * a new Node containing the optimized Geometries is attached. * @param scene The scene to optimize * @param useLods true if you want the resulting geometry to keep lod information * @return The newly created optimized geometries attached to a node */ public static Node optimize(Node scene, boolean useLods) { ArrayList<Geometry> geoms = new ArrayList<Geometry>(); gatherGeoms(scene, geoms); List<Geometry> batchedGeoms = makeBatches(geoms, useLods); for (Geometry geom : batchedGeoms) { scene.attachChild(geom); } for (Iterator<Geometry> it = geoms.iterator(); it.hasNext();) { Geometry geometry = it.next(); geometry.removeFromParent(); } // Since the scene is returned unaltered the transform must be reset scene.setLocalTransform(Transform.IDENTITY); return scene; }
Example #5
Source File: RagdollUtils.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Updates a bone position and rotation. * if the child bones are not in the bone list this means, they are not associated with a physic shape. * So they have to be updated * @param bone the bone * @param pos the position * @param rot the rotation */ public static void setTransform(Bone bone, Vector3f pos, Quaternion rot, boolean restoreBoneControl, Set<String> boneList) { //we ensure that we have the control if (restoreBoneControl) { bone.setUserControl(true); } //we set te user transforms of the bone bone.setUserTransformsWorld(pos, rot); for (Bone childBone : bone.getChildren()) { //each child bone that is not in the list is updated if (!boneList.contains(childBone.getName())) { Transform t = childBone.getCombinedTransform(pos, rot); setTransform(childBone, t.getTranslation(), t.getRotation(), restoreBoneControl, boneList); } } //we give back the control to the keyframed animation if (restoreBoneControl) { bone.setUserControl(false); } }
Example #6
Source File: TestSweepTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleUpdate(float tpf) { float move = tpf * 1; boolean colliding = false; List<PhysicsSweepTestResult> sweepTest = bulletAppState.getPhysicsSpace().sweepTest(capsuleCollisionShape, new Transform(capsule.getWorldTranslation()), new Transform(capsule.getWorldTranslation().add(dist, 0, 0))); for (PhysicsSweepTestResult result : sweepTest) { if (result.getCollisionObject().getCollisionShape() != capsuleCollisionShape) { PhysicsCollisionObject collisionObject = result.getCollisionObject(); fpsText.setText("Almost colliding with " + collisionObject.getUserObject().toString()); colliding = true; } } if (!colliding) { // if the sweep is clear then move the spatial capsule.move(move, 0, 0); } }
Example #7
Source File: PMDBoneMarkControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override protected void controlUpdate(float tpf) { for (int i = 0; i < boneMarkArray.length; i++) { Matrix4f m = skeletonControl.getOffsetMatrices()[i].clone(); PMDBone bone = boneArray[i]; // if (bone.getBoneName().equals("右腕")) { // Matrix4f m2 = boneMarkArray[i].getLocalToWorldMatrix(new Matrix4f()).clone(); // m.invertLocal(); // m.loadIdentity(); Vector3f bonePos = new Vector3f(bone.getBoneHeadPos().x, bone.getBoneHeadPos().y, bone.getBoneHeadPos().z); // System.out.println("projectionMatrix = "+projectionMatrix); // System.out.println("bonePos1 = "+bonePos); m.mult(bonePos, bonePos); // System.out.println("bonePos2 = "+bonePos); Transform t = new Transform(m.toTranslationVector()); cam.getScreenCoordinates(bonePos, bonePos); // System.out.println("bonePos3 = "+bonePos); t.setTranslation(bonePos); boneMarkArray[i].setLocalTransform(t); // } // System.out.println("m2 = "+m2); } }
Example #8
Source File: RagUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Read an array of transforms from an input capsule. * * @param capsule the input capsule (not null) * @param fieldName the name of the field to read (not null) * @return a new array or null * @throws IOException from capsule */ static Transform[] readTransformArray(InputCapsule capsule, String fieldName) throws IOException { Savable[] tmp = capsule.readSavableArray(fieldName, null); Transform[] result; if (tmp == null) { result = null; } else { result = new Transform[tmp.length]; for (int i = 0; i < tmp.length; ++i) { result[i] = (Transform) tmp[i]; } } return result; }
Example #9
Source File: PhysicsLink.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * De-serialize this link, for example when loading from a J3O file. * * @param im importer (not null) * @throws IOException from importer */ @Override @SuppressWarnings("unchecked") public void read(JmeImporter im) throws IOException { InputCapsule ic = im.getCapsule(this); children = ic.readSavableArrayList("children", new ArrayList(1)); bone = (Joint) ic.readSavable("bone", null); control = (DacLinks) ic.readSavable("control", null); blendInterval = ic.readFloat("blendInterval", 1f); kinematicWeight = ic.readFloat("kinematicWeight", 1f); joint = (PhysicsJoint) ic.readSavable("joint", null); parent = (PhysicsLink) ic.readSavable("parent", null); rigidBody = (PhysicsRigidBody) ic.readSavable("rigidBody", null); kpTransform = (Transform) ic.readSavable("kpTransform", new Transform()); kpVelocity = (Vector3f) ic.readSavable("kpVelocity", new Vector3f()); localOffset = (Vector3f) ic.readSavable("offset", new Vector3f()); }
Example #10
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * returns the correct transform for a collisionshape in relation * to the ancestor for which the collisionshape is generated * @param spat * @param parent * @return */ private static Transform getTransform(Spatial spat, Spatial parent) { Transform shapeTransform = new Transform(); Spatial parentNode = spat.getParent() != null ? spat.getParent() : spat; Spatial currentSpatial = spat; //if we have parents combine their transforms while (parentNode != null) { if (parent == currentSpatial) { //real parent -> only apply scale, not transform Transform trans = new Transform(); trans.setScale(currentSpatial.getLocalScale()); shapeTransform.combineWithParent(trans); parentNode = null; } else { shapeTransform.combineWithParent(currentSpatial.getLocalTransform()); parentNode = currentSpatial.getParent(); currentSpatial = parentNode; } } return shapeTransform; }
Example #11
Source File: ConstraintDefinitionSizeLimit.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void bake(Transform ownerTransform, Transform targetTransform, float influence) { Vector3f scale = ownerTransform.getScale(); if ((flag & LIMIT_XMIN) != 0 && scale.x < limits[0][0]) { scale.x -= (scale.x - limits[0][0]) * influence; } if ((flag & LIMIT_XMAX) != 0 && scale.x > limits[0][1]) { scale.x -= (scale.x - limits[0][1]) * influence; } if ((flag & LIMIT_YMIN) != 0 && scale.y < limits[1][0]) { scale.y -= (scale.y - limits[1][0]) * influence; } if ((flag & LIMIT_YMAX) != 0 && scale.y > limits[1][1]) { scale.y -= (scale.y - limits[1][1]) * influence; } if ((flag & LIMIT_ZMIN) != 0 && scale.z < limits[2][0]) { scale.z -= (scale.z - limits[2][0]) * influence; } if ((flag & LIMIT_ZMAX) != 0 && scale.z > limits[2][1]) { scale.z -= (scale.z - limits[2][1]) * influence; } }
Example #12
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * returns the correct transform for a collisionshape in relation * to the ancestor for which the collisionshape is generated * @param spat * @param parent * @return */ private static Transform getTransform(Spatial spat, Spatial parent) { Transform shapeTransform = new Transform(); Spatial parentNode = spat.getParent() != null ? spat.getParent() : spat; Spatial currentSpatial = spat; //if we have parents combine their transforms while (parentNode != null) { if (parent == currentSpatial) { //real parent -> only apply scale, not transform Transform trans = new Transform(); trans.setScale(currentSpatial.getLocalScale()); shapeTransform.combineWithParent(trans); parentNode = null; } else { shapeTransform.combineWithParent(currentSpatial.getLocalTransform()); parentNode = currentSpatial.getParent(); currentSpatial = parentNode; } } return shapeTransform; }
Example #13
Source File: DacLinks.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Create a jointless BoneLink for the named bone, and add it to the * boneLinks map. * * @param boneName the name of the bone to be linked (not null) * @param vertexLocations the set of vertex locations (not null, not empty) */ private void createBoneLink(String boneName, VectorSet vertexLocations) { Joint bone = findBone(boneName); Transform boneToMesh = bone.getModelTransform(); Transform meshToBone = boneToMesh.invert(); //logger3.log(Level.INFO, "meshToBone = {0}", meshToBone); /* * Create the CollisionShape and locate the center of mass. */ CollisionShape shape; Vector3f center; if (vertexLocations == null || vertexLocations.numVectors() == 0) { throw new IllegalStateException("no vertex for " + boneName); } else { center = vertexLocations.mean(null); center.subtractLocal(bone.getModelTransform().getTranslation()); shape = createShape(meshToBone, center, vertexLocations); } meshToBone.getTranslation().zero(); float mass = super.mass(boneName); Vector3f offset = meshToBone.transformVector(center, null); BoneLink link = new BoneLink(this, bone, shape, mass, offset); boneLinks.put(boneName, link); }
Example #14
Source File: GeometryBatchFactory.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Optimizes a scene by combining Geometry with the same material. * All Geometries found in the scene are detached from their parent and * a new Node containing the optimized Geometries is attached. * @param scene The scene to optimize * @param useLods true if you want the resulting geometry to keep lod information * @return The newly created optimized geometries attached to a node */ public static Node optimize(Node scene, boolean useLods) { ArrayList<Geometry> geoms = new ArrayList<Geometry>(); gatherGeoms(scene, geoms); List<Geometry> batchedGeoms = makeBatches(geoms, useLods); for (Geometry geom : batchedGeoms) { scene.attachChild(geom); } for (Iterator<Geometry> it = geoms.iterator(); it.hasNext();) { Geometry geometry = it.next(); geometry.removeFromParent(); } // Since the scene is returned unaltered the transform must be reset scene.setLocalTransform(Transform.IDENTITY); return scene; }
Example #15
Source File: DacLinks.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Calculate the physics transform to match the specified skeleton bone. * * @param bone the skeleton bone to match (not null, unaffected) * @param localOffset the location of the body's center (in the bone's local * coordinates, not null, unaffected) * @param storeResult storage for the result (modified if not null) * @return the calculated physics transform (either storeResult or a new * transform, not null) */ Transform physicsTransform(Joint bone, Vector3f localOffset, Transform storeResult) { Transform result = (storeResult == null) ? new Transform() : storeResult; /* * Start with the body's transform in the bone's local coordinates. */ result.setTranslation(localOffset); result.setRotation(rotateIdentity); result.setScale(1f); /* * Convert to mesh coordinates. */ Transform localToMesh = bone.getModelTransform(); result.combineWithParent(localToMesh); /* * Convert to world (physics-space) coordinates. */ Transform meshToWorld = meshTransform(null); result.combineWithParent(meshToWorld); return result; }
Example #16
Source File: VirtualTrack.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Sets the transform for the given frame. * * @param frameIndex * the frame for which the transform will be set * @param transform * the transformation to be set */ public void setTransform(int frameIndex, Transform transform) { if (translations == null) { translations = this.createList(Vector3f.ZERO, frameIndex); } this.append(translations, Vector3f.ZERO, frameIndex - translations.size()); translations.add(transform.getTranslation().clone()); if (rotations == null) { rotations = this.createList(Quaternion.IDENTITY, frameIndex); } this.append(rotations, Quaternion.IDENTITY, frameIndex - rotations.size()); rotations.add(transform.getRotation().clone()); if (scales == null) { scales = this.createList(Vector3f.UNIT_XYZ, frameIndex); } this.append(scales, Vector3f.UNIT_XYZ, frameIndex - scales.size()); scales.add(transform.getScale().clone()); }
Example #17
Source File: RagdollUtils.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Updates a bone position and rotation. * if the child bones are not in the bone list this means, they are not associated with a physic shape. * So they have to be updated * @param bone the bone * @param pos the position * @param rot the rotation */ public static void setTransform(Bone bone, Vector3f pos, Quaternion rot, boolean restoreBoneControl, Set<String> boneList) { //we ensure that we have the control if (restoreBoneControl) { bone.setUserControl(true); } //we set te user transforms of the bone bone.setUserTransformsWorld(pos, rot); for (Bone childBone : bone.getChildren()) { //each child bone that is not in the list is updated if (!boneList.contains(childBone.getName())) { Transform t = childBone.getCombinedTransform(pos, rot); setTransform(childBone, t.getTranslation(), t.getRotation(), restoreBoneControl, boneList); } } //we give back the control to the keyframed animation if (restoreBoneControl) { bone.setUserControl(false); } }
Example #18
Source File: ConstraintDefinitionSizeLike.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void bake(Transform ownerTransform, Transform targetTransform, float influence) { Vector3f ownerScale = ownerTransform.getScale(); Vector3f targetScale = targetTransform.getScale(); Vector3f offset = Vector3f.ZERO; if ((flag & LOCLIKE_OFFSET) != 0) {// we add the original scale to the // copied scale offset = ownerScale.clone(); } if ((flag & SIZELIKE_X) != 0) { ownerScale.x = targetScale.x * influence + (1.0f - influence) * ownerScale.x; } if ((flag & SIZELIKE_Y) != 0) { ownerScale.y = targetScale.y * influence + (1.0f - influence) * ownerScale.y; } if ((flag & SIZELIKE_Z) != 0) { ownerScale.z = targetScale.z * influence + (1.0f - influence) * ownerScale.z; } ownerScale.addLocal(offset); }
Example #19
Source File: CollisionShapeFactory.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Calculate the correct transform for a collision shape relative to the * ancestor for which the shape was generated. * * @param spat * @param parent * @return a new instance (not null) */ private static Transform getTransform(Spatial spat, Spatial parent) { Transform shapeTransform = new Transform(); Spatial parentNode = spat.getParent() != null ? spat.getParent() : spat; Spatial currentSpatial = spat; //if we have parents combine their transforms while (parentNode != null) { if (parent == currentSpatial) { //real parent -> only apply scale, not transform Transform trans = new Transform(); trans.setScale(currentSpatial.getLocalScale()); shapeTransform.combineWithParent(trans); parentNode = null; } else { shapeTransform.combineWithParent(currentSpatial.getLocalTransform()); parentNode = currentSpatial.getParent(); currentSpatial = parentNode; } } return shapeTransform; }
Example #20
Source File: SimulationNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Resets the node's feature to its starting transformation. */ private void reset() { if (spatial != null) { spatial.setLocalTransform(spatialStartTransform); for (SimulationNode child : children) { child.reset(); } } else if (skeleton != null) { for (Entry<Bone, Transform> entry : boneStartTransforms.entrySet()) { Transform t = entry.getValue(); entry.getKey().setBindTransforms(t.getTranslation(), t.getRotation(), t.getScale()); } skeleton.reset(); } }
Example #21
Source File: CollisionShapeFactory.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a hull collision shape for the specified geometry. * * @param geom the geometry on which to base the shape (not null) * @param parent */ private static HullCollisionShape createSingleDynamicMeshShape(Geometry geom, Spatial parent) { Mesh mesh = geom.getMesh(); Transform trans = getTransform(geom, parent); if (mesh != null) { HullCollisionShape dynamicShape = new HullCollisionShape(mesh); dynamicShape.setScale(trans.getScale()); return dynamicShape; } else { return null; } }
Example #22
Source File: ConstraintDefinitionLocLimit.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void bake(Transform ownerTransform, Transform targetTransform, float influence) { if (this.getOwner() instanceof Bone && ((Bone) this.getOwner()).getParent() != null) { // location limit does not work on bones who have parent return; } Vector3f translation = ownerTransform.getTranslation(); if ((flag & LIMIT_XMIN) != 0 && translation.x < limits[0][0]) { translation.x -= (translation.x - limits[0][0]) * influence; } if ((flag & LIMIT_XMAX) != 0 && translation.x > limits[0][1]) { translation.x -= (translation.x - limits[0][1]) * influence; } if ((flag & LIMIT_YMIN) != 0 && translation.y < limits[1][0]) { translation.y -= (translation.y - limits[1][0]) * influence; } if ((flag & LIMIT_YMAX) != 0 && translation.y > limits[1][1]) { translation.y -= (translation.y - limits[1][1]) * influence; } if ((flag & LIMIT_ZMIN) != 0 && translation.z < limits[2][0]) { translation.z -= (translation.z - limits[2][0]) * influence; } if ((flag & LIMIT_ZMAX) != 0 && translation.z > limits[2][1]) { translation.z -= (translation.z - limits[2][1]) * influence; } }
Example #23
Source File: BoneLink.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Calculate the local bone transform to match the physics transform of the * rigid body. * * @param storeResult storage for the result (modified if not null) * @return the calculated bone transform (in local coordinates, either * storeResult or a new transform, not null) */ private Transform localBoneTransform(Transform storeResult) { Transform result = (storeResult == null) ? new Transform() : storeResult; Vector3f location = result.getTranslation(); Quaternion orientation = result.getRotation(); Vector3f scale = result.getScale(); /* * Start with the rigid body's transform in physics/world coordinates. */ PhysicsRigidBody body = getRigidBody(); body.getPhysicsLocation(result.getTranslation()); body.getPhysicsRotation(result.getRotation()); result.setScale(body.getCollisionShape().getScale()); /* * Convert to mesh coordinates. */ Transform worldToMesh = getControl().meshTransform(null).invert(); result.combineWithParent(worldToMesh); /* * Convert to the bone's local coordinate system by factoring out the * parent bone's transform. */ Joint parentBone = getBone().getParent(); RagUtils.meshToLocal(parentBone, result); /* * Subtract the body's local offset, rotated and scaled. */ Vector3f parentOffset = localOffset(null); parentOffset.multLocal(scale); orientation.mult(parentOffset, parentOffset); location.subtractLocal(parentOffset); return result; }
Example #24
Source File: BoneLink.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Serialize this link, for example when saving to a J3O file. * * @param ex exporter (not null) * @throws IOException from exporter */ @Override public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule oc = ex.getCapsule(this); oc.write(managedBones, "managedBones", null); oc.write(submode, "submode", KinematicSubmode.Animated); oc.write(prevBoneTransforms, "prevBoneTransforms", new Transform[0]); oc.write(startBoneTransforms, "startBoneTransforms", new Transform[0]); }
Example #25
Source File: SpatialConstraint.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void apply(int frame) { Transform ownerTransform = constraintHelper.getTransform(ownerOMA, null, ownerSpace); Transform targetTransform = targetOMA != null ? constraintHelper.getTransform(targetOMA, subtargetName, targetSpace) : null; constraintDefinition.bake(ownerTransform, targetTransform, this.ipo.calculateValue(frame)); constraintHelper.applyTransform(ownerOMA, subtargetName, ownerSpace, ownerTransform); }
Example #26
Source File: SeparateJointModelTransform.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void applyBindPose(Transform localTransform, Matrix4f inverseModelBindMatrix, Joint parent) { localTransform.fromTransformMatrix(inverseModelBindMatrix.invert()); if (parent != null) { localTransform.combineWithParent(parent.getModelTransform().invert()); } }
Example #27
Source File: BlendAction.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void collect(HasLocalTransform target, Transform tr) { if (collectTransformDelegate != null) { collectTransformDelegate.collectTransform(target, tr, this.getWeight(), this); } else { if (getTransitionWeight() == 1) { target.setLocalTransform(tr); } else { Transform trans = target.getLocalTransform(); trans.interpolateTransforms(trans, tr, getTransitionWeight()); target.setLocalTransform(trans); } } }
Example #28
Source File: BlendAction.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void collectTransform(HasLocalTransform target, Transform t, float weight, BlendableAction source) { Transform tr = targetMap.get(target); if (weight == 1) { tr.set(t); } else if (weight > 0) { tr.interpolateTransforms(tr, t, weight); } if (source == actions[secondActiveIndex]) { collect(target, tr); } }
Example #29
Source File: ConstraintDefinitionDistLimit.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void bake(Transform ownerTransform, Transform targetTransform, float influence) { if (this.getOwner() instanceof Bone && ((Bone) this.getOwner()).getParent() != null) { // distance limit does not work on bones who have parent return; } Vector3f v = ownerTransform.getTranslation().subtract(targetTransform.getTranslation()); float currentDistance = v.length(); switch (mode) { case LIMITDIST_INSIDE: if (currentDistance >= dist) { v.normalizeLocal(); v.multLocal(dist + (currentDistance - dist) * (1.0f - influence)); ownerTransform.getTranslation().set(v.addLocal(targetTransform.getTranslation())); } break; case LIMITDIST_ONSURFACE: if (currentDistance > dist) { v.normalizeLocal(); v.multLocal(dist + (currentDistance - dist) * (1.0f - influence)); ownerTransform.getTranslation().set(v.addLocal(targetTransform.getTranslation())); } else if (currentDistance < dist) { v.normalizeLocal().multLocal(dist * influence); ownerTransform.getTranslation().set(targetTransform.getTranslation().add(v)); } break; case LIMITDIST_OUTSIDE: if (currentDistance <= dist) { v = targetTransform.getTranslation().subtract(ownerTransform.getTranslation()).normalizeLocal().multLocal(dist * influence); ownerTransform.getTranslation().set(targetTransform.getTranslation().add(v)); } break; default: throw new IllegalStateException("Unknown distance limit constraint mode: " + mode); } }
Example #30
Source File: SeparateJointModelTransform.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void updateModelTransform(Transform localTransform, Joint parent) { modelTransform.set(localTransform); if (parent != null) { modelTransform.combineWithParent(parent.getModelTransform()); } }