Author Topic: Problems loading models and applying textures  (Read 6187 times)

Offline alakat

  • byte
  • *
  • Posts: 9
    • View Profile
Problems loading models and applying textures
« on: June 01, 2008, 06:42:38 pm »
Hi all,i am a new jpct programer
at the moment i work  in a turn strategic game, in this game i use jpct but i am in trouble with textures and models.
i will explain my difficulties:
With this code i load a model and apply texture on it. but textures are not shown.
Code: [Select]
TextureManager textureManager = TextureManager.getInstance();
textureManager.addTexture("metal", new Texture(new FileInputStream("/home/miguel/perfectday_project/JPCTExm/textures/rocks.jpg")));
model = Loader.load3DS(new FileInputStream("/home/miguel/perfectday_project/blender_model/obj_export/plano.3ds"), 1);
Object3D field = model[0];
field.setTexture("metal");
if i don t load any model, and use Primitive to create a plane and apply texture on it the textures are shown.  ???
Code: [Select]
Object3D plane = Primitives.getPlane(1, 4);
        plane.translate(SimpleVector.ORIGIN);
        plane.setTexture("metal");
        plane.rotateX((float) (Math.PI /-2));
        plane.setEnvmapped(Object3D.ENVMAP_DISABLED);
        plane.build();
i have tried loading .obj and .3ds and textures are not applied tomy models ( i even tried loading very simple model like a cube or a plane)
I created these models  by using Blender 2.45  and exporting then to .0bj and 3ds. I dont know if the problem occurs when exporting the models or if it is due to the jpct configuration.
CarTest example works
Thank you  very much.
sorry for my english

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Problems loading models and applying textures
« Reply #1 on: June 01, 2008, 07:00:54 pm »
Are you calling build() on that 'field'-object after assigning the texture? Which renderer are you using? Software or OpenGL?

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Problems loading models and applying textures
« Reply #2 on: June 01, 2008, 07:16:50 pm »
I don't know very much about 3ds models, but it may be how the model is built. I have noticed that when setTexture is called on an object that was built with triangles that have no uv coordinates, it appears the texture is not set. But, when the object is built with triangles that do have uv coordinates the texture is set properly. Maybe when you generate the model, your not setting any textures to it, and when jpct builds the model it builds it with triangles that have no texture coordinate?

Also, make sure you check the output on the console.

Jman

Offline alakat

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Problems loading models and applying textures
« Reply #3 on: June 01, 2008, 08:41:41 pm »
thank you  for a so quick answer
Igon, i called .build() in field-object and i used Software Render.
Code: [Select]
TextureManager textureManager = TextureManager.getInstance();
        textureManager.addTexture("metal", new Texture(new FileInputStream("/home/miguel/perfectday_project/JPCTExm/textures/rocks.jpg")));
        model = Loader.load3DS(new FileInputStream("/home/miguel/perfectday_project/blender_model/obj_export/plano.3ds"), 1);
        Object3D field = model[0];
        field.setTexture("metal");
        field.setEnvmapped(Object3D.ENVMAP_DISABLED);
        field.setCenter(SimpleVector.ORIGIN);
        field.rotateX((float) (Math.PI /-2));       
        int size = (int) field.getScale();
        System.out.println("SCALE:"+field.getScale());
        field.translate(-field.getScale()*(1), -field.getScale()*(1), 0);
        field.setOrigin(SimpleVector.ORIGIN);
        field.build();
JavaMan: i think you have got  a point there. the model may not have uv cordinates, How could i set them in  run time? Or should i set them in model design?
how can i set jpct in DEBUG mode? Does jpct use Log4J?
Thank you again.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Problems loading models and applying textures
« Reply #4 on: June 01, 2008, 08:48:09 pm »
jPCT doesn't log anything about texture coordinates. You should know if your model has some in the modeler and if you have exported them correctly. There are ways to assign them at run time, but it's much more complicated than doing this in the modeler. For a quick check, you can call one of the calcTextureWrapXX()-methods in Object3D. If textures appear then, your models don't have correct UV-mapping assigned in the modeler.
jPCT doesn't use log4j...i hate it with a passion. It uses its own simple logging hidden the Logger-class. By default, it's prints out all it can. There's no way to enable more logging, just less.

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Problems loading models and applying textures
« Reply #5 on: June 02, 2008, 12:33:48 am »
How could i set them in  run time? Or should i set them in model design?

