www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: tezcancirakoglu on June 10, 2015, 12:05:18 pm

Title: After loading any 3ds model, i need to change texture of its sub objects
Post by: tezcancirakoglu on June 10, 2015, 12:05:18 pm
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?



Title: Re: After loading any 3ds model, i need to change texture of its sub objects
Post by: tezcancirakoglu on June 10, 2015, 12:11:44 pm
Here is a sample screenshot. How to change texture of pillows only?
(http://forextraq.com/wp-content/uploads/2015/06/sc.png)

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 );
Title: Re: After loading any 3ds model, i need to change texture of its sub objects
Post by: EgonOlsen on June 10, 2015, 12:51:10 pm
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().
Title: Re: After loading any 3ds model, i need to change texture of its sub objects
Post by: tezcancirakoglu on June 10, 2015, 04:22:44 pm
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
Title: Re: After loading any 3ds model, i need to change texture of its sub objects
Post by: Gatobot14 on June 10, 2015, 11:02:27 pm
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.