Author Topic: Texturing a Primitive  (Read 3880 times)

Offline Kaiidyn

  • long
  • ***
  • Posts: 103
    • View Profile
Texturing a Primitive
« on: November 21, 2010, 10:06:09 am »
Hello,

I just started out a couple of days ago with 3D programming for Android,
And jPCT-ae really got my attention, It's easy to use and well documented.
But I got a problem putting a texture on a Ellipsoid primitive.

Code: [Select]
TextureManager.getInstance().flush();
TextureManager tm = TextureManager.getInstance();
Resources res = Engine.resources;

/** LOAD TEXTURES **/
Texture random = new Texture(Engine.resources.getDrawable(R.raw.random));
tm.addTexture("random", random);

TextureInfo randomTex = new TextureInfo(tm.getTextureID("random"));

button1 = Primitives.getEllipsoid(64, 0.5f);
button1.setTexture(randomTex);
button1.build();
button1.translate(0, -125, 0);
world.addObject(button1);
All this code is located in onSurfaceCreated.

The texture I'm trying to put on.

I got the feeling it does actually work, but partially,
As I see my entire mesh in red.
I think I need to do something with the UV Mapping, but have no idea how that works.
Or, it has something to do with texture scaling.. that the image is too big for the object.

My question therefor is, how do I downscale the texture to match my object, or how does UV Mapping work?

Kind regards,
Kaiidyn.


Edit:
Figured out that it is actually a problem with the UV mapping,
the center of the texture (where i have the text) gets put on the side of the Ellipsoid that has been squeezed by the scaleHeight.
What I want is that the text in the texture is set on the top of the primitive as a button, like This one.
But I have no idea how to do that.
« Last Edit: November 21, 2010, 10:32:38 am by Kaiidyn »
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer’s intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texturing a Primitive
« Reply #1 on: November 21, 2010, 04:15:14 pm »
The objects created by the Primitives class have no proper uv-coordinates (except for the plane). They are mainly meant as placeholders or for debugging. There are two calcTextureWrap....methods in Object3D, but the outcome most likely won't fit your needs. It might be a better idea to create something in a 3d editor instead.

Offline vael

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Texturing a Primitive
« Reply #2 on: November 21, 2010, 06:12:00 pm »
btw what does calcTextureWrap() do? I tried calling it with a box primitive and it seemed like all uv were set (0; 0)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texturing a Primitive
« Reply #3 on: November 21, 2010, 08:23:38 pm »
It's like static environment mapping. UVs are 0,0 anyway, so letting calcTextureWrap...do this would be pointless.

Offline Kaiidyn

  • long
  • ***
  • Posts: 103
    • View Profile
Re: Texturing a Primitive
« Reply #4 on: November 21, 2010, 10:32:42 pm »
OK, thanks for the reply..
I currently don't have any modelling programs installed that I can actually work with,
Do have AC3D and Blender installed, but AC3D's export function just fails, and I don't like how Blender works.
Will download 3ds Max again when I'm at my parents place with better internet =p (next weekend:p)
Unless someone else could model me a button like this one or this one that can animate (pressing the button) *puppyeyes* :p

Kind regards and thanks again,
Kaiidyn.

Edit: Managed to get it working with AC3D :)
« Last Edit: November 21, 2010, 11:32:15 pm by Kaiidyn »
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer’s intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch