Object materials won't show up in final render



  • 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);
    }
    


  • 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



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

    BaseDocument* doc = op->GetDocument();
    

    Thank you.



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

    Cheers,
    Maxime.


Log in to reply