Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Set Material Default Projection

 Post Reply Post Reply
Author
Message
Aaron94 View Drop Down
Member
Member


Joined: 2015 Dec 15
Online Status: Offline
Posts: 78
Post Options Post Options   Quote Aaron94 Quote  Post ReplyReply Direct Link To This Post Topic: Set Material Default Projection
    Posted: 2017 Jul 29 at 7:50am

User Information:

Cinema 4D Version:   R17 
Platform:   Windows  ;   
Language(s):     C++  ;   

---------

Hello,

There are custom material plugins. And when they are assigned to objects their default projection is Spherical. I want default projection to be UVW (as for std Cinema materials).
Same history as http://www.plugincafe.com/forum/forum_posts.asp?TID=10594&PID=41173#41173

// note: nullptr checks omitted
Bool MyMaterial::Message(GeListNode* node, Int32 type, void* pData)
{
  if(type == MSG_MATERIALDRAGANDDROP)
  {
    BaseMaterial* mat = static_cast<BaseMaterial*>(node);
    MaterialDragAndDrop* mdd = static_cast<MaterialDragAndDrop*>(pData);
    mdd->result = mdd->op->MakeTag(Ttexture);
    mdd->result->SetParameter(TEXTURETAG_MATERIAL, mat, DESCFLAGS_SET_0);
    mdd->result->SetParameter(TEXTURETAG_PROJECTION, TEXTURETAG_PROJECTION_UVW, DESCFLAGS_SET_0);
    return true;
  }
  return MaterialData::Message(node, type, pData);
}

But that solution works only for simple cases. 

Consider a case. E.g. when we have a selection of polygons and try to assign own custom material with suggested method then SelectionTag is not created together with the TextureTag that we create on our own. Why? How to fix that?
However when we don't write the pointer to mdd->result then we can't change default projection of texture but anything else works fine and Selection Tag too.
Back to Top
Aaron94 View Drop Down
Member
Member


Joined: 2015 Dec 15
Online Status: Offline
Posts: 78
Post Options Post Options   Quote Aaron94 Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jul 29 at 9:42am
And here is my workaround:

In MaterialData message I remember who is assigned where:
case MSG_MATERIALDRAGANDDROP:
{
MaterialDragAndDrop * mdd = (MaterialDragAndDrop *)(msgdat);
if (mdd != 0 && mat != 0)
{
BaseObject * obj = mdd->op;
if (obj != 0)
{
MY_COMMON_DATA * rendata = MyCommonDataInstance();

int next_id = rendata->mat_dnd_num;
rendata->mat_dnd.SetLink(next_id + 0, mat);
rendata->mat_dnd.SetLink(next_id + 1, obj);
rendata->mat_dnd_num += 2;
}
}

break;
}

And in CoreMessage I intercept "change" message. It occurs for any change in scene also for previous one but with assigned and allocated Tags!
void ChangeDefaultProjection(BaseDocument * doc)
{
if (!doc) return;

MY_COMMON_DATA * rendata = MyCommonDataInstance();
if (rendata->mat_dnd_num <= 0) return;

for (int i = 0; i < rendata->mat_dnd_num; i += 2)
{
BaseMaterial * mat = (BaseMaterial *)rendata->mat_dnd.GetLink(i + 0, doc);
BaseObject * obj = (BaseObject *)rendata->mat_dnd.GetLink(i + 1, doc);

if (obj != 0 && mat != 0)
{
if (obj->IsInstanceOf(Obase) && mat->IsInstanceOf(Mbase))
{
BaseTag * tsearch = 0;
for (BaseTag * tag = obj->GetFirstTag(); tag; tag = tag->GetNext())
{
// search the last tag with this material
if (tag->IsInstanceOf(Ttexture)) {
BaseMaterial * mi = (BaseMaterial *)getParameterLink(*tag, TEXTURETAG_MATERIAL, 0);
if (mi == mat)
tsearch = tag;
}
}

if (tsearch != 0)
tsearch->SetParameter(TEXTURETAG_PROJECTION, TEXTURETAG_PROJECTION_UVW, DESCFLAGS_SET_0);
}
}
}

rendata->mat_dnd_num = 0; // flush the queue
}

Bool MyTimer::CoreMessage(Int32 id, const BaseContainer &bc)
{

BaseDocument * doc = GetActiveDocument();
if (id == EVMSG_CHANGE)
{
ChangeDefaultProjection(doc);
}
}

It works for cases that I have tested. Pls, can anybody consult on any potential non-working scenarious in this method? However, I don't like such huge code constructions for so small needs.
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1497
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jul 31 at 5:36am
Hi,

in another support case (not in this forum) Sebastian came up with this solution:

When you handle the MSG_MATERIALDRAGANDDROP message you have to handle the full creation of the (optional) TextureTag yourself. That's the point of that message.

But if you just want that the UVW projection is set by default you could simply return the VOLUMEINFO_EVALUATEPROJECTION flag in GetRenderInfo(). In this case the tag's projection will be set to UVW.


Edited by Andreas Block - 2017 Jul 31 at 5:37am
Cheers,
Andreas
SDK Support Engineer
Back to Top
Aaron94 View Drop Down
Member
Member


Joined: 2015 Dec 15
Online Status: Offline
Posts: 78
Post Options Post Options   Quote Aaron94 Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jul 31 at 7:20am
Super! How could we guess about that :) I will give it a try
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1497
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jul 31 at 9:44am
Sometimes it's not about guessing, but just about asking Wink
Nah, you are right of course, our docs could well be more informative in this area.
Cheers,
Andreas
SDK Support Engineer
Back to Top
Aaron94 View Drop Down
Member
Member


Joined: 2015 Dec 15
Online Status: Offline
Posts: 78
Post Options Post Options   Quote Aaron94 Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Aug 01 at 12:36pm
Don't worry! You are informative! Sometimes people hang inside the code editor and make gazillion of tests before the idea of asking on forum comes to mind :))
Making tests in Cinema 4D environment are very cool because it launches in 1 second. No need for own standalone testing app.
I tested the trick. It works as you describe. Thanks!


Edited by Aaron94 - 2017 Aug 01 at 12:37pm
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.