[AJUDA]Picking 3D models (or xxx.mesh.j3o xxx.mesh.xml) with mouse

Guys,

I began my studies at jMe3 and began to experience problems with the eighth tutorial Picking Hello. The problem is when I’m working with models or xxx.mesh.j3o xxx.mesh.xml, I can not get the correct name of Geometry, the image as follows:



I wonder if it’s some bug jMe and how to fix this problem, because when I work with models own jMe as shown in another image below, do not encounter any problem



I look forward to the solution. :slight_smile:

You give the name to the root node of the loaded model, that does not change the name of the Geometry leaf.

Open the model in jMP and you will see. Its a tree, you only change the name of the base Node, not of the Geometry contained inside. If you dont understand the concept, please read up on the tutorials.

Thanks man, I understand now what you wanted to say.

2 Cent of mine:


  1. Picking takes the center of the display at the moment. Picking with the mouse would be awesome!

    I solved it with jME2, but I buried the code somewhere in my backups! I know, you have to add only a few lines for mouse picking support! Would be great, if someone could solve that! :wink:


  2. Picking has trouble with meshes, which have submeshes! I always get a material error!
  1. The example does, picking works with mouse location. Theres even an example in the wiki now I think. Its very similar to jme2, I do it in this class for example.
  2. What kind of “submeshes” do you mean? LOD? A Geometry can only have one mesh per se.

Guys,

I’ll be more specific, what I want is that when I pick the model with the mouse, I can remove it from the scene, I’m trying to do this by taking the name of the geometry works for models (assets) of their own native engine type: Cube , Box When I try to do it with models or xxx.mesh.xml xxx.mesh.j3o, I can not, because I noticed that inside the ArrayList results, the objects of these types are stored differently, I would like you to examine code, to see what I’m doing wrong. DarkPhoenixX thanks for the tip I’ll take a look at jMe2 more calmly. NORMEN I do not want to change the name of the geometry, I get the correct name to detach and remove the model of the scene, I did what you told me earlier, plus it was not changing the name of the geometry, I’m sorry if not I was so specific. I used the class that you mentioned and still could not do what I want is to remove the model of the scene. Below the Source to give you a review.



[java]package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.bounding.BoundingBox;

import com.jme3.collision.CollisionResult;

import com.jme3.collision.CollisionResults;

import com.jme3.font.BitmapText;

import com.jme3.input.KeyInput;

import com.jme3.input.controls.ActionListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.input.controls.MouseButtonTrigger;

import com.jme3.light.DirectionalLight;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Ray;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

//import com.jme3.scene.Node;

import com.jme3.scene.Node;

import com.jme3.scene.Spatial;

import com.jme3.scene.shape.Box;

import com.jme3.scene.shape.Sphere;



