public void setAreaType(AreaType type){ switch (type){ case Spherical: area = new SphereProbeArea(Vector3f.ZERO, 1.0f); break; case OrientedBox: area = new OrientedBoxProbeArea(new Transform()); area.setCenter(position); break; } }
@Override public void write(JmeExporter e) throws IOException { OutputCapsule oc = e.getCapsule(this); oc.write(transform, "transform", new Transform()); }
/** * @return A {@link Transform} that converts from the FBX file coordinate * system to jME3 coordinate system. * jME3's coordinate system is: * <ul> * <li>Units are specified in meters.</li> * <li>Orientation is right-handed with Y-up.</li> * </ul> */ public Transform getGlobalTransform() { // Default unit scale factor is 1 (centimeters), // convert to meters. float scale = unitScaleFactor / 100.0f; // TODO: handle rotation return new Transform(Vector3f.ZERO, Quaternion.IDENTITY, new Vector3f(scale, scale, scale)); }
/** * Constructor instantiates a new <code>Spatial</code> object setting the * rotation, translation and scale value to defaults. * * @param name * the name of the scene element. This is required for * identification and comparison purposes. */ protected Spatial(String name) { this.name = name; localTransform = new Transform(); worldTransform = new Transform(); localLights = new LightList(this); worldLights = new LightList(this); localOverrides = new SafeArrayList<>(MatParamOverride.class); worldOverrides = new SafeArrayList<>(MatParamOverride.class); refreshFlags |= RF_BOUND; }
public Transform getModelBindInverseTransform() { Transform t = new Transform(); t.setTranslation(modelBindInversePos); t.setRotation(modelBindInverseRot); if (modelBindInverseScale != null) { t.setScale(modelBindInverseScale); } return t; }
@Override public void read(JmeImporter i) throws IOException { InputCapsule ic = i.getCapsule(this); transform = (Transform) ic.readSavable("transform", new Transform()); updateMatrix(); }
public Transform invert() { Transform t = new Transform(); t.fromTransformMatrix(toTransformMatrix().invertLocal()); return t; }
public Transform toTransform() { return new Transform(translation.toVector3f(), rotation.toQuaternion(), scale.toVector3f()); }
public Transform getBindInverseTransform() { Transform t = new Transform(); t.setTranslation(bindPos); t.setRotation(bindRot); if (bindScale != null) { t.setScale(bindScale); } return t.invert(); }
private static void relocateSpatial(Spatial spatial, Transform originalWorldTransform, Transform newWorldTransform) { Transform localTransform = new Transform(); localTransform.set(originalWorldTransform); localTransform.combineWithParent(newWorldTransform.invert()); spatial.setLocalTransform(localTransform); }
@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)); } }
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); }
@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); } } }
@Override public void write(JmeExporter ex) throws IOException { OutputCapsule output = ex.getCapsule(this); output.write(name, "name", null); output.write(attachedNode, "attachedNode", null); output.write(targetGeometry, "targetGeometry", null); output.write(initialTransform, "initialTransform", new Transform()); output.write(inverseModelBindMatrix, "inverseModelBindMatrix", new Matrix4f()); output.writeSavableArrayList(new ArrayList(children), "children", null); }
/** * 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; }
/** * Returns the local transform of this bone combined with the given position and rotation * @param position a position * @param rotation a rotation */ public Transform getCombinedTransform(Vector3f position, Quaternion rotation) { if(tmpTransform == null){ tmpTransform = new Transform(); } rotation.mult(localPos, tmpTransform.getTranslation()).addLocal(position); tmpTransform.setRotation(rotation).getRotation().multLocal(localRot); return tmpTransform; }
private static void applyInverse(Vector3f translation, Quaternion rotation, Vector3f scale, Transform inverseBindPose) { Transform t = new Transform(); t.setTranslation(translation); t.setRotation(rotation); if (scale != null) { t.setScale(scale); } t.combineWithParent(inverseBindPose); t.getTranslation(translation); t.getRotation(rotation); if (scale != null) { t.getScale(scale); } }
@Override public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) { if (influence == 0 || targetTransform == null) { return;// no need to do anything } Object target = this.getTarget();// Bone or Node Object owner = this.getOwner();// Bone or Node if (!target.getClass().equals(owner.getClass())) { ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class); TempVars tempVars = TempVars.get(); Matrix4f m = constraintHelper.toMatrix(targetTransform, tempVars.tempMat4); tempVars.tempMat42.set(BoneContext.BONE_ARMATURE_TRANSFORMATION_MATRIX); if (target instanceof Bone) { tempVars.tempMat42.invertLocal(); } m = m.multLocal(tempVars.tempMat42); tempVars.release(); targetTransform = new Transform(m.toTranslationVector(), m.toRotationQuat(), m.toScaleVector()); } this.applyOwnerTransform(targetTransform, ownerSpace); }
result.multLocal(scaleMat).multLocal(rotationMat).multLocal(translationMat); Transform t = new Transform(); t.fromTransformMatrix(result);
/** * This method calculates local transformation for the object. Parentage is * taken under consideration. * * @param objectStructure * the object's structure * @return objects transformation relative to its parent */ public Transform getTransformation(Structure objectStructure, BlenderContext blenderContext) { TempVars tempVars = TempVars.get(); Matrix4f parentInv = tempVars.tempMat4; Pointer pParent = (Pointer) objectStructure.getFieldValue("parent"); if (pParent.isNotNull()) { Structure parentObjectStructure = (Structure) blenderContext.getLoadedFeature(pParent.getOldMemoryAddress(), LoadedDataType.STRUCTURE); this.getMatrix(parentObjectStructure, "obmat", fixUpAxis, parentInv).invertLocal(); } else { parentInv.loadIdentity(); } Matrix4f globalMatrix = this.getMatrix(objectStructure, "obmat", fixUpAxis, tempVars.tempMat42); Matrix4f localMatrix = parentInv.multLocal(globalMatrix); this.getSizeSignums(objectStructure, tempVars.vect1); localMatrix.toTranslationVector(tempVars.vect2); localMatrix.toRotationQuat(tempVars.quat1); localMatrix.toScaleVector(tempVars.vect3); Transform t = new Transform(tempVars.vect2, tempVars.quat1.normalizeLocal(), tempVars.vect3.multLocal(tempVars.vect1)); tempVars.release(); return t; }