jPCT-AE - a 3d engine for Android > Support

How to add more texture maps to obj

(1/5) > >>

a8451727:
At present, I only know how to add 1 texture map to an object
But the exported obj has many texture maps


--- Code: ---#
## Alias OBJ Material File
# Exported from SketchUp, (c) 2000-2012 Trimble Navigation Limited

newmtl FrontColor
Ka 0.000000 0.000000 0.000000
Kd 1.000000 1.000000 1.000000
Ks 0.330000 0.330000 0.330000

newmtl Color_E04
Ka 0.000000 0.000000 0.000000
Kd 1.000000 1.000000 0.600000
Ks 0.330000 0.330000 0.330000

newmtl Color_E03
Ka 0.000000 0.000000 0.000000
Kd 1.000000 1.000000 0.396078
Ks 0.330000 0.330000 0.330000

newmtl Color_007
Ka 0.000000 0.000000 0.000000
Kd 0.227451 0.227451 0.227451
Ks 0.330000 0.330000 0.330000

newmtl Carpet_Loop_Pattern
Ka 0.000000 0.000000 0.000000
Kd 0.650980 0.541176 0.349020
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/Carpet_Loop_Pattern.jpg

newmtl _Wood__Floor_2
Ka 0.000000 0.000000 0.000000
Kd 0.607843 0.411765 0.239216
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/_Wood__Floor_2.jpg

newmtl Stone_Pavers_Flagstone_Gray
Ka 0.000000 0.000000 0.000000
Kd 0.635294 0.635294 0.635294
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/Stone_Pavers_Flagstone_Gray.jpg

newmtl Wood__Floor
Ka 0.000000 0.000000 0.000000
Kd 0.607843 0.411765 0.239216
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/Wood__Floor.jpg

newmtl Stone_Coursed_Rough
Ka 0.000000 0.000000 0.000000
Kd 0.647059 0.627451 0.509804
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/Stone_Coursed_Rough.jpg

newmtl Groundcover_RiverRock_4inch
Ka 0.000000 0.000000 0.000000
Kd 0.529412 0.447059 0.243137
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/Groundcover_RiverRock_4inch.jpg

newmtl _Vegetation_Blur7_1
Ka 0.000000 0.000000 0.000000
Kd 0.325490 0.447059 0.070588
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/_Vegetation_Blur7_1.jpg

newmtl Vegetation_Grass_Artificial
Ka 0.000000 0.000000 0.000000
Kd 0.466667 0.666667 0.352941
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/Vegetation_Grass_Artificial.jpg

newmtl Vegetation_Blur7
Ka 0.000000 0.000000 0.000000
Kd 0.384314 0.529412 0.082353
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/Vegetation_Blur7.jpg

newmtl _Wood__Floor_1
Ka 0.000000 0.000000 0.000000
Kd 0.607843 0.411765 0.239216
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/_Wood__Floor_1.jpg

newmtl Groundcover_Sand_Smooth
Ka 0.000000 0.000000 0.000000
Kd 0.713725 0.580392 0.396078
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/Groundcover_Sand_Smooth.jpg

newmtl _Vegetation_Blur7_3
Ka 0.000000 0.000000 0.000000
Kd 0.278431 0.447059 0.043137
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/_Vegetation_Blur7_3.jpg

newmtl Groundcover_Gravel_1inch
Ka 0.000000 0.000000 0.000000
Kd 0.827451 0.796078 0.635294
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/Groundcover_Gravel_1inch.jpg

newmtl _Vegetation_Juniper2_2
Ka 0.000000 0.000000 0.000000
Kd 0.352941 0.501961 0.254902
Ks 0.330000 0.330000 0.330000
map_Kd changjing2/_Vegetation_Juniper2_2.jpg

--- End code ---

a8451727:
This is part of my code


