Scaling multiple geometries / Scaling a node with multiple geometries attached to it

Hello



I am trying to join a number of geometries together - in fact all of them are Boxes. I have set the location of each box using setLocalTranslation() and joined each box to a Node.



However, when I scale the geometries - which I am doing by scaling the Node - the distance between each box does not scale. The result is that boxes which used to be adjacent to each other now have a large gap between them.



Has anyone dealt this problem before? What am I doing wrong?

Show us the code?

[java]package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.math.Vector3f;

import com.jme3.renderer.Camera.FrustumIntersect;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;

import com.jme3.system.AppSettings;

import java.util.LinkedList;



/**

*

*

/

public class Main extends SimpleApplication {



public static void main(String[] args) {

AppSettings settings = new AppSettings(true);

settings.setResolution(800,480);

Main app = new Main();

app.setShowSettings(false);

settings.setSamples(4);

app.setSettings(settings);

app.start();

}



@Override

public void simpleInitApp() {



LinkedList<Pixel> ll = new LinkedList();



ll.add(new Pixel(0f, 0f, 0f, assetManager));

ll.add(new Pixel(0f, 2f, 0f, assetManager));



Node n1 = new Node("pivot");



Geometry geom_temp;

Vector3f vector3f_temp;



for (int x = 0; x < ll.size(); x++)

{

geom_temp = ll.get(x).getGeom();

vector3f_temp = ll.get(x).getLocation();



geom_temp.setLocalTranslation(vector3f_temp);

System.out.println(vector3f_temp);

n1.attachChild(geom_temp);

}



n1.scale(1f);



rootNode.attachChild(n1);



}



@Override

public void simpleUpdate(float tpf) {

//TODO: add update code

cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);

}



@Override

public void simpleRender(RenderManager rm) {

//TODO: add render code

}

}[/java]







[java]/

  • To change this template, choose Tools | Templates
  • and open the template in the editor.

    */

    package mygame;



    import com.jme3.asset.AssetManager;

    import com.jme3.bullet.control.RigidBodyControl;

    import com.jme3.material.Material;

    import com.jme3.math.ColorRGBA;

    import com.jme3.math.Vector3f;

    import com.jme3.scene.Geometry;

    import com.jme3.scene.shape.Box;



    /**

    *

    *

    */

    public class Pixel {



    private Geometry pixel_geom;

    private Material pixel_mat;

    private RigidBodyControl pixel_phy;

    private Vector3f pixel_location;



    public Pixel(float x, float y, float z, AssetManager assetManager)

    {

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);

    pixel_geom = new Geometry("Box", b);

    pixel_location = new Vector3f(x, y, z);

    pixel_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    pixel_mat.setColor("Color", ColorRGBA.randomColor());

    pixel_geom.setMaterial(pixel_mat);

    pixel_phy = new RigidBodyControl(0f);

    pixel_geom.addControl(pixel_phy);

    }



    public void setLocation()

    {

    pixel_geom.setLocalTranslation(pixel_location);

    }



    public Vector3f getLocation()

    {

    return pixel_location;

    }



    public Geometry getGeom()

    {

    return pixel_geom;

    }



    }

    [/java]

Its because the localTransation is scaled by the parent node:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies

@kentsusai you’re scaling them down, right?


normen said:
Its because the localTransation is scaled by the parent node:

That's the other way round i think, scale is applied to scale but not to translation.
edit : which shouldn't be the case btw.

@kentsusai try to use Node.setLocalScale() and not the scale() method.

No. The localTranslation of the child is scaled by the parent node, believe me. That is why he experiences what he does. I tested every behavior I describe in that tutorial.

normen said:
No. The localTranslation of the child is scaled by the parent node, believe me. That is why he experiences what he does. I tested every behavior I describe in that tutorial.


So it scales the translation of the children but does not scale their scale? If so, then that's busted. And in my experience, scale definitely scales the children.

Otherwise, if you have a box at 0 with radius 1 and a box at 2 with radius one, they will be touching... no amount of scaling should change that. For example, scale of 0.5 would put the boxes at 0 and 1 with .5 radius... they would still touch.

So I'm not sure what's going on here. I may have to play with this myself later as it goes counter to previous tests I've done.

