Manual material creation

knight0fw0e

15-10-2006 12:36:21

Here's the code with wich I tried to create material manually.
ResourcePtr mat = MaterialManager.GetSingleton().Create("boundingBox", "General", true);
Material material = (Material)mat.Get();
material.GetTechnique(0).getPass(0).setDiffuse(Color.FromArgb(255, 255, 255));
material.GetTechnique(0).getPass(0).setDepthCheckEnabled(false);
material.GetTechnique(0).getPass(0).setDepthWriteEnabled(false);
material.GetTechnique(0).getPass(0).setLightingEnabled(false);

It compiles fine, but thorws an exception at runtime, 'cause it can't convert Resource to Material
Played with it a little, but still can't figure out how to create a material manually. Anyone can help? :(

dwrenne

15-10-2006 23:40:53

Hi,
I cannot answer this but while teh code is c#, The problem is a generic ogre one. maybe it would be better and get more visibility if it was on the generic ogre forum.

I want to do an animate sea (waves,etc) and maybe chnaging teh material, bump map or whatever would be the way.

D

knight0fw0e

16-10-2006 04:21:07

Hi dwrenne

I don't see how it fits the generic forum as it actually is a .NET problem. C++ ogre casts MaterialPtr to ResourcePtr just fine and .NET needs a little more than just 2 pointers to do the cast.

Anybody got a way around that?

Mwr

16-11-2006 17:00:44

I know this is quite a old post but thought I would answer it anyway.

With the classes from OgreDotNet you can't "cast" them to another one like you would in standard Ogre but must create a new object of the required type out of them. So to "convert" a ResourcePtr into a MaterialPtr you need to create that new MaterialPtr as follows:

ResourcePtr resPtr = MaterialManager.Instance.Create("BoundingBox",ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME );
MaterialPtr mat = new MaterialPtr( ResourcePtr.getCPtr(resPtr).Handle, false);

Then you can get the Material object from the MaterialPtr with the .Get() method.

iko79

23-11-2006 17:21:06

ResourcePtr resPtr = MaterialManager.Instance.Create("BoundingBox",ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME );
MaterialPtr mat = new MaterialPtr( ResourcePtr.getCPtr(resPtr).Handle, false);


this seems not to work on the current version of (mogre 0.1.8.1). neither has ResourcePtr a function called getCPtr nor is there a constructor for MaterialPtr that takes one argument. the MaterialPtr-contructor looks like this:
MaterialPtr( Material obj )
does anybody have an idea how this works on current versions?

Bekas

23-11-2006 18:46:40

@iko79, see this: http://www.ogre3d.org/phpBB2addons/viewtopic.php?p=16071#16071

iko79

24-11-2006 21:20:28

thanks for your reply!
sometimes it would be that easy... :? (m)ogre is just quite huge if you're new at it...