use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.
the class Spatial method read.
public void read(JmeImporter im) throws IOException {
InputCapsule ic = im.getCapsule(this);
name = ic.readString("name", null);
worldBound = (BoundingVolume) ic.readSavable("world_bound", null);
cullHint = ic.readEnum("cull_mode", CullHint.class, CullHint.Inherit);
batchHint = ic.readEnum("batch_hint", BatchHint.class, BatchHint.Inherit);
queueBucket = ic.readEnum("queue", RenderQueue.Bucket.class, RenderQueue.Bucket.Inherit);
shadowMode = ic.readEnum("shadow_mode", ShadowMode.class, ShadowMode.Inherit);
localTransform = (Transform) ic.readSavable("transform", Transform.IDENTITY);
localLights = (LightList) ic.readSavable("lights", null);
localLights.setOwner(this);
ArrayList<MatParamOverride> localOverridesList = ic.readSavableArrayList("overrides", null);
if (localOverridesList == null) {
localOverrides = new SafeArrayList<>(MatParamOverride.class);
} else {
localOverrides = new SafeArrayList(MatParamOverride.class, localOverridesList);
}
worldOverrides = new SafeArrayList<>(MatParamOverride.class);
//changed for backward compatibility with j3o files generated before the AnimControl/SkeletonControl split
//the AnimControl creates the SkeletonControl for old files and add it to the spatial.
//The SkeletonControl must be the last in the stack so we add the list of all other control before it.
//When backward compatibility won't be needed anymore this can be replaced by :
//controls = ic.readSavableArrayList("controlsList", null));
controls.addAll(0, ic.readSavableArrayList("controlsList", null));
userData = (HashMap<String, Savable>) ic.readStringSavableMap("user_data", null);
}
use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.
the class Spatial method checkDoTransformUpdate.
/**
* Computes the world transform of this Spatial in the most
* efficient manner possible.
*/
void checkDoTransformUpdate() {
if ((refreshFlagGetAnd(RF_TRANSFORM)) == 0) {
return;
}
if (parent == null) {
worldTransform.set(localTransform);
refreshFlagAnd(~RF_TRANSFORM);
} else {
TempVars vars = TempVars.get();
Spatial[] stack = vars.spatialStack;
Spatial rootNode = this;
int i = 0;
while (true) {
Spatial hisParent = rootNode.parent;
if (hisParent == null) {
rootNode.worldTransform.set(rootNode.localTransform);
rootNode.refreshFlagAnd(~RF_TRANSFORM);
i--;
break;
}
stack[i] = rootNode;
if ((hisParent.refreshFlagGetAnd(RF_TRANSFORM)) == 0) {
break;
}
rootNode = hisParent;
i++;
}
vars.release();
for (int j = i; j >= 0; j--) {
rootNode = stack[j];
//rootNode.worldTransform.set(rootNode.localTransform);
//rootNode.worldTransform.combineWithParent(rootNode.parent.worldTransform);
//rootNode.refreshFlags &= ~RF_TRANSFORM;
rootNode.updateWorldTransforms();
}
}
}
use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.
the class RenderManager method renderGeometry.
/**
* Renders the given geometry.
* <p>
* First the proper world matrix is set, if
* the geometry's {@link Geometry#setIgnoreTransform(boolean) ignore transform}
* feature is enabled, the identity world matrix is used, otherwise, the
* geometry's {@link Geometry#getWorldMatrix() world transform matrix} is used.
* <p>
* Once the world matrix is applied, the proper material is chosen for rendering.
* If a {@link #setForcedMaterial(com.jme3.material.Material) forced material} is
* set on this RenderManager, then it is used for rendering the geometry,
* otherwise, the {@link Geometry#getMaterial() geometry's material} is used.
* <p>
* If a {@link #setForcedTechnique(java.lang.String) forced technique} is
* set on this RenderManager, then it is selected automatically
* on the geometry's material and is used for rendering. Otherwise, one
* of the {@link MaterialDef#getDefaultTechniques() default techniques} is
* used.
* <p>
* If a {@link #setForcedRenderState(com.jme3.material.RenderState) forced
* render state} is set on this RenderManager, then it is used
* for rendering the material, and the material's own render state is ignored.
* Otherwise, the material's render state is used as intended.
*
* @param geom The geometry to render
*
* @see Technique
* @see RenderState
* @see Material#selectTechnique(java.lang.String, com.jme3.renderer.RenderManager)
* @see Material#render(com.jme3.scene.Geometry, com.jme3.renderer.RenderManager)
*/
public void renderGeometry(Geometry geom) {
if (geom.isIgnoreTransform()) {
setWorldMatrix(Matrix4f.IDENTITY);
} else {
setWorldMatrix(geom.getWorldMatrix());
}
// Perform light filtering if we have a light filter.
LightList lightList = geom.getWorldLightList();
if (lightFilter != null) {
filteredLightList.clear();
lightFilter.filterLights(geom, filteredLightList);
lightList = filteredLightList;
}
Material material = geom.getMaterial();
//else the geom is not rendered
if (forcedTechnique != null) {
MaterialDef matDef = material.getMaterialDef();
if (matDef.getTechniqueDefs(forcedTechnique) != null) {
Technique activeTechnique = material.getActiveTechnique();
String previousTechniqueName = activeTechnique != null ? activeTechnique.getDef().getName() : TechniqueDef.DEFAULT_TECHNIQUE_NAME;
geom.getMaterial().selectTechnique(forcedTechnique, this);
//saving forcedRenderState for future calls
RenderState tmpRs = forcedRenderState;
if (geom.getMaterial().getActiveTechnique().getDef().getForcedRenderState() != null) {
//forcing forced technique renderState
forcedRenderState = geom.getMaterial().getActiveTechnique().getDef().getForcedRenderState();
}
// use geometry's material
material.render(geom, lightList, this);
material.selectTechnique(previousTechniqueName, this);
//restoring forcedRenderState
forcedRenderState = tmpRs;
//Reverted this part from revision 6197
//If forcedTechnique does not exists, and forcedMaterial is not set, the geom MUST NOT be rendered
} else if (forcedMaterial != null) {
// use forced material
forcedMaterial.render(geom, lightList, this);
}
} else if (forcedMaterial != null) {
// use forced material
forcedMaterial.render(geom, lightList, this);
} else {
material.render(geom, lightList, this);
}
}
use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.
the class TestSweepTest method simpleUpdate.
@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);
}
}
use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.
the class FbxNode method relocateSpatial.
private static void relocateSpatial(Spatial spatial, Transform originalWorldTransform, Transform newWorldTransform) {
Transform localTransform = new Transform();
localTransform.set(originalWorldTransform);
localTransform.combineWithParent(newWorldTransform.invert());
spatial.setLocalTransform(localTransform);
}
Aggregations