Author Topic: Issue in Picking individual parts of an object  (Read 2225 times)

Offline aklenka

  • byte
  • *
  • Posts: 3
    • View Profile
Issue in Picking individual parts of an object
« on: June 07, 2013, 03:27:07 pm »
I am new user of JPCT-AE. It may be silly question, but I tried too much I am not getting any such result.

My problem is, I have a car object which having 7-8 mess or 30-40 array of Object3D but the file is single and the format is car.3ds. I have loaded the car and displaying in the screen, when the user will pick any part of the car(i.e. tire, light, body etc.) only that part or mesh should be identified. I have tried but I am not getting whole car. Please suggest me how can I get identify individual parts or mess/part of the car. I have attached the code for your verification, whatever way I tried.

public void onSurfaceChanged(GL10 gl, int w, int h) {
         if (buffer != null) {
            buffer.dispose();
         }
         buffer = new FrameBuffer(gl, w, h);
         // if (master == null)
         {
            world = new World();
            world.setAmbientLight(150, 150, 150);
            sun = new Light(world);
            sun.setIntensity(250, 250, 250);
            int rID = R.raw.car;
            try {
               model = Object3D.mergeAll(loadModel(rID, modelScale));            } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }
            model.build();
            world.addObject(model);
            cam = world.getCamera();
            cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
            cam.lookAt(model.getTransformedCenter());
            SimpleVector sv = new SimpleVector();
            sv.set(model.getTransformedCenter());
            sv.y -= 100;
            sv.z -= 100;
            sun.setPosition(sv);
            if(bInitObjectPos){
               initObjectSetting();
               bInitObjectPos = false;
            }
         }
      }

private SimpleVector getWorldPosition(float X, float Y)
     {
      SimpleVector pos = null;
      model.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS|Object3D.COLLISION_CHECK_SELF);
      model.setCollisionOptimization(true);
      
      SimpleVector ray = Interact2D.reproject2D3DWS(world.getCamera(),
            buffer, (int) X, (int) Y);
      if (ray != null) {
         SimpleVector norm = ray.normalize();          
         Object[] slectedModel = world.calcMinDistanceAndObject3D(world.getCamera().getPosition(), norm, 1000);                  
                                                               if (slectedModel[1] != null) {
            
            Object3D selectmodel = (Object3D)slectedModel[1];            }
      }
      return pos;
     }

Here I am getting selectmodel is same as model, but I need individual parts of the same object. model consists array of Object3D, I need by touch whatever parts selected then that should return as selectmodel. Is there any API available in JPCT-AE. please share me your suggestion/opinion.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Issue in Picking individual parts of an object
« Reply #1 on: June 07, 2013, 06:39:06 pm »
You can't pick individual parts/objects if you merge all into one object at load time. To be able to pick a part, that part has to remain a single object.

Offline aklenka

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Issue in Picking individual parts of an object
« Reply #2 on: June 10, 2013, 10:10:50 am »
Dear Sir,

Many thanks for your reply.

I tried to change the code like below attached without merging the Object3D[], I rendered, now I am able to pick each parts of the object but the objects are destructing. I have attached the original object and destruction object for your reference. Is there any scope without merge we can render the object without any destruction? I need your valuable guidance.

Code: [Select]
public void onSurfaceChanged(GL10 gl, int w, int h) {
if (buffer != null) {
buffer.dispose();
}
buffer = new FrameBuffer(gl, w, h);
// if (master == null)
{
world = new World();
world.setAmbientLight(150, 150, 150);
sun = new Light(world);
sun.setIntensity(250, 250, 250);
int rID = R.raw.car;
try {
//model = Object3D.mergeAll(loadModel(rID, modelScale));
thing = loadModel(rID, modelScale);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

//model.build();
                 
for (int i = 0; i < thing.length; i++) { thing[i].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
thing[i].setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
thing[i].build();
}

//world.addObject(model);
for (int i = 0; i < thing.length; i++) {
world.addObject(thing[i]);
}

cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
//cam.lookAt(model.getTransformedCenter());
for(int i=0;i<thing.length;i++){
cam.lookAt(thing[i].getTransformedCenter());
}
SimpleVector sv = new SimpleVector();
//sv.set(model.getTransformedCenter());
for(int i=0;i<thing.length;i++){
sv.set(thing[i].getTransformedCenter());
}
sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);
if(bInitObjectPos){
initObjectSetting();
bInitObjectPos = false;
}
}
}


private SimpleVector getWorldPosition(float X, float Y)
  {
  String keyValue = "";
SimpleVector pos = null;
SimpleVector ray = Interact2D.reproject2D3DWS(world.getCamera(),
buffer, (int) X, (int) Y);
if (ray != null) {
SimpleVector norm = ray.normalize();
Object[] slectedModel = world.calcMinDistanceAndObject3D(world.getCamera().getPosition(), norm, 1000);
if (slectedModel[1] != null) {

Object3D selectmodel = (Object3D)slectedModel[1];

keyValue = objHashTable.get(selectmodel.toString());}
}
return pos;
  }

Thanks & regards
Anil


[attachment deleted by admin]
« Last Edit: June 10, 2013, 05:47:06 pm by EgonOlsen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Issue in Picking individual parts of an object
« Reply #3 on: June 10, 2013, 05:49:07 pm »
Are you doing some translations to the model? What does loadModel(...) do exactly? Apart from that, please wrap code in code-Tags (i've edited your post). And these parts

Code: [Select]
for(int i=0;i<thing.length;i++){
cam.lookAt(thing[i].getTransformedCenter());
}

Code: [Select]
for(int i=0;i<thing.length;i++){
sv.set(thing[i].getTransformedCenter());
}

Don't make much sense (they don't really hurt either, but thing[0] or similar would be sufficient).

Offline aklenka

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Issue in Picking individual parts of an object
« Reply #4 on: June 11, 2013, 03:55:38 pm »
Dear Sir,

I have changed the code as per your comments, but I am not getting any change on the rendered object. Still the objects are destruction. Depending on touch point location I am getting the particular object selectmodel in getWorldPosition.

I have attached my whole code whatever I am doing in loadModel, onSurfaceChanged and onDrawFrame function.

Please check my attached file. Is there some wrong I did in these code?

Thanks & regards
Anil


[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Issue in Picking individual parts of an object
« Reply #5 on: June 11, 2013, 04:05:16 pm »
My comments wasn't expected to help on the problem itself. I just wanted to point out that these parts make no sense. Anyway, the problem is most likely in initObjectSetting(). You are doing rotations on each each individual objects, which means that each object will rotate around it's own rotation pivot, which can't do anything but tear the object apart. Try to make all objects child objects of one significant parent one (maybe the chassis) and rotate/translate only that one.