set generic scale for diffrent 3D model in JPCT-AE VUFORIA

Started by angieIe, October 15, 2014, 04:57:43 AM

Previous topic - Next topic

angieIe

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.

EgonOlsen

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.

angieIe


angieIe

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

EgonOlsen

What is this part supposed to do?


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..

angieIe

hi, Egon. Try to understand and so far this is my code:

      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?

EgonOlsen