Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Register
    • Login

    Object materials won't show up in final render

    Cinema 4D SDK
    c++ sdk
    3
    4
    647
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mfersaouiM
      mfersaoui
      last edited by mfersaoui

      Hello,
      Object materials won't show up in final render even though it shows up in the render view. bellow is my code:

      BaseObject* MyObject::GetVirtualObjects(BaseObject* op, HierarchyHelp* hh)
      {
      	if (!op)
      		return BaseObject::Alloc(Onull);
      
      	Bool bIsDirty = op->CheckCache(hh) || op->IsDirty(DIRTYFLAGS_DATA);
      
      	if (!bIsDirty)
      		return op->GetCache(hh);
      
      	BaseObject* container = BaseObject::Alloc(Onull);
      	if (!container)
      		return BaseObject::Alloc(Onull);
      
      	BaseObject* cube = BaseObject::Alloc(Ocube);
      	if (!cube)
      		return container;
      
      	// create the texture tag
      	TextureTag* const textureTag = static_cast<TextureTag*>(cube->MakeTag(Ttexture));
      	if (textureTag == nullptr)
      		return container;
      
      	// apply material
      	BaseDocument* doc = GetActiveDocument();
      	BaseMaterial* material = doc->SearchMaterial("mat_name");
      
      	if (!material)
      		return container;
      
      	textureTag->SetMaterial(material);
      
      	cube->InsertUnder(container);
      	container->Message(MSG_UPDATE);
      
      	return domeContainer;
      }
      
      Bool MyObject::Message(GeListNode* node, Int32 type, void* data)
      {
      	switch (type)
      	{
      	case (MSG_MENUPREPARE):
      	{
      		Material* const material = Material::Alloc();
      		if (material == nullptr)
      			return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
      
      		const Vector  color(0.85, 0.85, 0.85);
      
      		material->SetParameter(DescID(MATERIAL_COLOR_COLOR), color, DESCFLAGS_SET_0);
      		material->SetParameter(DescID(MATERIAL_USE_REFLECTION), Bool(false), DESCFLAGS_SET_0);
      
      		material->SetName("mat_name");
      
      		BaseDocument* doc = GetActiveDocument();
      		doc->InsertMaterial(material);
      		break;
      	}
      
      	}
      	return SUPER::Message(node, type, data);
      }
      
      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by

        Hi,

        you use GetActiveDocument() in a NodeData environment. You cannot do this, since nodes are also executed when their document is not the active document (while rendering for example - documents get cloned for rendering).

        Cheers
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        mfersaouiM 1 Reply Last reply Reply Quote 3
        • mfersaouiM
          mfersaoui @ferdinand
          last edited by mfersaoui

          @zipit
          Hi,
          I used the following and it is working.

          BaseDocument* doc = op->GetDocument();
          

          Thank you.

          1 Reply Last reply Reply Quote 0
          • M
            m_adam
            last edited by

            For more information about it, please read the BaseDocument Manual.

            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            1 Reply Last reply Reply Quote 0
            • First post
              Last post