Search in sources :

Example 61 with Transform

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);
}
Also used : Bucket(com.jme3.renderer.queue.RenderQueue.Bucket) SafeArrayList(com.jme3.util.SafeArrayList) ShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode) MatParamOverride(com.jme3.material.MatParamOverride)

Example 62 with Transform

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();
        }
    }
}
Also used : TempVars(com.jme3.util.TempVars)

Example 63 with Transform

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);
    }
}
Also used : RenderState(com.jme3.material.RenderState) LightList(com.jme3.light.LightList) Material(com.jme3.material.Material) Technique(com.jme3.material.Technique) MaterialDef(com.jme3.material.MaterialDef)

Example 64 with Transform

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);
    }
}
Also used : Transform(com.jme3.math.Transform) PhysicsSweepTestResult(com.jme3.bullet.collision.PhysicsSweepTestResult) PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject)

Example 65 with Transform

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);
}
Also used : Transform(com.jme3.math.Transform)

Aggregations

Vector3f (com.jme3.math.Vector3f)29 Transform (com.jme3.math.Transform)26 TempVars (com.jme3.util.TempVars)24 Quaternion (com.jme3.math.Quaternion)11 Matrix4f (com.jme3.math.Matrix4f)10 Bone (com.jme3.animation.Bone)9 BoundingBox (com.jme3.bounding.BoundingBox)6 BoneContext (com.jme3.scene.plugins.blender.animations.BoneContext)5 PointLight (com.jme3.light.PointLight)4 Spatial (com.jme3.scene.Spatial)4 FloatBuffer (java.nio.FloatBuffer)4 Transform (com.bulletphysics.linearmath.Transform)3 ChildCollisionShape (com.jme3.bullet.collision.shapes.infos.ChildCollisionShape)3 DirectionalLight (com.jme3.light.DirectionalLight)3 Light (com.jme3.light.Light)3 SpotLight (com.jme3.light.SpotLight)3 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)2 BoneTrack (com.jme3.animation.BoneTrack)2 SpatialTrack (com.jme3.animation.SpatialTrack)2 BoundingVolume (com.jme3.bounding.BoundingVolume)2