[fixed] 'ReadOnlyMaterials' bug in CAnimatedMeshSceneNode

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
buffer
Posts: 4
Joined: Fri Jun 19, 2009 10:01 pm

[fixed] 'ReadOnlyMaterials' bug in CAnimatedMeshSceneNode

Post by buffer »

Irrlicht 1.5 issue

'ReadOnlyMaterials' is not handled properly in CAnimatedMeshSceneNode::render()

Please note that when CAnimatedMeshSceneNode::render() is called and the 'ReadOnlyMaterials' flag is true, the node's material is always used and not the material of the meshbuffer.
See the implementation of CMeshSceneNode (line 158) where this is correctly handled by:

const video::SMaterial& material = ReadOnlyMaterials ? mb->getMaterial() : Materials;
buffer
Posts: 4
Joined: Fri Jun 19, 2009 10:01 pm

Post by buffer »

May I suggest the following:

Code: Select all

	// render original meshes
	if ( renderMeshes )
	{
		for (u32 i=0; i<m->getMeshBufferCount(); ++i)
		{
			scene::IMeshBuffer* mb = m->getMeshBuffer(i);
			const video::SMaterial& material = ReadOnlyMaterials ? mb->getMaterial() : Materials[i];

			video::IMaterialRenderer* rnd = driver->getMaterialRenderer(material.MaterialType);
			bool transparent = (rnd && rnd->isTransparent());

			// only render transparent buffer if this is the transparent render pass
			// and solid only in solid pass
			if (transparent == isTransparentPass)
			{
				if (RenderFromIdentity)
					driver->setTransform(video::ETS_WORLD, core::matrix4() );
				else if (Mesh->getMeshType() == EAMT_SKINNED)
					driver->setTransform(video::ETS_WORLD, AbsoluteTransformation * ((SSkinMeshBuffer*)mb)->Transformation);

				driver->setMaterial(material);
				driver->drawMeshBuffer(mb);
			}
		}
	}
Instead of:

Code: Select all

	// render original meshes
	if ( renderMeshes )
	{
		for (u32 i=0; i<m->getMeshBufferCount(); ++i)
		{
			video::IMaterialRenderer* rnd = driver->getMaterialRenderer(Materials[i].MaterialType);
			bool transparent = (rnd && rnd->isTransparent());

			// only render transparent buffer if this is the transparent render pass
			// and solid only in solid pass
			if (transparent == isTransparentPass)
			{
				scene::IMeshBuffer* mb = m->getMeshBuffer(i);

				if (RenderFromIdentity)
					driver->setTransform(video::ETS_WORLD, core::matrix4() );
				else if (Mesh->getMeshType() == EAMT_SKINNED)
					driver->setTransform(video::ETS_WORLD, AbsoluteTransformation * ((SSkinMeshBuffer*)mb)->Transformation);

				driver->setMaterial(Materials[i]);
				driver->drawMeshBuffer(mb);
			}
		}
	}
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

This is now fixed, thanks :)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Post Reply