Texture-coordinates from Blender

Started by Enk, August 16, 2008, 12:24:04 AM

Previous topic - Next topic

Enk

Hei, I am having a problem with textures from blender.

I have a heightmap (which is actually just a flat plane). I have assigned a material named "rocks" and a texture to the material named "rocks" (the picture from the car-test example). I have sat x- and y-repeat to 16 and exported it as a 3DS-file, but when I run it the plane is just green (the texture is probably stretched).

In my program I have

Texture rocks = new Texture("textures/rocks.jpg");
texture_manager.addTexture("rocks", rocks);

Object3D terrain = map_manager.loadMap("models/map/1.3ds");

Function loadMap:
...
        Object3D[] objs = Loader.load3DS(input, 400);
        if (objs.length > 0) {
            map = new Map(objs[0]);
            map.setTexture("rocks.jpg");
        }
       
        return map;
...


What do I have to do to get the texture-coordinates from blender to work (as in the 3DS-file in the car example).


EgonOlsen

Have you called build() on the object?

Enk

Yes, after it is loaded I call this function:

    /**
     * Build the map object and add it to the world
     * @param world
     */
    public void addToWorld(World world) {
        world.addObject(this);
        enableLazyTransformations();
        build();
        createTriangleStrips(2);
    }

EgonOlsen

Then it should unless blender doesn't export the coordinates correctly to 3ds. Have you tried an export to obj?

Enk

Tried it and got the same results.

http://main.spurv.net/upload/game.JPG

I used the car-example as a base for the project so I guess there is something I am doing wrong (or not doing) in Blender? :/

EgonOlsen


Enk

Strange, it works here :S

I can describe it though: the ground is solid green with a lot of noise. When I move the camera the noise flickers (like a TV without signal :P), but when the camera stands still it takes a few seconds the flickering stops.



Off-topic:
In my test game I have this class diagram:
Object3D
- Entity
-- DynamicEntity
--- Player

I have used Interact2D to select the object, but it is possible to get the Player-instance from Object3D? Sorry for my poor java-knowledge.

EgonOlsen

Maybe your coordinates are way too high? The software renderer allows for tiling (i.e. coordinates larger than 1 will be remapped to 0..1) but it's limited in accuracy. You can't use 100 as a texture coordinate. Doing so may cause similar flickering. If that's not the case, i suggest to load the model in some other viewer to see if the texturing is exported correctly.

About your other question: You can cast your Object3D to a Player given that it is a player. Or did i get you wrong?

Enk

I have just applied a texture to a object in Blender and sat the X-repeat and Y-repeat values. I'll try and play around some more.

The other question:
I want to be able to get a instance of the Entity-class from the Object3D.


// In the class definition
public class Entity extends Object3D { ...

// In the game
...
private Entity enemy = new Entity();
...


// In the mouse handling
...
Object3D selected_object = world.getObject(Interact2D.getObjectID(result));

// Now I want to get the Entity-instance (e.g. enemy) from the selected_object

EgonOlsen

#9
The Object3D IS the instance of the Entity class, because Entity extends Object3D. If you are sure, that tee Entity-instance has been returned, you can simply do:


Entity ent=(Entity) world.getObject(Interact2D.getObjectID(result));


If you are not sure, do:


Object3D obj=world.getObject(Interact2D.getObjectID(result));
Entity ent=null;
if (obj instanceof Entity) {
   ent=(Entity)  obj;
}


Not that both ways are very elegant, but there is no other way in this case...

Enk

Thanks, it worked perfectly!

I'll try to get the textures working now. Thanks for all the replies.

fireside

On the textures in Blender.  I think it might only export the main window texture coordinates from the image editor.  What I do is open image editor, select all the vertices I want to texture in edit mode of the object and choose an image in the image editor.  For repeats, I go into the image editor window, select all the vertices, and then "s" size them larger, which makes them repeat.  You can also cube map etc, by choosing "u" in the 3d window.
click here->Fireside 7 Games<-

Enk

Thanks Fireside! :)

Instead of using UV/Image-editor, I just added a texture to the material which didn't work. With TexFace it worked just fine :)