use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.
the class AssetLinkNode method read.
@Override
public void read(JmeImporter e) throws IOException {
super.read(e);
InputCapsule capsule = e.getCapsule(this);
BinaryImporter importer = BinaryImporter.getInstance();
AssetManager loaderManager = e.getAssetManager();
assetLoaderKeys = (ArrayList<ModelKey>) capsule.readSavableArrayList("assetLoaderKeyList", new ArrayList<ModelKey>());
for (Iterator<ModelKey> it = assetLoaderKeys.iterator(); it.hasNext(); ) {
ModelKey modelKey = it.next();
AssetInfo info = loaderManager.locateAsset(modelKey);
Spatial child = null;
if (info != null) {
child = (Spatial) importer.load(info);
}
if (child != null) {
child.parent = this;
children.add(child);
assetChildren.put(modelKey, child);
} else {
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot locate {0} for asset link node {1}", new Object[] { modelKey, key });
}
}
}
use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.
the class Geometry method computeWorldMatrix.
/**
* Indicate that the transform of this spatial has changed and that
* a refresh is required.
*/
// NOTE: Spatial has an identical implementation of this method,
// thus it was commented out.
// @Override
// protected void setTransformRefresh() {
// refreshFlags |= RF_TRANSFORM;
// setBoundRefresh();
// }
/**
* Recomputes the matrix returned by {@link Geometry#getWorldMatrix() }.
* This will require a localized transform update for this geometry.
*/
public void computeWorldMatrix() {
// Force a local update of the geometry's transform
checkDoTransformUpdate();
// Compute the cached world matrix
cachedWorldMat.loadIdentity();
cachedWorldMat.setRotationQuaternion(worldTransform.getRotation());
cachedWorldMat.setTranslation(worldTransform.getTranslation());
TempVars vars = TempVars.get();
Matrix4f scaleMat = vars.tempMat4;
scaleMat.loadIdentity();
scaleMat.scale(worldTransform.getScale());
cachedWorldMat.multLocal(scaleMat);
vars.release();
}
use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.
the class Spatial method rotate.
/**
* Rotates the spatial by the xAngle, yAngle and zAngle angles (in radians),
* (aka pitch, yaw, roll) in the local coordinate space.
*
* @return The spatial on which this method is called, e.g <code>this</code>.
*/
public Spatial rotate(float xAngle, float yAngle, float zAngle) {
TempVars vars = TempVars.get();
Quaternion q = vars.quat1;
q.fromAngles(xAngle, yAngle, zAngle);
rotate(q);
vars.release();
return this;
}
use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.
the class Spatial method oldClone.
/**
* The old clone() method that did not use the new Cloner utility.
*/
public Spatial oldClone(boolean cloneMaterial) {
try {
Spatial clone = (Spatial) super.clone();
if (worldBound != null) {
clone.worldBound = worldBound.clone();
}
clone.worldLights = worldLights.clone();
clone.localLights = localLights.clone();
// Set the new owner of the light lists
clone.localLights.setOwner(clone);
clone.worldLights.setOwner(clone);
clone.worldOverrides = new SafeArrayList<>(MatParamOverride.class);
clone.localOverrides = new SafeArrayList<>(MatParamOverride.class);
for (MatParamOverride override : localOverrides) {
clone.localOverrides.add((MatParamOverride) override.clone());
}
// No need to force cloned to update.
// This node already has the refresh flags
// set below so it will have to update anyway.
clone.worldTransform = worldTransform.clone();
clone.localTransform = localTransform.clone();
if (clone instanceof Node) {
Node node = (Node) this;
Node nodeClone = (Node) clone;
nodeClone.children = new SafeArrayList<Spatial>(Spatial.class);
for (Spatial child : node.children) {
Spatial childClone = child.clone(cloneMaterial);
childClone.parent = nodeClone;
nodeClone.children.add(childClone);
}
}
clone.parent = null;
clone.setBoundRefresh();
clone.setTransformRefresh();
clone.setLightListRefresh();
clone.setMatParamOverrideRefresh();
clone.controls = new SafeArrayList<Control>(Control.class);
for (int i = 0; i < controls.size(); i++) {
Control newControl = controls.get(i).cloneForSpatial(clone);
newControl.setSpatial(clone);
clone.controls.add(newControl);
}
if (userData != null) {
clone.userData = (HashMap<String, Savable>) userData.clone();
}
return clone;
} catch (CloneNotSupportedException ex) {
throw new AssertionError();
}
}
use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.
the class Spatial method lookAt.
/**
* <code>lookAt</code> is a convenience method for auto-setting the local
* rotation based on a position in world space and an up vector. It computes the rotation
* to transform the z-axis to point onto 'position' and the y-axis to 'up'.
* Unlike {@link Quaternion#lookAt(com.jme3.math.Vector3f, com.jme3.math.Vector3f) }
* this method takes a world position to look at and not a relative direction.
*
* Note : 28/01/2013 this method has been fixed as it was not taking into account the parent rotation.
* This was resulting in improper rotation when the spatial had rotated parent nodes.
* This method is intended to work in world space, so no matter what parent graph the
* spatial has, it will look at the given position in world space.
*
* @param position
* where to look at in terms of world coordinates
* @param upVector
* a vector indicating the (local) up direction. (typically {0,
* 1, 0} in jME.)
*/
public void lookAt(Vector3f position, Vector3f upVector) {
Vector3f worldTranslation = getWorldTranslation();
TempVars vars = TempVars.get();
Vector3f compVecA = vars.vect4;
compVecA.set(position).subtractLocal(worldTranslation);
getLocalRotation().lookAt(compVecA, upVector);
if (getParent() != null) {
Quaternion rot = vars.quat1;
rot = rot.set(parent.getWorldRotation()).inverseLocal().multLocal(getLocalRotation());
rot.normalizeLocal();
setLocalRotation(rot);
}
vars.release();
setTransformRefresh();
}
Aggregations