.obj no texture

Hi



i tried the whole night to get it to work, i don't get it and do not know how to continue.



I know this problem have been posted several times, i tried these examples, but damm, my nice satellite in outer space does miss his textures.



first:

jme 1

StandardGame

Blender export to obj



// in a GameState extending GameState

ObjToJme converter = new ObjToJme();
      try {
         URL objFile = TestObjJmeWrite.class.getClassLoader().getResource(
               "objects/mainMenu/satellite.obj");
//         converter.setProperty("mtllib", objFile);
//                     converter.setProperty("texdir",objFile);
         ByteArrayOutputStream BO = new ByteArrayOutputStream();
         System.out.println("Starting to convert .obj to .jme");
         converter.convert(objFile.openStream(), BO);
                        //load as a TriMesh if single object
         TriMesh model = (TriMesh) BinaryImporter.getInstance().load(
               new ByteArrayInputStream(BO.toByteArray()));
//         Node model=(Node)BinaryImporter.getInstance().load(
//                  new ByteArrayInputStream(BO.toByteArray()));

            //load as a node if multiple objects

         model.setModelBound(new BoundingSphere());
         model.updateModelBound();
         rootNode.attachChild(model);

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


       
        rootNode.updateRenderState();


i tried it with

converter.setProperty("mtllib", objFile); converter.setProperty("texdir",objFile);

and without theese two lines as seen in some posts, can't get it work.

The .obj, .mtl and textures are all in the same dir, textures are png.

In Blender it looks fine, by exporting i select:
Context
  Selection Only
Extra Data
  Edges
  Normals
  High Quality No
  Uv's
  Materials
  Triangulate
Grouping
  Objects
Object Prefs.
  Apply modifiers
  Rotate X90

With this i got two different  results.
When i try it with

converter.setProperty("mtllib", objFile);
converter.setProperty("texdir",objFile);

all faces have the color assignend in Blender, without this two lines theses faces become white (looks like a failed texture loading but i don't really get the difference).

In my GameState i have also implemented

 try {
            ResourceLocatorTool.addResourceLocator(
                    ResourceLocatorTool.TYPE_TEXTURE,
                    new SimpleResourceLocator(getClass().getResource(
                            "/objects/mainMenu/")));
        } catch (Exception e) {
            System.out.println("Unable to access texture directory.");
            e.printStackTrace();
        }

. Textures are loaded there propely, when i try to use one of the satellite textures as a skybox textutre it is shown right.

Last, sorry for my spelling, it's a some time ago i posted in english.

mfg
Drake

Could you try adding the following:


ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,new SimpleResourceLocator(texdir));



where "texdir" is a URL for the folder which stores your textures.

This line is already in:


Drake said:

 try {
            ResourceLocatorTool.addResourceLocator(
                    ResourceLocatorTool.TYPE_TEXTURE,
                    new SimpleResourceLocator(getClass().getResource(
                            "/objects/mainMenu/")));
        } catch (Exception e) {
            System.out.println("Unable to access texture directory.");
            e.printStackTrace();
        }




Maybe the problem is not jme nor me, but a falied export.


URL objFile = TestObjJmeWrite.class.getClassLoader().getResource("objects/mainMenu/satellite.obj");
URL mtlFile = TestObjJmeWrite.class.getClassLoader().getResource("objects/mainMenu/satellite.mtl");
URL dir = TestObjJmeWrite.class.getClassLoader().getResource("objects/mainMenu");
converter.setProperty("mtllib",  mtlFile);
converter.setProperty("texdir", dir);



you have to set the mtllib property to the .mtl file and the texdir directory to the directory

also, check if the filenames of the referenced textures in the .mtl file are the same as the filenames of the actual textures. e.g.: Cinema 4d replaces " " with "_" in texture filenames ...

hi



first, thx for your answers, but i think the problem is the exporting in blender. After long experementing i tried to import the .obj file in blender and it doesn't show textures either. So i think i know where to start today after work.



Drake

Did you attach a lightState directly to the character? If not–do that.

I've opend the .obj in a text editor and couldn't find any link to one of my assigned textures, but i don't get my fault in exporting. But it's nice to now that the export is the (first) thing that's going wrong.



Drake

unfortunately, its completely normal that 3d modelling programs export things wrong. as far as i know, only 3ds max exports .obj files the right way and cinema 4d needs a third party plugin to get it right … all you need to do is try …

I don't get it.



It is possible to export from into .obj with all texture info?

The HelloModelLoading example doesn't use texures. Is there a way to add texture info maually in the obj file, or would it be better to use another format for exporting?



Sorry for this continous asking, I'm working with java some time, but 3D is new to me, never needed to export something from blender.



Drake



[edit]

back to the roots, the problem is blender and how the textures were applied, and there i have to start.

When i export it to obj and re import in blender textures are missing, and i thing this is the part where i really need help, but don't know what is missing.

[/edit]

Drake said:

Is there a way to add texture info maually in the obj file


there is:

One material in a .mtl file looks like this:


newmtl Plane4
illum 2
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
map_Ka PlaneSurface_Color.dds



the 'map_Ka' thingy lets you set a texture

Blender's OBJ exporter does not define a texture path inside the material file, but it does include texture coordinates. You have to manually write map_Kd <texture path> in the mtl file or apply the texture within jME. There other formats (e.g mesh.xml) which have better support in both modeling tools and jME.

@Momoko_Fan: God bless you. Thanks alot. My Programmer at least stopped banging his head against the walls. :wink: This stuff is really "explained". This will help us. Thanks.

Hallo



shame on me, the textures were wrong applied in blender, (first) steps on 3d arent' really easy, but jme is a really nice development.



mfg

Drake