Mapping Objects

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Mapping Objects

Post by LunaRebirth »

Hello,
I'm really sorry for the title -- I'm not sure how to explain this.

My boyfriend is absolutely in love with Zelda games. As a surprise for his upcoming birthday, I decided to attempt to make him a mobile version for his phone.
While this is all great and I've got everything set up, it seems Zelda Ocarina of Time is doing something I've never been aware of before.

Here's what I'm talking about:
Image
And here's how it should look (the trail):
Image

How do you think they did this? Is it possible for me to do this in Irrlicht??
Same thing for the water. In my program, the water is not clear, nor is it walk-through.
But all objects from the Zelda game are in one large .obj file?
(I could fix the water simply by making it a separate object. But the trail?!)

Any help would be appreciated.
I hope to get this going as soon as possible.
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Mapping Objects

Post by LunaRebirth »

Also,
It seems loading images for models through the .mtl (from .obj file) only works on PC.
The Kokiri textures will not load on the Android version, unless I specifically set materials.
However, the .obj is full of many different objects in one file and as far as I know, I cannot set each object to a different texture within one obj file.

Thanks again!
CuteAlien
Admin
Posts: 9846
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Mapping Objects

Post by CuteAlien »

I use mtl's to load images on Android, so has to work somehow. Are you getting any warnings/errors? Can't tell much more without having the mtl files, obj files, code, paths and textures involved.

Trail looks like wrong material.So you have to change the materials of the corresponding meshbuffer. Same for water.
Making water walkthrough is a little bit more tricky. They probably use the texture-information for this. Basically you would need to create your own triangleselector which only is created for certain mesh-buffer types.

And... your upping the stakes a lot for birthday presents ;-)

edit: Are those zelda .obj files somewhere available online?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Mapping Objects

Post by hendu »

That path texture looks quite like a splatmap, you need to write a shader to use it. Remember that materials are per-meshbuffer, so just that meshbuffer will use that shader.

Likewise, you would mark only the needed meshbuffers transparent, to keep draw overhead low.
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Mapping Objects

Post by LunaRebirth »

The models were all found online at http://www.models-resource.com/nintendo ... inaoftime/
I had not edited any of those I've downloaded, just set them up into the project.

As far as the mtl not loading, I was not getting any errors when compiling using Cygwin, though I have yet to check from the Android logger.

Would either of you be able to provide an example for me, or some link I can use to start writing a shader or any information on how to use the mesh-buffers to complete my task?
I've never done that before, and I've no idea where to start. Anything I can work off at this point would be a huge help..
Thanks!
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Mapping Objects

Post by LunaRebirth »

I'm going to try some pseudo-code, because looking into meshbuffers from the tutorial is quite complicated and confusing.
I'm not sure what to do, so I'm going to write this, and could you let me know where I'm going wrong or what needs changed? I realize no one is here to help me code, but I'd really like to get this at least started on the basics by this week.

Code: Select all

add new SMeshBuffer() from forest level .obj
get vertex count
 
a for loop for all vertices
   use getTCoords
      if TCoord is water.jpg, *somehow* set it to emt_transparent_add_color
I hope I'm on the right track with setting the water vertices to be a bit transparent. Still not sure how I'd handle walking through it.

I assume similar would be used on the paths, but I can't even think of how it was done.

Again, any help would seriously be appreciated.
I realize Irrlicht is a great engine with many capabilities, I'm just not aware of all the things I can do with it. So pointing me in the right direction to learning how to do these things would be amazing.
Thanks!

Edit:
I used the log and found this in the output:

Code: Select all

I/Irrlicht(10400): Loaded texture: media/Link/YoungLink_grp.png
I/Irrlicht(10400): Reading material file: KokiriForest.mtl
I/Irrlicht(10400): Loaded group start: training
I/Irrlicht(10400): Loaded material start: grass
I/Irrlicht(10400): Loaded group start: training
I/Irrlicht(10400): Loaded material start: wall
I/Irrlicht(10400): Loaded group start: training
I/Irrlicht(10400): Loaded material start: trunks
I/Irrlicht(10400): Loaded group start: training
I/Irrlicht(10400): Loaded material start: trees
I/Irrlicht(10400): Loaded group start: training
I/Irrlicht(10400): Loaded material start: cut
I/Irrlicht(10400): Loaded group start: training
I/Irrlicht(10400): Loaded material start: cut
I/Irrlicht(10400): Loaded group start: training
I/Irrlicht(10400): Loaded material start: house
I/Irrlicht(10400): Loaded group start: training
I/Irrlicht(10400): Loaded material start: cut
I/Irrlicht(10400): Loaded group start: training
I/Irrlicht(10400): Loaded material start: bush
I/Irrlicht(10400): Loaded group start: training
I/Irrlicht(10400): Loaded material start: bushside
I/Irrlicht(10400): Loaded group start: training
I/Irrlicht(10400): Loaded material start: path
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: wall
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: walls
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: ledge
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: grass
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: bark
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: NemuMat27
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: bushside
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: bush
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: exit
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: house
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: exit
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: steptop
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: step
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: cut
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: tower
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: house
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: enter
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: curtain
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: cut
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: house
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: vine
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: edge
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: porch
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: rail
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: ladder
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: ladder
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: shroom
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: enter
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: mido
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: cut
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: house
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: enter
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: cut
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: enter
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: saria
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: cut
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: house
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: enter
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: cut
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: cut
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: enter
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: cut
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: shop
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: awning
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: trunks
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: trees
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: fence
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: fencew
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: bridge
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: bridge
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: leaf
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: fence
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: leaf
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: fence
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: leaf
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: vineh
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: patch
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: water
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: water
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: pathe
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: path
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: patht
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: patht
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: doodd
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: doodh
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: doods
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: fade
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: fade
I/Irrlicht(10400): Loaded group start: main
I/Irrlicht(10400): Loaded material start: vinew
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: bark
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: grass
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: wall
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: vineh
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: wall
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: bark
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: NemuMat27
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: bark
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: trunks
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: trees
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: bark
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: pathe
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: path
I/Irrlicht(10400): Loaded group start: dekutree
I/Irrlicht(10400): Loaded material start: fade
I/Irrlicht(10400): Loaded mesh: media/Locations/KokiriForest/Kokiri Forest.obj
It seems the mtl file is loading properly (it is named correctly as well) but no texture is being displayed on Android. Only young link's textures.
Image
Last edited by LunaRebirth on Fri May 01, 2015 4:17 am, edited 2 times in total.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Mapping Objects

