Author Topic: set generic scale for diffrent 3D model in JPCT-AE VUFORIA  (Read 3334 times)

Offline angieIe

  • byte
  • *
  • Posts: 29
    • View Profile
set generic scale for diffrent 3D model in JPCT-AE VUFORIA
« on: October 15, 2014, 04:57:43 am »
In my app, am using JPCT-ae for 3d rendering. I am downloading 3d models form server and rendering it in android device. my problem is some models are small and some are very big. I want to set one generic scale for all the models regardless of what scale they were exported with. so that when i render them on device they should be of same size.

I dont know to do it. please any idea any help is very much appreciated.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: set generic scale for diffrent 3D model in JPCT-AE VUFORIA
« Reply #1 on: October 15, 2014, 10:16:50 pm »
You can get yourself the Mesh of an Object3D and from that, you can get the bounding box. Form the bb, you can calculate the dimensions along all three axis and scale the object according to the largest. Please note that you have to call build() or at least calcBoundingBox() on the object for this to work.

Offline angieIe

  • byte
  • *
  • Posts: 29
    • View Profile
Re: set generic scale for diffrent 3D model in JPCT-AE VUFORIA
« Reply #2 on: October 16, 2014, 03:48:22 am »
Thank Egon, will try getBoundingBox

Offline angieIe

  • byte
  • *
  • Posts: 29
    • View Profile
Re: set generic scale for diffrent 3D model in JPCT-AE VUFORIA
« Reply #3 on: October 16, 2014, 04:24:35 am »
I trying to add getBoundingBox.. here is my code:
 try {
     
      // Create a texture out of the icon...:-)
      TextureManager txtMgr = TextureManager.getInstance();
         if (!txtMgr.containsTexture("texture")) {
            Texture texture = new Texture(new FileInputStream(t));
            txtMgr.addTexture("texture", texture);
           }
         else{
           Texture old_texture = new Texture(new FileInputStream(t));
           txtMgr.replaceTexture("texture", old_texture);
            }
    
       cube=Loader.load3DS(new FileInputStream(f),scale)[0];
       cube.calcBoundingBox();
       float[] bb=cube.getMesh().getBoundingBox();
       scale=bb[mViewHeight];
       cube.setTexture("texture");
       cube.strip();
        cube.setTexture("texture");
      cube.build();
        } catch (IOException e) {
         e.printStackTrace();      
   }
please more guide..thank you

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: set generic scale for diffrent 3D model in JPCT-AE VUFORIA
« Reply #4 on: October 16, 2014, 08:27:01 pm »
What is this part supposed to do?

Code: [Select]
scale=bb[mViewHeight];

The format of the returned float array is minX, maxX, minY, maxY, minZ, maxZ, so you have to calculate bb[1]-bb[0] to get xDif and bb[3]-bb[2] for yDif...you get the idea, i guess. Then calculate the max value of these values (that matter to you, maybe just of xDif and yDif) and scale accordingly, i.e. if a model with size 100 fits fine with a scale of 2, one of size 200 would need 1, one of 50 would need 4 etc..

Offline angieIe

  • byte
  • *
  • Posts: 29
    • View Profile
Re: set generic scale for diffrent 3D model in JPCT-AE VUFORIA
« Reply #5 on: October 22, 2014, 09:23:34 am »
hi, Egon. Try to understand and so far this is my code:
Code: [Select]
      cube=Primitives.getBox(15,3);
      cube.calcBoundingBox();
      float[] bb=cube.getMesh().getBoundingBox();
      float xDiff=bb[1]-bb[0];
      float yDiff=bb[3]-bb[2];
      float zDiff=bb[5]-bb[4];
      float s=cube.getScale();
  SimpleVector out = new SimpleVector(xDiff*s,yDiff*s,zDiff*s);
am i in the right path?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: set generic scale for diffrent 3D model in JPCT-AE VUFORIA
« Reply #6 on: October 22, 2014, 11:14:12 am »
Looks reasonable to me.