Vray mats to C4D maps (Simple script maybe)


#1

I’m taking quick job where another artist packed in due to complications.
It’s a VRay scene that would render as well (and much faster in C4D)

The scene however has 200-300 materials that need converting from VRay mats to C4D, though they contain no special information other than diffuse texture channels.

Is there anybody out there who could write a script to bring those materials back into Cinema materials?


#2

i wrote you a pm with 2 suggestions…
cheers
stefan


#3

Thanks.

Just wanted to point out that my observation about speed differences is due to ‘not’ needing a GI solution for the particular shot. Where AR would be faster with a simple sun/sky setup.


#4

no prob, as i said Lennart might be your guy then… he made great scripts also for me

cheers
stefan


#5

You iterate the VrayMats , making new C4d mats
then transfer the shader settings.
Iterate the Object manager tags replacing
the tag material from VrayMat to the new corresponding C4D mat.

Cheers
Lennart


#6

Stuart, did you get anywhere?
See the framework how it could be done.
Note, only checked with R11/Vray1.1 as
I don’t have Vray1.2 installed in R12.

Cheers
Lennart

Copy -all- into script manager and keep your fingers crossed :slight_smile:


// VrayMat_To_C4DMat tcastudios.com©2011
//
// In Material Manager, select all VrayMaterial to be replaced.
// Creates new C4D materials based on:
// Vray Materials DiffuseLayer 1 Diffuse Color -> C4D Color Channel
// Vray DiffuseLayer 1 Diffuse Transparency -> C4D Transparency Channel
// Vray Material Weight -> C4D Alpha Channel
// Vray Specular1 -> C4D Specular and Specular Color Channel
//
// Then replaces found VrayMat Tags in Object Manager
//
// NOTE! Only tested in R11 and VrayForC4d v1.1.
// Check UNDO and Vray enumerates for R12+/VrayForC4D 1.2, see comments in code