Post by mongoose7 »

Look in the MTL file and see if there are any file names. I wonder if textures were exported. Note that Link's texture was loaded before the MTL file was read, so I guess he was in a different file? Probably not an OBJ file. If you want TRANSPARENT_ADD_COLOR (and I have no idea what this will do for you) you can set it automatically by putting the texture in the MTL file as map_d or map_opacity.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Mapping Objects

Post by hendu »

Meshbuffer pseudocode:

Code: Select all

mesh = load(my.obj)
for each meshbuffer in mesh
   if texture[0] is water.jpg
      meshbuffer.material.materialtype = emt_transparent_alpha_channel
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Mapping Objects

Post by LunaRebirth »

Great!
I tried this code, and it's crashing my program.

Code: Select all

void changeObject(SMesh* &obj) {
    for (int x=0; x<obj->getMeshBufferCount(); x++) {
        IMeshBuffer* mb = obj->getMeshBuffer(x);
        ITexture* myT = driver->getTexture("media/Locations/KokiriForest/water.png");
        if (mb->getMaterial().getTexture(0)==myT) {
            obj->getMeshBuffer(x)->getMaterial().MaterialType=EMT_TRANSPARENT_ALPHA_CHANNEL;
        }
    }
}
 
int main() {
   changeObject((SMesh*&)objects[0]); //I believe the crash is because of this..
      //I think that because objects[0] is an IAnimatedMeshSceneNode, not an SMesh.
}
Debug output:

Code: Select all

irr::scene::ISceneNode::serializeAttributes(irr::io::IAttributes*, irr::io::SAttributeReadWriteOptions*) const () (??:??)
irr::scene::CAnimatedMeshSceneNode::serializeAttributes(irr::io::IAttributes*, irr::io::SAttributeReadWriteOptions*) const () (??:??)
Thanks for your help!
I will continue trying to get this crash fixed.
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Mapping Objects

Post by LunaRebirth »

Okay I fixed the crash by doing

Code: Select all

void changeObject(IAnimatedMeshSceneNode* &obj) {
    for (int x=0; x<obj->getMesh()->getMeshBufferCount(); x++) {
        IMeshBuffer* mb = obj->getMesh()->getMeshBuffer(x);
        ITexture* myT = driver->getTexture("media/Locations/KokiriForest/water.png");
        if (mb->getMaterial().getTexture(0)==myT) {
            obj->getMesh()->getMeshBuffer(x)->getMaterial().MaterialType=EMT_TRANSPARENT_ALPHA_CHANNEL;
        }
    }
}
However, the water isn't changing. It still looks a normal solid water.png texture.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Mapping Objects

Post by mongoose7 »

Are you sure it is texture 0? Maybe try texture 1 if there is one. Also, remove the getTexture from the loop and put it before.
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Mapping Objects

Post by LunaRebirth »

Thanks, I didn't think about the Texture being in the loop.
Unfortunately, changing those didn't help. Here's what I tried:

Code: Select all

void changeObject(IAnimatedMeshSceneNode* &obj) {
    ITexture* myT = driver->getTexture("media/Locations/KokiriForest/water.png");
    for (int x=0; x<obj->getMesh()->getMeshBufferCount(); x++) {
        IMeshBuffer* mb = obj->getMesh()->getMeshBuffer(x);
        for (int y=0; y<100; y++) {
            if (mb->getMaterial().getTexture(y)==myT) {
                obj->getMesh()->getMeshBuffer(x)->getMaterial().MaterialType=EMT_TRANSPARENT_ALPHA_CHANNEL;
                printf("%i,%i\n",x,y);
            }
        }
    }
}
The output is:
43,0

Still no change in the water.
(I realize I shouldn't check for 100 textures. It was only for testing, however.)
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Mapping Objects

Post by mongoose7 »

You've switched to TRANSPARENT_ALPHA_CHANNEL! Well, at the least, you will need a texture with an alpha channel. It probably goes in slot 1 so you will need a texture in slot 0.

I think all that you need is to set the material type to TRANSPARENT_VERTEX_ALPHA and set the alpha in the material to a value between 0 and 255:

mb->getMaterial().DiffuseColor.setAlpha(alpha);
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Mapping Objects

Post by LunaRebirth »

mongoose7 wrote:You've switched to TRANSPARENT_ALPHA_CHANNEL! Well, at the least, you will need a texture with an alpha channel. It probably goes in slot 1 so you will need a texture in slot 0.

I think all that you need is to set the material type to TRANSPARENT_VERTEX_ALPHA and set the alpha in the material to a value between 0 and 255:

mb->getMaterial().DiffuseColor.setAlpha(alpha);
That did not work
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Mapping Objects

Post by hendu »

Note that irr by default has materials in the node, and your latest function modifies the mesh's materials instead.

Try changing
obj->getMesh()->getMeshBuffer(x)->getMaterial()
to
obj->getMaterial(x)
Post Reply