Author Topic: Texture-coordinates from Blender  (Read 5154 times)

Offline Enk

  • byte
  • *
  • Posts: 22
    • View Profile
Texture-coordinates from Blender
« on: August 16, 2008, 12:24:04 am »
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

Code: [Select]
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).


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Texture-coordinates from Blender
« Reply #1 on: August 16, 2008, 11:24:52 am »
Have you called build() on the object?

Offline Enk

  • byte
  • *
  • Posts: 22
    • View Profile
Re: Texture-coordinates from Blender
« Reply #2 on: August 16, 2008, 01:34:06 pm »
Yes, after it is loaded I call this function:

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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Texture-coordinates from Blender
« Reply #3 on: August 16, 2008, 01:46:36 pm »
Then it should unless blender doesn't export the coordinates correctly to 3ds. Have you tried an export to obj?

Offline Enk

  • byte
  • *
  • Posts: 22
    • View Profile
Re: Texture-coordinates from Blender
« Reply #4 on: August 16, 2008, 02:32:19 pm »
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? :/

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Texture-coordinates from Blender
« Reply #5 on: August 16, 2008, 02:56:17 pm »
The link doesn't work for me... :(

Offline Enk

  • byte
  • *
  • Posts: 22
    • View Profile
Re: Texture-coordinates from Blender
« Reply #6 on: August 16, 2008, 03:00:58 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Texture-coordinates from Blender
« Reply #7 on: August 16, 2008, 05:26:33 pm »
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?

Offline Enk

  • byte
  • *
  • Posts: 22
    • View Profile
Re: Texture-coordinates from Blender
« Reply #8 on: August 16, 2008, 05:42:27 pm »
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.

Code: [Select]
// 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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Texture-coordinates from Blender
« Reply #9 on: August 16, 2008, 06:13:32 pm »
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:

Code: [Select]
Entity ent=(Entity) world.getObject(Interact2D.getObjectID(result));

If you are not sure, do:

Code: [Select]
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...
« Last Edit: August 16, 2008, 06:38:52 pm by EgonOlsen »

Offline Enk

  • byte
  • *
  • Posts: 22
    • View Profile
Re: Texture-coordinates from Blender
« Reply #10 on: August 16, 2008, 06:23:56 pm »
Thanks, it worked perfectly!

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

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: Texture-coordinates from Blender
« Reply #11 on: August 16, 2008, 09:46:18 pm »
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<-

Offline Enk

  • byte
  • *
  • Posts: 22
    • View Profile
Re: Texture-coordinates from Blender
« Reply #12 on: August 17, 2008, 02:47:44 pm »
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 :)