Author Topic: Project texture down on ground and objects  (Read 7881 times)

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Project texture down on ground and objects
« on: November 18, 2011, 09:26:59 am »
Hi people,

I'm trying to figure out howto draw a texture "mark like a circle" on location with the mouse on the ground and objects.
Is that possible ? anybody done something like that ?  I was thing to get the position to draw it like picking on Objects maybe,  and somehow projecting a texture down on anything below it. maybe blit ?

I hope this make sense  :-)


Faith is for the weak...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Project texture down on ground and objects
« Reply #1 on: November 18, 2011, 09:43:33 am »
You can either use a plane object that hovers across your ground and maybe adjusts itself roughly to the grounds shape based on the underlying polygon's face normal or some distance check from multiple points (like the car example does it do make the car follow the terrain). Or you can use a Projector. For that, you need an additional texture layer on all objects that should show the mark.

This (german) thread has an example: http://www.jpct.net/forum2/index.php/topic,2387.msg17591.html#msg17591

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Re: Project texture down on ground and objects
« Reply #2 on: November 18, 2011, 10:35:52 am »
Thank you again Egon

I think I'm going to try working on using the Projector, I was think about creating a Light and moving it around, but its only a color and I wantet a bit more maybe create a animation.
Faith is for the weak...

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Re: Project texture down on ground and objects
« Reply #3 on: November 18, 2011, 06:41:59 pm »
I can't seem to get the Projector to show anything at all.
I created a new Projector and just set it to look at the center of my landscape.

I added the texture to all the textures, but nothing is coming up. I apply the texture to the TextureInfo after the models have been loaded and the textures have been set. Could this be the problem ? Would I have to set the texture on the Object again ?

right now I'm doing this.
Code: [Select]
    public void setMarker(String texturename) {
        markerTextureID = texturename;
        Enumeration e = tm.getNames();
        while (e.hasMoreElements()) {
            String textureID = e.nextElement().toString();
            if (textureID.equals(markerTextureID)) {
                continue;
            }
            TextureInfo info = new TextureInfo(tm.getTextureID(textureID));
            info.add(tm.getTextureID(markerTextureID), TextureInfo.MODE_ADD);
        }

        tm.getTexture(markerTextureID).setEnabled(true);
        tm.getTexture(markerTextureID).setProjector(markerProjector, true);
        drawMarker = true;
    }
Faith is for the weak...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Project texture down on ground and objects
« Reply #4 on: November 19, 2011, 12:44:09 am »
You have to assign the created TextureInfo instead of the texture that the object has. In your code, you just create it and do nothing with it.

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Re: Project texture down on ground and objects
« Reply #5 on: November 19, 2011, 08:37:06 am »
I'm sorry, you so correct dont know what I was thinking.
Is there anyway to get the Textures or TextureInfo from the Object3D, so it returns what allready been set on it or is it impossible or maybe just the Texture names found when it got Loaded throw the Loader ?

I search the java doc and the only way I could find out what texture names belong to what Object3D is using the Loader.readTextureNames3DS.
This will tell me what texture name belongs to what object, but how do I read the texture names set for a Wave Object (obj) or other model ?




Faith is for the weak...

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Re: Project texture down on ground and objects
« Reply #6 on: November 19, 2011, 08:56:19 am »
Its not all that important.
I can write a simple utill class to read the names from the loader if its a 3DS and just do a simple pattern search for other models.
Then i can recreate a TextureInfo containing all textures for a given model
Faith is for the weak...

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Re: Project texture down on ground and objects
« Reply #7 on: November 19, 2011, 10:23:40 am »
LOL I'm loosing my marbles here.
I have my Model, it is a grouped with with lets say 2 parts in it, and one part have TextureA and the other TextureB

When I create a TextureInfo its for a single Texture like TexturaA or TextureB, so I create two TextureInfo foreach Texture.
Now when I want to reapply the Textures as TextureInfo on my Object3D then I can only set one TextureInfo.

And uses that for the hole model ? I havent tried yet ., but that would be my believe.
So how do I added the second TextureInfo.
Faith is for the weak...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Project texture down on ground and objects
« Reply #8 on: November 19, 2011, 11:20:30 am »
The PolygonManager lets you access the texture information of each polygon in the mesh. That might help.

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Re: Project texture down on ground and objects
« Reply #9 on: November 19, 2011, 12:18:22 pm »
Ohh thank you I can see that, but that just helps me getting all the Textures for a Model.
The PolygonManager can set a Texture for a Poly Id.

So when I found all my used Textures and wrapped them in a TextureInfo where I added my Marker to be projected down.
How do I reapply the Textures to the Model. The Model only takes one TextureInfo ? and all Textures are wrapped in their own TextureInfo and I need to apply two/Or more Textures back om model.