TagVrayToC4D(obj,vmat,cmat) // Search and replace TextureTag materials(Vray->C4D) for object
 {
  var tag = obj->GetFirstTag();
  if(!tag) return NULL;
  var doc = tag->GetObject()->GetDocument();
  while(tag)
   {
    if(tag && tag->GetType() == Ttexture && tag#TEXTURETAG_MATERIAL == vmat)
      {
       doc->AddUndo(UNDO_TAG_DATA,tag); // R11+
       //doc->AddUndo(UNDOTYPE_CHANGE,tag); // R12+ <----------
       tag#TEXTURETAG_MATERIAL = cmat;
       EventAdd();
      }
    tag = tag->GetNext();
   }
  return NULL;
 }

VrayToC4D(obj,vmat,cmat) // Iterate the scene
{
 while(obj)
  {
   TagVrayToC4D(obj,vmat,cmat); // Do the Tag thing
   VrayToC4D(obj->GetDown(),vmat,cmat);
   obj = obj->GetNext();
  }
}

main(doc,op)
{ 
if(!material()) return;// No Mats selected

var i = 0;
doc->StartUndo();
while(material(i)) // While iterating materials
 {
  var cmat;
  var vmat = material(i);
     if(vmat->GetType() == 1020295) // If VrayMaterial
      {
       cmat = AllocMaterial(Mmaterial); // Make C4D Material
       doc->AddUndo(UNDO_NEW,cmat); // R11+
       //doc->AddUndo(UNDOTYPE_NEW,cmat); // R12+ <----------
       cmat->SetName(stradd(tostring(vmat->GetName()),"_c4d")); // Name it

     ///// Vray Material Weight to C4D Alpha //////////////////////////
     if(vmat#VRAYMATERIAL_USE_TRANSP)
      {
			if(vmat#VRAYMATERIAL_TRANSP_SHADER != NULL)// If shader
         {
          cmat#MATERIAL_USE_ALPHA    = TRUE;// Activate C4D Alpha Channel
          cmat#MATERIAL_ALPHA_INVERT = TRUE; // Alpha Invert
          cmat#MATERIAL_ALPHA_SHADER = vmat#VRAYMATERIAL_TRANSP_SHADER;// Vray Shader to C4D shader
          cmat#MATERIAL_ALPHA_SHADER->SetContainer(vmat#VRAYMATERIAL_TRANSP_SHADER->GetContainer());// Shader Settings
         }
      }
     ///////////////////////////////////////////////////////////////////

     ///// Vray Diffuse1 to C4D color //////////////////////////////////
     if(vmat#VRAYMATERIAL_USE_COLOR)
      {  
       cmat#MATERIAL_COLOR_COLOR = vmat#VRAYMATERIAL_COLOR_COLOR; 
       if(vmat#VRAYMATERIAL_COLOR_SHADER != NULL) // If shader
         {
          cmat#MATERIAL_COLOR_SHADER = vmat#VRAYMATERIAL_COLOR_SHADER; // Vray Shader to C4D shader
          cmat#MATERIAL_COLOR_SHADER->SetContainer(vmat#VRAYMATERIAL_COLOR_SHADER->GetContainer());// Shader Settings
         }

       // Vray Diffuse1 Transparency to C4D Transparency Channel
       if(vmat#VRAYMATERIAL_COLOR_TRANSP_MULT > 0) 
         {
          cmat#MATERIAL_USE_TRANSPARENCY        = TRUE; // Activate Transparency C4D Channel
          cmat#MATERIAL_TRANSPARENCY_COLOR      = vmat#VRAYMATERIAL_COLOR_TRANSP; // Vray Transp to C4D Transp
          cmat#MATERIAL_TRANSPARENCY_BRIGHTNESS = vmat#VRAYMATERIAL_COLOR_TRANSP_MULT;// Set level
           if(vmat#VRAYMATERIAL_COLOR_TRANSPSHADER != NULL) // If Shader
            {
             cmat#MATERIAL_TRANSPARENCY_SHADER = vmat#VRAYMATERIAL_COLOR_TRANSPSHADER;// Vray Shader to C4D shader
             cmat#MATERIAL_TRANSPARENCY_SHADER->SetContainer(vmat#VRAYMATERIAL_COLOR_TRANSPSHADER->GetContainer());// Shader Settings
            }
         }
       }
      //////////////////////////////////////////////////////////////////

      ///// Vray Reflection to C4D Reflection Channel //////////////////
      if(vmat#VRAYMATERIAL_USE_REFLECTION)
        {
         cmat#MATERIAL_USE_REFLECTION = TRUE;
         cmat#MATERIAL_REFLECTION_COLOR = vmat#VRAYMATERIAL_REFLECTION_COLOR;
          if(vmat#VRAYMATERIAL_REFLECTION_SHADER != NULL)
           {
            cmat#MATERIAL_REFLECTION_SHADER        = vmat#VRAYMATERIAL_REFLECTION_SHADER;
            cmat#MATERIAL_REFLECTION_BRIGHTNESS    = vmat#VRAYMATERIAL_REFLECTION_COLOR_MULT;
            cmat#MATERIAL_REFLECTION_TEXTUREMIXING = 0; // "Normal"
            cmat#MATERIAL_REFLECTION_TEXTURESTRENGTH = vmat#VRAYMATERIAL_REFLECTION_TEXTUREMULT;
            cmat#MATERIAL_REFLECTION_SHADER->SetContainer(vmat#VRAYMATERIAL_REFLECTION_SHADER->GetContainer());
           }
        }
       //////////////////////////////////////////////////////////////////

      ///// Vray Specular Layer1 to C4D Specular and Spec Color Channel //////////////////
      if(vmat#VRAYMATERIAL_USE_SPECULAR1)
       {
        cmat#MATERIAL_USE_SPECULAR        = TRUE;
        cmat#MATERIAL_SPECULAR_WIDTH      = 1.0 - (vmat#VRAYMATERIAL_SPECULAR1_HIGHLIGHTGLOSS);
        cmat#MATERIAL_USE_SPECULARCOLOR   = TRUE;
        cmat#MATERIAL_SPECULAR_COLOR      = vmat#VRAYMATERIAL_SPECULAR1_COLOR;
        cmat#MATERIAL_SPECULAR_BRIGHTNESS = vmat#VRAYMATERIAL_SPECULAR1_COLOR_MULT;
         if(vmat#VRAYMATERIAL_SPECULAR1_SHADER)
          {
           cmat#MATERIAL_SPECULAR_SHADER          = vmat#VRAYMATERIAL_SPECULAR1_SHADER;
           cmat#MATERIAL_SPECULAR_TEXTUREMIXING   = 0;
           cmat#MATERIAL_SPECULAR_TEXTURESTRENGTH = vmat#VRAYMATERIAL_SPECULAR1_TEXTUREMULT;
           cmat#MATERIAL_SPECULAR_SHADER->SetContainer(vmat#VRAYMATERIAL_SPECULAR1_SHADER->GetContainer());
          }

       }
      ///////////////////////////////////////////////////////////////////////////////////

       cmat->InsertBefore(material(0));            // Insert it
       VrayToC4D(doc->GetFirstObject(),vmat,cmat); // Find and replace it in Object Manager
      }
  i = i+1; // Next Material
 }

doc->EndUndo();
}


#7

I wasn’t sure what you meant by iterating the mats, sorry.

I really appreciate the effort, the file is R11 file and if I can install an earlier copy of VRay, this will work.

In R12 it gives me all the relevant C4D materials, though texture channel doesn’t convert.


#8

I see, something might have changed regarding containers in R12 then
(that’s how the textures/shaders are read and set in the script).

Just saw that the Vray Refraction channel is a better choice to set
the C4D Transparency channel.
Just re route the corresponding ID’s (From Diffuse Color Transparency
to Refraction ID’s)

Cheers
Lennart


#9

i will try this out 2morrow …i could have used this in two projects already and safe some time

thx


#10

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.