SharedNode containing SharedMesh

Hi,



have created some shared meshs and put them into a node. SharedNodes are created from the original node and added to the scene.



The shared mesh's lose their local translation. Is this intentional ?? or should you be able to add a sharedmesh to a sharednode







Quick example as follows


package jmetest.renderer;

import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.SharedMesh;
import com.jme.scene.SharedNode;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Dome;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;

/**
 * <code>TestDome</code>
 *
 * @author Peter Andersson
 * @version $Id:
 */
public class TestDome extends SimpleGame {

   private Dome dome;

   private Quaternion rotQuat = new Quaternion();

   private float angle = 0;

   private Vector3f axis = new Vector3f(0, 1, 0);

   public static void main(String[] args) {
      TestDome app = new TestDome();
      app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
      app.start();
   }

   /**
    * Rotates the dome
    */
   protected void simpleUpdate() {
      if (tpf < 1) {
         angle = angle + (tpf * 1);
         if (angle > 360) {
            angle = 0;
         }
      }
      rotQuat.fromAngleAxis(angle, axis);
      dome.setLocalRotation(rotQuat);
   }

   /*
    * (non-Javadoc)
    *
    * @see com.jme.app.SimpleGame#initGame()
    */
   protected void simpleInitGame() {
      Node mainNode = new Node("main");

      dome = new Dome("My Dome", null, 20, 20, 20);      
      dome.setModelBound(new BoundingBox());
      dome.updateModelBound();

      TextureState ts = display.getRenderer().createTextureState();
      ts.setEnabled(true);
      ts.setTexture(TextureManager.loadTexture(
            TestBoxColor.class.getClassLoader().getResource(
                  "jmetest/data/images/Monkey.jpg"),
            Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR));

      Box rod = new Box("rod", new Vector3f(-10,20,0),new Vector3f(10,21,1));
      dome.setRenderState(ts);
      
      SharedMesh s1 = new SharedMesh("s1",rod);
      s1.setLocalTranslation(new Vector3f(-10,0,0));
      
      SharedMesh s2 = new SharedMesh("s2",rod);
      s2.setLocalTranslation(new Vector3f(10,0,0));
      
      mainNode.attachChild(dome);
      mainNode.attachChild(s1);
      mainNode.attachChild(s2);
      
      SharedNode n1 = new SharedNode("sn1", mainNode);
      SharedNode n2 = new SharedNode("sn1", mainNode);
      Quaternion q = n2.getLocalRotation();
      q.fromAngles(new float[]{FastMath.DEG_TO_RAD*180,0.0f,0.0f});
      
      rootNode.attachChild(mainNode);
      rootNode.attachChild(n2);
      
      
   }
}

SharedNode creates a similar structure of Nodes and SharedMesh. That is, where a Node is found, a new Node is created, where a TriMesh is found, a SharedMesh is created. I.e. it's expecting TriMeshes not SharedMeshes. It's primary use would be to share something like a Model, etc.

Darn



Thats a shame.



Any chance of getting it on the wanted list

Well, I added a check to see if it is a SharedMesh when adding (altering the casts). This is another mojo's patented change with no testing (something EVERYONE loves). Let me know if that does what you want, or completely broke things. If it breaks things, then Irrisor, Llama and Renanse can yell at me.

Sounds good.



Ill grab from the nightly build tommorrow  :slight_smile:

I've altered TestSharedNodeOffset to use SharedMeshes where the SharedMesh with the sphere has a local translation set. The test shows it working.

The TestSharedNodeOffset class from the nightly build didnt do the trick



There was a field in it called shared typed sharedmesh, but it wasnt used.



I have made a small mod to the method in the class to demonstrate the issue.



You should see 2 spheres and one pyramid



protected void simpleInitGame() {
display.setTitle("jME - Sphere");
display.getRenderer().setBackgroundColor(ColorRGBA.black);
display.setMinSamples(4);

file = new Node("main");

s = new Sphere("s", 20,20,5);
s.setLocalTranslation(new Vector3f(5,5,0));
Pyramid p = new Pyramid("p", 10,5);
SharedMesh sharedSphere = new SharedMesh("sphereMesh", s);

SharedMesh sharedSphere2 = new SharedMesh("sphereMesh", s);
sharedSphere2.getLocalTranslation().y +=25;

file.attachChild(sharedSphere);
file.attachChild(sharedSphere2);
file.attachChild(p);

Node n1 = new Node("n1");

for (int i = 0; i < 100; i++) {

SharedNode sm = new SharedNode("Share" + i, file);
sm.setLocalTranslation(new Vector3f(
(float) Math.random() * 200 - 100,
(float) Math.random() * 200 - 100,
(float) Math.random() * 200 - 100));
n1.attachChild(sm);

if(i == 0) {
shared = (SharedMesh)((Node)sm.getChild(0)).getChild(0);
}
}

n1.setLocalTranslation(new Vector3f(500, 0, 0));
rootNode.attachChild(n1);

SharedNode sm1 = new SharedNode("Share1", n1);
sm1.setLocalTranslation(new Vector3f(200, 100, 200));
sm1.setLocalScale(new Vector3f(0.5f, 0.5f, 0.5f));
Matrix3f m = new Matrix3f();
m.fromAngleAxis(2f, new Vector3f(1, 1, 0));
sm1.setLocalRotation(m);
rootNode.attachChild(sm1);

SharedNode sm2 = new SharedNode("Share1", n1);
sm2.setLocalTranslation(new Vector3f(-200, 100, 200));
rootNode.attachChild(sm2);

SharedNode sm3 = new SharedNode("Share1", n1);
sm3.setLocalTranslation(new Vector3f(200, 100, -200));
rootNode.attachChild(sm3);

SharedNode sm4 = new SharedNode("Share1", n1);
sm4.setLocalTranslation(new Vector3f(-200, -100, -200));
rootNode.attachChild(sm4);

}

Ok - what is the purpose of sharednode over mesh - should attach child recognise it or throw an exception ???

Still not inhereting :frowning:



Is this a planned feature or a planned discouragement

I was out of town for a few days. I'll get back to this as soon as I can.

I fail to see the problem here.



In your updated test you add a second sphere that is translated up 25 units. That is reflected in all the Pyramid/sphere combinations displayed on screen. What is the behavior you are expecting?

Woo Hooo



It works…



Must have been a timing thing from when i took from the nightly build.



Thanks…