your test case works fine for me as soon as i remove the RigidBodyControl off the geometry.

RigidBodyControl is not supposed to work on its own

please read this doc https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_physics

@nehon is going to teach me to always blame physics whenever anything is strange. :slight_smile:

lol no you don’t get it…the first step is to blame JMP…then physics …but in the end it’s always Kirill :stuck_out_tongue:

pspeed said:
So it scales the translation of the children but does not scale their scale?

Yes it does scale their scale, but a spatial doesn't scale its own local translation. But yeah, that can't be the issue, actually the default behavior should work for this threads use case.

Thank you for all your comments



I have changed the code so that the RigidBodyControl is added after scaling.



[java]package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.bullet.BulletAppState;

import com.jme3.math.Vector3f;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;

import com.jme3.system.AppSettings;

import java.util.LinkedList;



/**

  • test
  • @author kentsusai

    /

    public class Main extends SimpleApplication {



    public static void main(String[] args) {

    AppSettings settings = new AppSettings(true);

    settings.setResolution(800,480);

    Main app = new Main();

    app.setShowSettings(false);

    settings.setSamples(4);

    app.setSettings(settings);

    app.start();

    }



    @Override

    public void simpleInitApp() {



    BulletAppState bulletAppState = new BulletAppState();

    stateManager.attach(bulletAppState);



    LinkedList<Pixel> ll = new LinkedList();



    ll.add(new Pixel(0f, 0f, 0f, assetManager));

    ll.add(new Pixel(0f, 2f, 0f, assetManager));



    Node n1 = new Node("pivot");



    Geometry geom_temp;

    Vector3f vector3f_temp;



    //attach each child spatial to the parent node

    for (int x = 0; x < ll.size(); x++)

    {

    geom_temp = ll.get(x).getGeom();

    vector3f_temp = ll.get(x).getLocation();



    System.out.println(vector3f_temp);

    n1.attachChild(geom_temp);

    }



    //attach parent node to root node

    rootNode.attachChild(n1);

    n1.scale(0.25f); //Here is the scaling



    for (int x = 0; x < ll.size(); x++)

    {

    vector3f_temp = ll.get(x).getLocation();

    System.out.println(vector3f_temp);



    ll.get(x).attachPhysics(bulletAppState);

    }







    }



    @Override

    public void simpleUpdate(float tpf) {

    //TODO: add update code

    cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);

    }



    @Override

    public void simpleRender(RenderManager rm) {

    //TODO: add render code

    }

    }

    [/java]







    [java]/

  • To change this template, choose Tools | Templates
  • and open the template in the editor.

    */

    package mygame;



    import com.jme3.asset.AssetManager;

    import com.jme3.bullet.BulletAppState;

    import com.jme3.bullet.control.RigidBodyControl;

    import com.jme3.material.Material;

    import com.jme3.math.ColorRGBA;

    import com.jme3.math.Vector3f;

    import com.jme3.scene.Geometry;

    import com.jme3.scene.shape.Box;



    /**

    *
  • @author kentsusai

    */

    public class Pixel {



    private Geometry pixel_geom;

    private Material pixel_mat;

    private RigidBodyControl pixel_phy;

    private Vector3f pixel_location;



    public Pixel(float x, float y, float z, AssetManager assetManager)

    {

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);

    pixel_geom = new Geometry("Box", b);

    pixel_location = new Vector3f(x, y, z);

    pixel_geom.setLocalTranslation(pixel_location);

    pixel_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    pixel_mat.setColor("Color", ColorRGBA.randomColor());

    pixel_geom.setMaterial(pixel_mat);

    }



    public void setLocation()

    {

    pixel_geom.setLocalTranslation(pixel_location);

    }



    public Vector3f getLocation()

    {

    return pixel_geom.getLocalTranslation();

    }



    public Geometry getGeom()

    {

    return pixel_geom;

    }



    public void attachPhysics(BulletAppState bullet)

    {

    pixel_phy = new RigidBodyControl(0f);

    pixel_geom.addControl(pixel_phy);

    bullet.getPhysicsSpace().add(pixel_phy);

    }



    }

    [/java]