[SOLVED] How to set size of spatial

Hey guys,

how do I set the size of a spatial? Seems kinda basic but all I found is Spatial.scale() that

Scales the spatial by the given value

There should be a way to set a spatial to an abitrary new size without caring about or knowing its current size, right?

What am I missing?

Cheers,
DefaultCube

Did you look at the javadoc? You want to “set” the “scale”, right?

Yup, that quote is from scale’s javadoc.

I want to make my spatial for instance to become 2 units wide, not to increase its size by 2 units.

Let’s say I tried something like this to make my Object “pulse”:

@override
public void simpleUpdate(float tpf) {
    float size = FastMath.sin(tpf);
    rootNode.getChild(0).scale(size);
}

Since scale() changes the spatial size depending on the current value, this snippet will of course not work as intended.

Use Spatial.setLocalScale(float) :slight_smile:

https://javadoc.jmonkeyengine.org/v3.3.2-stable/com/jme3/scene/Spatial.html#setLocalScale-float-

Some methods work (as you discovered) on the current state (scale/rotation/location) of the spatial. Other methods work on the initial state of the spatial.

Take a look at the tutorials, one of the first ones explains this.

Thanks that worked. :slight_smile:

For the sake of completeness:

@Override
public void simpleUpdate(float tpf) {

    float size = 1f + FastMath.sin(
         java.lang.System.nanoTime() / FastMath.pow(10, 9)
    );

    rootNode.getChild(0).setLocalScale(size);       
}
2 Likes