/** * Checks if the first given OMA points to a parent of the second one. * The parent need not to be the direct one. This method should be called when we are sure * that both of the features are alred loaded because it does not check it. * The OMA's should point to a spatials, otherwise the function will throw ClassCastException. * @param supposedParentOMA * the OMA of the node that we suppose might be a parent of the second one * @param spatialOMA * the OMA of the scene's node * @return <b>true</b> if the first given OMA points to a parent of the second one and <b>false</b> otherwise */ public boolean isParent(Long supposedParentOMA, Long spatialOMA) { Spatial supposedParent = (Spatial) blenderContext.getLoadedFeature(supposedParentOMA, LoadedDataType.FEATURE); Spatial spatial = (Spatial) blenderContext.getLoadedFeature(spatialOMA, LoadedDataType.FEATURE); Spatial parent = spatial.getParent(); while (parent != null) { if (parent.equals(supposedParent)) { return true; } parent = parent.getParent(); } return false; }
/** * <code>detachChild</code> removes a given child from the node's list. * This child will no longer be maintained. * * @param child * the child to remove. * @return the index the child was at. -1 if the child was not in the list. */ public int detachChild(Spatial child) { if (child == null) throw new NullPointerException(); if (child.getParent() == this) { int index = children.indexOf(child); if (index != -1) { detachChildAt(index); } return index; } return -1; }
/** * The method bakes all available and valid constraints. * * @param blenderContext * the blender context */ public void bakeConstraints(BlenderContext blenderContext) { Set<Long> owners = new HashSet<Long>(); for (Constraint constraint : blenderContext.getAllConstraints()) { if(constraint instanceof BoneConstraint) { BoneContext boneContext = blenderContext.getBoneContext(constraint.ownerOMA); owners.add(boneContext.getArmatureObjectOMA()); } else { Spatial spatial = (Spatial) blenderContext.getLoadedFeature(constraint.ownerOMA, LoadedDataType.FEATURE); while (spatial.getParent() != null) { spatial = spatial.getParent(); } owners.add((Long)blenderContext.getMarkerValue(ObjectHelper.OMA_MARKER, spatial)); } } List<SimulationNode> simulationRootNodes = new ArrayList<SimulationNode>(owners.size()); for(Long ownerOMA : owners) { simulationRootNodes.add(new SimulationNode(ownerOMA, blenderContext)); } for (SimulationNode node : simulationRootNodes) { node.simulate(); } }
/** * 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; }
/** * 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; }
/** * applies the current transform to the given jme Node if the location has been updated on the physics side * @param spatial */ public boolean applyTransform(Spatial spatial) { if (!physicsLocationDirty) { return false; } if (!applyPhysicsLocal && spatial.getParent() != null) { localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(worldRotationQuat); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(worldLocation); spatial.setLocalRotation(worldRotationQuat); } physicsLocationDirty = false; return true; }
public void applyWheelTransform() { if (wheelSpatial == null) { return; } Quaternion localRotationQuat = wheelSpatial.getLocalRotation(); Vector3f localLocation = wheelSpatial.getLocalTranslation(); if (!applyLocal && wheelSpatial.getParent() != null) { localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation()); localLocation.divideLocal(wheelSpatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(wheelWorldRotation); tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); wheelSpatial.setLocalTranslation(localLocation); wheelSpatial.setLocalRotation(localRotationQuat); } else { wheelSpatial.setLocalTranslation(wheelWorldLocation); wheelSpatial.setLocalRotation(wheelWorldRotation); } }
/** * Apply this wheel's physics location and orientation to its associated * spatial, if any. */ public void applyWheelTransform() { if (wheelSpatial == null) { return; } Quaternion localRotationQuat = wheelSpatial.getLocalRotation(); Vector3f localLocation = wheelSpatial.getLocalTranslation(); if (!applyLocal && wheelSpatial.getParent() != null) { localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation()); localLocation.divideLocal(wheelSpatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(wheelWorldRotation); tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); wheelSpatial.setLocalTranslation(localLocation); wheelSpatial.setLocalRotation(localRotationQuat); } else { wheelSpatial.setLocalTranslation(wheelWorldLocation); wheelSpatial.setLocalRotation(wheelWorldRotation); } }
/** * Apply a physics transform to the spatial. * * @param worldLocation location vector (in physics-space coordinates, not * null, unaffected) * @param worldRotation orientation (in physics-space coordinates, not null, * unaffected) */ protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation) { if (enabled && spatial != null) { Vector3f localLocation = spatial.getLocalTranslation(); Quaternion localRotationQuat = spatial.getLocalRotation(); if (!applyLocal && spatial.getParent() != null) { localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(worldRotation); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(worldLocation); spatial.setLocalRotation(worldRotation); } } }
/** * Apply the specified location and orientation to the specified spatial. * * @param worldLocation location vector (in physics-space coordinates, not * null, unaffected) * @param worldRotation orientation (in physics-space coordinates, not null, * unaffected) * @param spatial where to apply (may be null) */ protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation, Spatial spatial) { if (spatial != null) { Vector3f localLocation = spatial.getLocalTranslation(); Quaternion localRotationQuat = spatial.getLocalRotation(); if (spatial.getParent() != null) { localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(worldRotation); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(worldLocation); spatial.setLocalRotation(worldRotation); } } } }
private static void validateSubScene(Spatial scene) { scene.checkCulling(DUMMY_CAM); Set<MatParamOverride> actualOverrides = new HashSet<MatParamOverride>(); for (MatParamOverride override : scene.getWorldMatParamOverrides()) { actualOverrides.add(override); } Set<MatParamOverride> expectedOverrides = new HashSet<MatParamOverride>(); Spatial current = scene; while (current != null) { for (MatParamOverride override : current.getLocalMatParamOverrides()) { expectedOverrides.add(override); } current = current.getParent(); } assertEquals("For " + scene, expectedOverrides, actualOverrides); }
/** * Apply a physics transform to the spatial. * * @param worldLocation location vector (in physics-space coordinates, not * null, unaffected) * @param worldRotation orientation (in physics-space coordinates, not null, * unaffected) */ protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation) { if (enabled && spatial != null) { Vector3f localLocation = spatial.getLocalTranslation(); Quaternion localRotationQuat = spatial.getLocalRotation(); if (!applyLocal && spatial.getParent() != null) { localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(worldRotation); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(worldLocation); spatial.setLocalRotation(worldRotation); } } }
/** * Apply the specified location and orientation to the specified spatial. * * @param worldLocation location vector (in physics-space coordinates, not * null, unaffected) * @param worldRotation orientation (in physics-space coordinates, not null, * unaffected) * @param spatial where to apply (may be null) */ protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation, Spatial spatial) { if (spatial != null) { Vector3f localLocation = spatial.getLocalTranslation(); Quaternion localRotationQuat = spatial.getLocalRotation(); if (spatial.getParent() != null) { localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); localRotationQuat.set(worldRotation); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); spatial.setLocalTranslation(localLocation); spatial.setLocalRotation(localRotationQuat); } else { spatial.setLocalTranslation(worldLocation); spatial.setLocalRotation(worldRotation); } } } }
public void update(float tpf) { if (enabled && spatial != null) { Quaternion localRotationQuat = spatial.getLocalRotation(); Vector3f localLocation = spatial.getLocalTranslation(); if (!applyLocal && spatial.getParent() != null) { getPhysicsLocation(localLocation); localLocation.subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); spatial.setLocalTranslation(localLocation); if (useViewDirection) { localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y); spatial.setLocalRotation(localRotationQuat); } } else { spatial.setLocalTranslation(getPhysicsLocation()); localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y); spatial.setLocalRotation(localRotationQuat); } } }
public void update(float tpf) { if (enabled && spatial != null) { Quaternion localRotationQuat = spatial.getLocalRotation(); Vector3f localLocation = spatial.getLocalTranslation(); if (!applyLocal && spatial.getParent() != null) { getPhysicsLocation(localLocation); localLocation.subtractLocal(spatial.getParent().getWorldTranslation()); localLocation.divideLocal(spatial.getParent().getWorldScale()); tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); spatial.setLocalTranslation(localLocation); if (useViewDirection) { localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y); spatial.setLocalRotation(localRotationQuat); } } else { spatial.setLocalTranslation(getPhysicsLocation()); localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y); spatial.setLocalRotation(localRotationQuat); } } }
@Override public void update(float tpf) { super.update(tpf); if(enabled){ timer+=tpf; if(timer>maxTime){ if(spatial.getParent()!=null){ space.removeCollisionListener(this); space.remove(this); spatial.removeFromParent(); } } } if (enabled && curTime >= 0) { curTime += tpf; if (curTime > fxTime) { curTime = -1; effect.removeFromParent(); } } }
public void collision(PhysicsCollisionEvent event) { if (space == null) { return; } if (event.getObjectA() == this || event.getObjectB() == this) { space.add(ghostObject); ghostObject.setPhysicsLocation(getPhysicsLocation(vector)); space.addTickListener(this); if (effect != null && spatial.getParent() != null) { curTime = 0; effect.setLocalTranslation(spatial.getLocalTranslation()); spatial.getParent().attachChild(effect); effect.emitAllParticles(); } space.remove(this); spatial.removeFromParent(); } }
Transform localTransform = loopSpatial.getLocalTransform(); combined.combineWithParent(localTransform); loopSpatial = loopSpatial.getParent();
/** * Rotate the billboard so it points directly opposite the direction the * camera's facing * * @param camera * Camera */ private void rotateScreenAligned(Camera camera) { // coopt diff for our in direction: look.set(camera.getDirection()).negateLocal(); // coopt loc for our left direction: left.set(camera.getLeft()).negateLocal(); orient.fromAxes(left, camera.getUp(), look); Node parent = spatial.getParent(); Quaternion rot=new Quaternion().fromRotationMatrix(orient); if ( parent != null ) { rot = parent.getWorldRotation().inverse().multLocal(rot); rot.normalizeLocal(); } spatial.setLocalRotation(rot); fixRefreshFlags(); }