public class Main extends SimpleApplication {



public static void main(String[] args) {

Main app = new Main();

app.start();

}



Node shootables;

Geometry mark;

// Spatial Oto;



@Override

public void simpleInitApp() {

initCrossHairs(); // a “+” in the middle of the screen to help aiming

initKeys(); // load custom key mappings

initMark(); // a red sphere to mark the hit



/** create four colored boxes and a floor to shoot at: /

shootables = new Node();



cam.setDirection(new Vector3f(0, -1, 0));

cam.setLocation(new Vector3f(10,0,10));

shootables.attachChild(makeCube1(-2f, 0f, 1f));

shootables.attachChild(makeGolem());

shootables.attachChild(makeGolem2());

shootables.attachChild(makeFloor());

rootNode.attachChild(shootables);

DirectionalLight sun = new DirectionalLight();

sun.setDirection(new Vector3f(-9,-9,-9));

rootNode.addLight(sun);



DirectionalLight sun2 = new DirectionalLight();

sun2.setDirection(new Vector3f(9,9,9));

rootNode.addLight(sun2);



}



/
* Declaring the “Shoot” action and mapping to its triggers. /

private void initKeys() {

inputManager.addMapping(“Shoot”,

new KeyTrigger(KeyInput.KEY_SPACE), // trigger 1: spacebar

new MouseButtonTrigger(0)); // trigger 2: left-button click

inputManager.addListener(actionListener, “Shoot”);

}



/
* Defining the “Shoot” action: Determine what was hit and how to respond. /

private ActionListener actionListener = new ActionListener() {

@Override

public void onAction(String name, boolean keyPressed, float tpf) {

if (name.equals(“Shoot”) && !keyPressed) {



CollisionResults results = new CollisionResults();

Ray ray = new Ray(cam.getLocation(), cam.getDirection());



shootables.collideWith(ray, results);



float dist = results.getClosestCollision().getDistance();

Vector3f pt = results.getClosestCollision().getContactPoint();

String hit = results.getClosestCollision().getGeometry().getName();

System.out.println(" You shot " + hit + " at " + pt + “, " + dist + " wu away.”);

if (results.size() > 0){

CollisionResult closest = results.getClosestCollision();

mark.setLocalTranslation(closest.getContactPoint());

rootNode.attachChild(mark);

shootables.detachChildNamed(results.getClosestCollision().getGeometry().getName());



} else {

rootNode.detachChild(mark);

}

}

}

};



protected Geometry makeCube(String name, float x, float y, float z) {

Box box = new Box(new Vector3f(x, y, z), 1, 1, 1);

Geometry cube = new Geometry(name, box);

Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat1.setColor(“m_Color”, ColorRGBA.randomColor());

cube.setMaterial(mat1);

return cube;

}



protected Geometry makeCube1(float x, float y, float z) {

Box box = new Box(new Vector3f(x, y, z), 1, 1, 1);

Geometry cube = new Geometry(“The box is Red”, box);

Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat1.setColor(“m_Color”, ColorRGBA.Red);

cube.setMaterial(mat1);

return cube;

}



protected Geometry makeFloor() {

Box box = new Box(new Vector3f(0,-4,-5), 15,0,15);

Geometry floor = new Geometry(“the Floor”, box);

Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat1.setColor(“m_Color”, ColorRGBA.Gray);

floor.setMaterial(mat1);

return floor;

}



private Spatial makeGolem() {

Spatial golem = assetManager.loadModel(“Models/Oto.mesh.j3o”);

golem.setLocalTranslation(-5f, 0f, 3f);

golem.setLocalScale(0.5f);

return golem;

}



private Spatial makeGolem2() {

Spatial golem = assetManager.loadModel(“Models/Oto.mesh.j3o”);

golem.setLocalTranslation(5f, 0f, 3f);

golem.setLocalScale(0.5f);

return golem;

}

protected void initMark() {

Sphere sphere = new Sphere(30, 30, 0.2f);

mark = new Geometry(“BOOM!”, sphere);

Material mark_mat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mark_mat.setColor(“m_Color”, ColorRGBA.Red);

mark.setMaterial(mark_mat);

}



protected void initCrossHairs() {

guiNode.detachAllChildren();

guiFont = assetManager.loadFont(“Interface/Fonts/Default.fnt”);

BitmapText ch = new BitmapText(guiFont, false);

ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);

ch.setText("+"); // crosshairs

ch.setLocalTranslation( // center

settings.getWidth()/2 - guiFont.getCharSet().getRenderedSize()/3
2,

settings.getHeight()/2 + ch.getLineHeight()/2, 0);

guiNode.attachChild(ch);

}





}[/java]

No, I mean a normal mesh model. Maybe it’s a material error, but it does work without “picking”.

The model is an ogre mesh, meaning you can use it in HelloPicking!



Example:

http://www.file-upload.net/download-2902852/kira.rar.html



Error:

[java]bootleg_material: emissive

Unsupported texture_unit directive: tex_coord_set

Unsupported texture_unit directive: colour_op

Unsupported texture_unit directive: scale

Unsupported texture_unit directive: scroll

Unsupported texture_unit directive: rotate

boots_material: emissive

Unsupported texture_unit directive: tex_coord_set

Unsupported texture_unit directive: colour_op

Unsupported texture_unit directive: scale

Unsupported texture_unit directive: scroll

Unsupported texture_unit directive: rotate

glove_large: emissive

Unsupported texture_unit directive: tex_coord_set

Unsupported texture_unit directive: colour_op

Unsupported texture_unit directive: scale

Unsupported texture_unit directive: scroll

Unsupported texture_unit directive: rotate

glove_material: emissive

Unsupported texture_unit directive: tex_coord_set

Unsupported texture_unit directive: colour_op

Unsupported texture_unit directive: scale

Unsupported texture_unit directive: scroll

Unsupported texture_unit directive: rotate

shirt_material: emissive

Unsupported texture_unit directive: tex_coord_set

Unsupported texture_unit directive: colour_op

Unsupported texture_unit directive: scale

Unsupported texture_unit directive: scroll

Unsupported texture_unit directive: rotate

trousers_material: emissive

Unsupported texture_unit directive: tex_coord_set

Unsupported texture_unit directive: colour_op

Unsupported texture_unit directive: scale

Unsupported texture_unit directive: scroll

Unsupported texture_unit directive: rotate

skin_material: emissive

lambert1: emissive

scarf_material: emissive

hair_material: emissive

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-sharedgeom) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-1) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-2) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-3) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-4) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-5) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-6) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-7) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-8) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-9) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-10) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-11) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-12) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-13) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-geom-14) attached to this node (Kira-ogremesh)

19.10.2010 18:26:57 com.jme3.scene.Node attachChild

INFO: Child (Kira-ogremesh) attached to this node (selectable)

19.10.2010 18:26:58 com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

WARNUNG: Uniform m_VertexColor is not declared in shader.

19.10.2010 18:27:00 com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

WARNUNG: Uniform m_UseMaterialColors is not declared in shader.

19.10.2010 18:27:01 com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

WARNUNG: Uniform m_UseMaterialColors is not declared in shader.

19.10.2010 18:27:03 com.jme3.scene.Node detachChildAt

INFO: Child removed.

(2129.0, 1111.0)

Exception in thread “LWJGL Renderer Thread” java.lang.NullPointerException

at com.jme3.collision.bih.BIHTree.initTriList(BIHTree.java:91)

at com.jme3.collision.bih.BIHTree.(BIHTree.java:128)

at com.jme3.collision.bih.BIHTree.(BIHTree.java:135)

at com.jme3.scene.Mesh.createCollisionData(Mesh.java:464)

at com.jme3.scene.Mesh.collideWith(Mesh.java:475)

at com.jme3.scene.Geometry.collideWith(Geometry.java:232)

at com.jme3.scene.Node.collideWith(Node.java:498)

at com.jme3.scene.Node.collideWith(Node.java:498)

at sandbox.SandboxJME$1.onAction(SandboxJME.java:142)

at com.jme3.input.InputManager.invokeActions(InputManager.java:140)

at com.jme3.input.InputManager.onKeyEvent(InputManager.java:316)

at com.jme3.input.lwjgl.LwjglKeyInput.update(LwjglKeyInput.java:79)

at com.jme3.input.InputManager.update(InputManager.java:426)

at com.jme3.app.Application.update(Application.java:448)

at com.xero.app.XeroApplication.update(XeroApplication.java:225)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)

at com.jme3.system.lwjgl.LwjglCanvas.runLoop(LwjglCanvas.java:226)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:198)

at java.lang.Thread.run(Unknown Source)[/java]



MousePicking:

By the way, thx for the link!

This should only happen when theres messed up meshes or geometries w/o meshes… Or if theres really a bug in the collision code…

The meshes are cleaned up :frowning:

Well, if you find something let me know! I try to figure the problem myself.

Without “collision” function, the model works well!



Maybe the hair or one boot has messed up meshes (The hair is not cleaned up/ one boot is a copy of the other boot)

I will test that!