Problems loading models and applying textures

Started by alakat, June 01, 2008, 06:42:38 PM

Previous topic - Next topic

alakat

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.

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.  ???

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

EgonOlsen

Are you calling build() on that 'field'-object after assigning the texture? Which renderer are you using? Software or OpenGL?

JavaMan

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

alakat

thank you  for a so quick answer
Igon, i called .build() in field-object and i used Software Render.

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.

EgonOlsen

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.

JavaMan

Quote from: alakat on June 01, 2008, 08:41:41 PM
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

fireside

#6
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. 
click here->Fireside 7 Games<-

alakat

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():


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:

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.

alakat


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

alakat



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

fireside

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<-