Well you could use the PolygonManager of the object to go through the polygons and set the textures individually, but that obviously is going to take some time. I think you should try to set them in Blender.

Jman

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: Problems loading models and applying textures
« Reply #6 on: June 02, 2008, 03:46:08 am »
If you can see the texture in 3d mode, then it should be exporting the uv coordinates.  I use Blender with 3ds models and don't have any problem. 
« Last Edit: June 02, 2008, 03:48:58 am by fireside »
click here->Fireside 7 Games<-

Offline alakat

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Problems loading models and applying textures
« Reply #7 on: June 02, 2008, 08:32:14 am »
Again Thank every body.
I  do more examples, i explain this example and there result.
I modified CarTest, and i use my models, in this example mi model do NOT set Texture, because i think that the problem is a model, but.
I modified my code, and i use cartest terrain model (terascene.3ds). and do not set textures  ???, becouse i have a problem in code.
As well as  this examples, i tried two more examples. In first example i add field.calcTextureWrap():

Code: [Select]
textureManager.addTexture("metal", new Texture(new FileInputStream("/home/miguel/perfectday_project/JPCTExm/textures/rocks.jpg")));
        model = Loader.load3DS(new FileInputStream("/home/miguel/perfectday_project/blender_model/obj_export/montanya2.3ds"), 1);
        Object3D field = model[0];
        field.calcTextureWrap();
        field.setTexture("metal");
        field.setEnvmapped(Object3D.ENVMAP_DISABLED);
        field.setCenter(SimpleVector.ORIGIN);
        field.rotateX((float) (Math.PI /-2));
       
        int size = (int) field.getScale();
        System.out.println("SCALE:"+field.getScale());

        field.setOrigin(SimpleVector.ORIGIN);
        field.build();
        worldx.addObject(field);

this code does not set Texture. In Secon code:
Code: [Select]
textureManager.addTexture("metal", new Texture(new FileInputStream("/home/miguel/perfectday_project/JPCTExm/textures/rocks.jpg")));
        model = Loader.load3DS(new FileInputStream("/home/miguel/perfectday_project/blender_model/obj_export/montanya2.3ds"), 1);
        Object3D field = model[0];
        field.calcTextureWrapSpherical();
        field.setTexture("metal");
        field.setEnvmapped(Object3D.ENVMAP_DISABLED);
        field.setCenter(SimpleVector.ORIGIN);
        field.rotateX((float) (Math.PI /-2));
       
        int size = (int) field.getScale();
        System.out.println("SCALE:"+field.getScale());

        field.setOrigin(SimpleVector.ORIGIN);
        field.build();
        worldx.addObject(field);
in this code set Texture but they are dont show ver well

I use Blender to model created. But i new Blender used, and i dont know if i exporting my model well. How do i exporting model to set uv cordinates? i need exporting in .obj o .3ds.

Thank every body for help me.

Offline alakat

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Problems loading models and applying textures
« Reply #8 on: June 02, 2008, 09:11:47 am »

I find my problem. it is in models.
Thank for every body.

My last question it is: where  can i find good blender tutorial that explain me exporting model.
Agan Thank every body

Offline alakat

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Problems loading models and applying textures
« Reply #9 on: June 02, 2008, 09:59:35 am »


I resolved the problem
If other person suffer this problem, i resolved add uv textures in model blender. you press button "new " in UVTexture, button place is "edit mode"

Sorry i dont know put image in this post. email me if you have this problem. See my profile
Thank for all

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: Problems loading models and applying textures
« Reply #10 on: June 02, 2008, 03:27:29 pm »
Blender takes a little while to get used to, but it's a nice program.  They made some changes in 2.46 that drove me crazy, but I'm used to them now. 
click here->Fireside 7 Games<-