Texture reference shared to all MeshSceneNode

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
theandrew80
Posts: 11
Joined: Tue Mar 07, 2006 8:02 am
Location: Italy

Texture reference shared to all MeshSceneNode

Post by theandrew80 »

Hi!
I'm getting a reference to a texture of a mesh with this code:

Code: Select all

m_FullCardMeshNode.GetMaterial(0).Texture1
Then I replace the bitmap contained into that texture with another bitmap, but this change affects all the meshes on the screen. The other meshes are into the same SceneManager and derive from the same .x file, but are separated nodes.

There is a way to change only one mesh texture?

Thanks for your help!
Martins

Post by Martins »

Most likely all your meshes reference the same texture instance. And that is why changing this texture affects all meshes.

You could create separate texture for each node:

Code: Select all

ITexture texture = AddTexture(new Dimension2D(64, 64), String.Empy);
sceneNode.SetMaterialTexture(0, texture);
and then your method might work as you expect.
Braneloc
Posts: 68
Joined: Fri Jan 20, 2006 5:12 am
Location: England
Contact:

Post by Braneloc »

Unlikely :(

Irrlicht uses a loader system that ensures only one copy of a texture exists. Not sure if it is implemented in Irrlicht.Net, but it MIGHT be possible to feed in a brand new texture to the model to point, it certainly can't be done by editing.
Sometimes you've just gotta say, the laws of time and space, who gives a smeg ?!

Irrlicht.Net Information - http://www.irrforge.org/index.php/.net
Irrlicht# (aka the C# port) - http://irrlichtsharp.sourceforge.net
theandrew80
Posts: 11
Joined: Tue Mar 07, 2006 8:02 am
Location: Italy

Post by theandrew80 »

I've just tried the Martin's solution, and it's working perfectly.
Thanks Martins... for the second time! :wink:
theandrew80
Posts: 11
Joined: Tue Mar 07, 2006 8:02 am
Location: Italy

Post by theandrew80 »

Mmmmh.... SetMaterialTexture adds my texture to all faces of my mesh, but i nedd to apply only on front face... That methods take a parameter, textureLayer, that i set to 0. What is exactly that parameter?
theandrew80
Posts: 11
Joined: Tue Mar 07, 2006 8:02 am
Location: Italy

Post by theandrew80 »

I read the documentation of the SetMaterialTexture method:

Sets the texture of the specified layer in all materials of this scene node to the new texture.

The problem is that I want to apply the texture only to one material of the mesh. Do you know if a method exists? I could create the method modifying the irrlicht source...
theandrew80
Posts: 11
Joined: Tue Mar 07, 2006 8:02 am
Location: Italy

Post by theandrew80 »

I've created a new method on original engine and I've wrapped it on Irrlicht.NET: and overload of existing SetMaterialTexture, with an additional parameter, "material", that specifies the index of the material the texture refers.
It's strange that that overload doesn't exists in the official release, it seems to be useful...
Martins

Post by Martins »

Other way would be to do something like this:

Code: Select all

Material m = sceneNode.GetMaterial(0);
m.Texture1 = texture;
sceneNode.SetMaterial(0, m)
theandrew80
Posts: 11
Joined: Tue Mar 07, 2006 8:02 am
Location: Italy

Post by theandrew80 »

Yes, I've tried your solution and it works too.

Thanks!
Locked