GetUVGen() for CHECKER_CLASS_ID

GetUVGen() for CHECKER_CLASS_ID

istan
Advisor Advisor
3,393 Views
14 Replies
Message 1 of 15

GetUVGen() for CHECKER_CLASS_ID

istan
Advisor
Advisor
auto tmap = (::Texmap *) ip->CreateInstance( TEXMAP_CLASS_ID, Class_ID( CHECKER_CLASS_ID, 0 ) );
BitmapTex * bmt = dynamic_cast<BitmapTex *> ( tmap );
StdUVGen * uv = bmt->GetUVGen();  // <<< FAILS!

I need access to "StdUVGen" but have no idea, how to get the pointer for a checker map.

All the samples just show it for a Bitmap map.

0 Likes
Accepted solutions (1)
3,394 Views
14 Replies
Replies (14)
Message 2 of 15

denisT.MaxDoctor
Advisor
Advisor

I confirm the failure.

 

Well... use the GetTheUVGen method of the Texmap class.

0 Likes
Message 3 of 15

denisT.MaxDoctor
Advisor
Advisor
auto tmap = (::Texmap *) ip->CreateInstance( TEXMAP_CLASS_ID, Class_ID( CHECKER_CLASS_ID, 0 ) );
BitmapTex * bmt = dynamic_cast<BitmapTex *> ( tmap );

Why do you cast Checker to BitmapTex? It doesn't seem right...
But as I mentioned earlier, BitmapTex::GetUVGen doesn't work for me.

 

0 Likes
Message 4 of 15

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

You can cast after that:

 

 

	if (auto tex = (Texmap*)max_ip()->CreateInstance(TEXMAP_CLASS_ID, Class_ID(CHECKER_CLASS_ID, 0)))
	{
		UVGen* uvgen = tex->GetTheUVGen();
		StdUVGen* uvstd = dynamic_cast<StdUVGen*>(uvgen);
...
		

 

 

 

 
Message 5 of 15

klvnk
Collaborator
Collaborator

you can't cast  a Checker map to a BitmapTex and expect it to work 🙂

 

do it this way...

 

 

 

 

 

Texmap *checkerMap = (Texmap *) CreateInstance(TEXMAP_CLASS_ID, Class_ID(CHECKER_CLASS_ID,0));
	StdUVGen *uvGen = (StdUVGen*)checkerMap->GetTheUVGen();

 

 

 

 

to be precise you should get a UVGen first, then check to see it thats a StdUVGen with UVGen::IsStdUVGen () then cast to StdUVGen, but hey ho 😄

0 Likes
Message 6 of 15

A012255
Enthusiast
Enthusiast

You are right. This is it:

StdUVGen * uv = (StdUVGen *) tmap->GetTheUVGen();
0 Likes
Message 7 of 15

A012255
Enthusiast
Enthusiast

Thanks to everybody!

0 Likes
Message 8 of 15

denisT.MaxDoctor
Advisor
Advisor

We worked in parallel... 😉

It seems like the direct GetUVGen method BitmapTex is not functioning properly.

0 Likes
Message 9 of 15

klvnk
Collaborator
Collaborator

I checked it in our exporter seems fine if it is an Actual BitmapTex 

0 Likes
Message 10 of 15

denisT.MaxDoctor
Advisor
Advisor

 

 

	if (auto tex = (Texmap*)max_ip()->CreateInstance(TEXMAP_CLASS_ID, Class_ID(CHECKER_CLASS_ID, 0)))
	{
		UVGen* uvgen = tex->GetTheUVGen();
		StdUVGen* uvstd = dynamic_cast<StdUVGen*>(uvgen);
...
		

 

My understanding is that GetTheUVGen returns StdUVGen in general... otherwise dynamic_cast should not have worked. Wouldn't it?

0 Likes
Message 11 of 15

istan
Advisor
Advisor
UVGen* uvg0 = tex->GetTheUVGen();
if (uvg0 && uvg0->IsStdUVGen()) {
	StdUVGen *uvg = (StdUVGen*)uvg0;
	uvg->InitSlotType(MAPSLOT_ENVIRON);
	uvg->SetCoordMapping(UVMAP_SPHERE_ENV);
}

Look at this code snippet from the examples. IMHO it's self explaining (if it's working).

For me all clarified. Thank you Denis & klvnk.

 

0 Likes
Message 12 of 15

denisT.MaxDoctor
Advisor
Advisor

Here is what the header says:

virtual BOOL IsStdUVGen() { return FALSE; } // class StdUVGen implements this to return TRUE

virtual (!)

 

The question is: if it's not StdUVGen, what is it? The documentation mentions either StdXYZGen or a custom 🤣

0 Likes
Message 13 of 15

klvnk
Collaborator
Collaborator

a custom implementation that derives from UVGen that returns false from IsStdUVGen

0 Likes
Message 14 of 15

denisT.MaxDoctor
Advisor
Advisor

@klvnk wrote:

a custom implementation that derives from UVGen that returns false from IsStdUVGen


Yes. What is about StdXYZGen?

 

0 Likes
Message 15 of 15

denisT.MaxDoctor
Advisor
Advisor

Haha! I found how easy to crash the MAX:

 

meditmaterials[1] = c = checker()
c.coords = StandardXYZGen()

 

... and try to open the Material Editor 😜

 

but for texmaps those need StdXYZGen it's safe:

 

meditmaterials[2] = d = dent()
d.coords = StandardUVGen()

 

PS. No! Both setting UV in place of XYZ or XYZ in place of UV will cause MAX to crash

This is interesting because I can't find a way to check what type of Map Coordinates a texture map class needs.

 

0 Likes