--- Code: ---                world=new World();
                TextureManager tm=TextureManager.getInstance();
                try {
                    Texture _Vegetation_Blur7_1 = new Texture(getAssets().open(
                            "changjing2/_Vegetation_Blur7_1.jpg"));
                    Texture _Vegetation_Blur7_3 = new Texture(getAssets().open(
                            "changjing2/_Vegetation_Blur7_3.jpg"));
                    Texture _Vegetation_Juniper2_2 = new Texture(getAssets().open(
                            "changjing2/_Vegetation_Juniper2_2.jpg"));
                    Texture _Wood__Floor_1 = new Texture(getAssets().open(
                            "changjing2/_Wood__Floor_1.jpg"));
                    Texture _Wood__Floor_2 = new Texture(getAssets().open(
                            "changjing2/_Wood__Floor_2.jpg"));
                    Texture Carpet_Loop_Pattern = new Texture(getAssets().open(
                            "changjing2/Carpet_Loop_Pattern.jpg"));
                    Texture Groundcover_Gravel_1inch = new Texture(getAssets().open(
                            "changjing2/Groundcover_Gravel_1inch.jpg"));
                    Texture Groundcover_RiverRock_4inch = new Texture(getAssets().open(
                            "changjing2/Groundcover_RiverRock_4inch.jpg"));
                    Texture Groundcover_Sand_Smooth = new Texture(getAssets().open(
                            "changjing2/Groundcover_Sand_Smooth.jpg"));
                    Texture Stone_Coursed_Rough = new Texture(getAssets().open(
                            "changjing2/Stone_Coursed_Rough.jpg"));
                    Texture Stone_Pavers_Flagstone_Gray = new Texture(getAssets().open(
                            "changjing2/Stone_Pavers_Flagstone_Gray.jpg"));
                    Texture Vegetation_Blur7 = new Texture(getAssets().open(
                            "changjing2/Vegetation_Blur7.jpg"));
                    Texture Vegetation_Grass_Artificial = new Texture(getAssets().open(
                            "changjing2/Vegetation_Grass_Artificial.jpg"));
                    Texture Wood__Floor = new Texture(getAssets().open(
                            "changjing2/Wood__Floor.jpg"));


                    tm.addTexture("_Vegetation_Blur7_1",_Vegetation_Blur7_1);
                    tm.addTexture("_Vegetation_Blur7_3",_Vegetation_Blur7_3);
                    tm.addTexture("_Vegetation_Juniper2_2",_Vegetation_Juniper2_2);
                    tm.addTexture("_Wood__Floor_1",_Wood__Floor_1);
                    tm.addTexture("_Wood__Floor_2",_Wood__Floor_2);
                    tm.addTexture("Carpet_Loop_Pattern",Carpet_Loop_Pattern);
                    tm.addTexture("Groundcover_Gravel_1inch",Groundcover_Gravel_1inch);
                    tm.addTexture("Groundcover_RiverRock_4inch",Groundcover_RiverRock_4inch);
                    tm.addTexture("Groundcover_Sand_Smooth",Groundcover_Sand_Smooth);
                    tm.addTexture("Stone_Coursed_Rough",Stone_Coursed_Rough);
                    tm.addTexture("Stone_Pavers_Flagstone_Gray",Stone_Pavers_Flagstone_Gray);
                    tm.addTexture("Vegetation_Blur7",Vegetation_Blur7);
                    tm.addTexture("Vegetation_Grass_Artificial",Vegetation_Grass_Artificial);
                    tm.addTexture("Wood__Floor",Wood__Floor);

                    plane =  Object3D.mergeAll(Loader.loadOBJ(
                            getAssets().open("plane.obj"),
                            getAssets().open("plane.mtl"),
                            0.15f));


                       //??????????????????
//                    plane.setTexture("_Vegetation_Blur7_1");
//                    plane.setTexture("_Vegetation_Blur7_3");
//                    plane.setTexture("_Vegetation_Juniper2_2");
//                    plane.setTexture("_Wood__Floor_1");
//                    plane.setTexture("_Wood__Floor_2");
//                    plane.setTexture("Carpet_Loop_Pattern");
//                    plane.setTexture("Groundcover_Gravel_1inch");
//                    plane.setTexture("Groundcover_Gravel_1inch");
//                    plane.setTexture("Groundcover_RiverRock_4inch");
//                    plane.setTexture("Groundcover_Sand_Smooth");
//                    plane.setTexture("Stone_Coursed_Rough");
//                    plane.setTexture("Stone_Pavers_Flagstone_Gray");
//                    plane.setTexture("Vegetation_Blur7");
//                    plane.setTexture("Vegetation_Grass_Artificial");
//                    plane.setTexture("Wood__Floor");


                } catch (IOException e) {
                    e.printStackTrace();
                }


--- End code ---

AeroShark333:
I believe the general logic should be:
- Load textures with full names
- Load model file
- Load MTL file
- Load 3D object using model and MTL files

If used properly then Object3D#setTexture(...) is not necessary
The model loader will find the texture names that are specified in the MTL file. But these names should be properly set in the texture manager.

Instead of this:
tm.addTexture("_Vegetation_Blur7_1",_Vegetation_Blur7_1);

Try one of these:
tm.addTexture("changjing2/_Vegetation_Blur7_1.jpg",_Vegetation_Blur7_1);

Or:
tm.addTexture("changjing2/_Vegetation_Blur7_1",_Vegetation_Blur7_1);

a8451727:

--- Quote from: AeroShark333 on June 04, 2022, 04:36:14 pm ---I believe the general logic should be:
- Load textures with full names
- Load model file
- Load MTL file
- Load 3D object using model and MTL files

If used properly then Object3D#setTexture(...) is not necessary
The model loader will find the texture names that are specified in the MTL file. But these names should be properly set in the texture manager.

Instead of this:
tm.addTexture("_Vegetation_Blur7_1",_Vegetation_Blur7_1);

Try one of these:
tm.addTexture("changjing2/_Vegetation_Blur7_1.jpg",_Vegetation_Blur7_1);

Or:
tm.addTexture("changjing2/_Vegetation_Blur7_1",_Vegetation_Blur7_1);

--- End quote ---

Hello, aeroshark333

Thank you for your help, but I tried it. It didn't solve the problem

I found that it can only recognize one texture map, which is the first one in the MTL file

EgonOlsen:
It should work that way. Have a look at the log output when loading the file. You should get log messages if a texture name can't be found and you should be able to see what exactly these names are.

Navigation

[0] Message Index

[#] Next page

Go to full version