Is there a way I can set the TextureInfo in the TextureManager insted of a Texture, so lets say TextureManager.getInstance().addTexture("roof.jpg", textureInfoA); ??

I might be going around this the wrong way or misunderstand a lot of things, so please excuse my lack of knowledge.
Faith is for the weak...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Project texture down on ground and objects
« Reply #10 on: November 19, 2011, 12:25:33 pm »
The PolygonManager lets you get as well as set the texture per polygon.

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Re: Project texture down on ground and objects
« Reply #11 on: November 19, 2011, 07:52:35 pm »
I'm not sure I understand... howto use that...
I created a small demo project, that projects a mark on the ground, there is allso a simple object more, that have two textures in the in the scene as well. I havent added any "mark" code for it, for I have nu glue where to start using the PolygonManager and setting the texture. The mark moves on the ground based on the Mouse or that was the idea, it does not work perfectly but I'll have to fix that later.   

If you get some time at some point, can you have a look at it and see if I'm overcomplicated what I'm trying to do, or maybe trying to do something impossible.

http://www.cintix.dk/MarkedWorld.zip

Faith is for the weak...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Project texture down on ground and objects
« Reply #12 on: November 20, 2011, 11:23:51 pm »
I'll take a look when i find the time. However, it's actually pretty simple: Load the model, use the PolygonManager to get the texture of each polygon, create a new TextureInfo instance with that, add the projective texture and assign that TextureInfo back to the polygon...done!

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Re: Project texture down on ground and objects
« Reply #13 on: November 21, 2011, 07:10:51 am »
Arhhh I see !!

I was look at the polygonManager at looked at setPolygonTexture(int polyID, int textureID) , didnt really notice that it had setPolygonTexture(int polyID, TextureInfo tInf) too.
It made no sense using the PolygonManager then, but now it does
Faith is for the weak...

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Re: Project texture down on ground and objects
« Reply #14 on: November 21, 2011, 12:47:59 pm »
Okay I tried and yes it does project the marker on all object, but it looses some of the textures on the objects.
In my Demo project I lost the roof texture and only the marker came up, and it shows the marker on both object at the same time

I tried adjusting  markerProjector.setFOV(0.3f); and the limits to get a better image, but it still streches it sides to width of the objects... 

Code: [Select]
    public void setMarker(String markerTextureName) {
        Enumeration e = tm.getNames();
        Map<Integer, TextureInfo> textureMap = new TreeMap<Integer, TextureInfo>();
        int maxID, textureIndex;
        PolygonManager manager;

        tm.getTexture(markerTextureName).setEnabled(true);
        tm.getTexture(markerTextureName).setProjector(markerProjector, true);

        while (e.hasMoreElements()) {
            String textureName = e.nextElement().toString();
            if (textureName.equals(markerTextureName)) {
                continue;
            }
            TextureInfo info = new TextureInfo(tm.getTextureID(textureName));
            info.add(tm.getTextureID(markerTextureName), TextureInfo.MODE_ADD);
            textureMap.put(tm.getTextureID(textureName), info);
        }


        Collection<Object3D> models = model3DManager.getModels();
        for (Object3D md : models) {
            if (md != skyModel) {
                manager = md.getPolygonManager();
                maxID = manager.getMaxPolygonID();
                for (int idx = 0; idx < maxID; idx++) {
                    textureIndex = manager.getPolygonTexture(idx);
                    manager.setPolygonTexture(idx, textureMap.get(textureIndex));
                }
            }
        }
   }
   
   // I allso tried to match the UV of the existing texture
    public void setMarker(String markerTextureName) {
        Map<Integer, TextureInfo> textureMap = new TreeMap<Integer, TextureInfo>();
        int maxID, textureIndex;
        PolygonManager manager;
        TextureInfo info;

        tm.getTexture(markerTextureName).setEnabled(true);
        tm.getTexture(markerTextureName).setProjector(markerProjector, true);

        Collection<Object3D> models = model3DManager.getModels();
        for (Object3D md : models) {
            if (md != skyModel) {
                manager = md.getPolygonManager();
                maxID = manager.getMaxPolygonID();
                for (int idx = 0; idx < maxID; idx++) {
                    textureIndex = manager.getPolygonTexture(idx);
                    info = new TextureInfo(textureIndex);
                    SimpleVector uv1 = manager.getTextureUV(idx, 0);
                    SimpleVector uv2 = manager.getTextureUV(idx, 1);
                    SimpleVector uv3 = manager.getTextureUV(idx, 2);
                    info.add(tm.getTextureID(markerTextureName),uv1.x,uv1.y,uv2.x,uv2.y,uv3.x,uv3.y,TextureInfo.MODE_ADD);
                    manager.setPolygonTexture(idx, info);
                }
            }
        }
    }
Faith is for the weak...