Author Topic: After loading any 3ds model, i need to change texture of its sub objects  (Read 662 times)

Offline tezcancirakoglu

  • byte
  • *
  • Posts: 3
    • View Profile
Hello,

i am loading 3ds model into the world and it is all loaded with textures. But after than i need to change some textures of sub objects (for example, pillow textures inside a sofa model) i cannot access sub objects of the whole model. (Also when loading 3ds model we merge all objects into one as seen on the sample code on jptc site, is it about that?)

How can we do this in jptc?




Offline tezcancirakoglu

  • byte
  • *
  • Posts: 3
    • View Profile
Here is a sample screenshot. How to change texture of pillows only?


Loading code is below...

   private Object3D load3dsModel(String filename, float scale) throws IOException {
      InputStream stream = MainActivity.this.getApplicationContext().getAssets().open(filename);
      Object3D[] model = Loader.load3DS(stream, scale);
        Object3D o3d = new Object3D(0);
        Object3D temp = null;
        for (int i = 0; i < model.length; i++) {
            temp = model;
            temp.setCenter(SimpleVector.ORIGIN);
            temp.rotateX((float)( -.5*Math.PI));
            temp.rotateMesh();
            temp.setRotationMatrix(new Matrix());
            o3d = Object3D.mergeObjects(o3d, temp);
            o3d.build();
        }
        return o3d;
    }

in other routine...

curModel = loadObjModel("kanepe.3ds", 0.05F);
world.addObject(curModel );

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Just don't merge the objects or at least not the ones that you want to change. Add them to the world individually. After that, you can assign a new texture or, if that's needed, you can change the texture coordinates by using the PolygonManager. If you have to modify the coordinates, make sure to build the object by using build(false); instead of just build().

Offline tezcancirakoglu

  • byte
  • *
  • Posts: 3
    • View Profile
Thanks for the answer, i already did that. Did not merge, added all to world. But when i need to rotate the whole object i fail. Cos every object's pivot point is their calculated center. Also i tried to create a dummy Object3D and add the objects from 3ds to it, i could not get it shown on screen. As long as i am using one model in the world in my app, i am able to use camera for rotation. But when i began to add multiple models into the world camera rotation will not be a solution.

Aim of this app is to make user place furnitures around and change textures on any of them to fit in his/her room.

Is it possible to add all of the objects to one Object3d created on the fly as children?

Thanks

Offline Gatobot14

  • int
  • **
  • Posts: 64
    • View Profile
create a dummy object and add all the part of the model, then you must add the parts of the model to the world, and if you need to rotate/tranlate do it on your dummy object.