Jump to content

[SOLVED] How to set opacity to Mesh


photo

Recommended Posts

Hi there,

I am working on Mesh object. I am creating mesh at runtime and trying to set opacity to it. I have tried 

setMaterialParameter("albedo_color", ...); but it does not work.

 

Kindly guide.

 

Thank  you.

 

 

Link to comment

Hi Debashis,

Please correct me if I wrong,  you want to get semi-transparent object? If so, I would recommend to use setTransparent() method for that.

Otherwise, could you please give us more details about your use-case (some screenshots or video of what you are trying to achieve)?

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
13 hours ago, silent said:

Hi Debashis,

Please correct me if I wrong,  you want to get semi-transparent object? If so, I would recommend to use setTransparent() method for that.

Otherwise, could you please give us more details about your use-case (some screenshots or video of what you are trying to achieve)?

Thanks!

Hello Silent,

Yes! I want to create a semi transparent box.

I have written following function that I am calling from AppWorldLogic::init()

int AppWorldLogic::AddMeshToScene3()
{
	// creating a box (ObjectMeshDynamic node)
	MeshPtr mesh = Mesh::create();
	mesh->addBoxSurface("box_surface", Math::vec3(1.5f, 1.5f, 1.5f));
	ObjectMeshDynamicPtr my_mesh = ObjectMeshDynamic::create(mesh);
	my_mesh->release();
	editor_->addNode(my_mesh->getNode(), 1);
	mesh->clear();
	
	// getting the interface to material libraries
	Materials *materials = Materials::get();
	
	// creating a new material library
	materials->create("my_material_lib");

	// creating a new child material of the mesh_base and putting it to the created library
	materials->inheritMaterial("mesh_base", "my_material_lib", "my_mesh_base0");
	
	// getting a pointer to the new material named "my_mesh_base0"
	MaterialPtr  my_mesh_base = materials->findMaterial("my_mesh_base0");
	
	// setting the albedo color of the material to red
	my_mesh_base->setParameter(Material::PARAMETER_COLOR, Math::vec4(255, 0, 0, 255));
	my_mesh_base->setTransparent(Material::TRANSPARENT_BLEND);

	// assigning a "my_mesh_base0" material to the surface 0 of the my_mesh ObjectMeshDynamic node
	my_mesh->setMaterial("my_mesh_base0", 0);
	
	// assigning a "my_mesh_base0" material to all surfaces of the my_mesh ObjectMeshDynamic node
	my_mesh->setMaterial("my_mesh_base0", "*");
	return  1;
}

I have atached screenshot of how it shows. Also I tried these values too: 

        TRANSPARENT_NONE,
        TRANSPARENT_ALPHA_TEST,
        TRANSPARENT_WATER,


for 

my_mesh_base->setTransparent(...)

But it does not show properly

Kindly guide!

Thank you

TRANSPARENT_BLEND.jpg

Link to comment

It worked as expected after I did following:

int AppWorldLogic::AddMeshToScene3()
{
	// creating a box (ObjectMeshDynamic node)
	MeshPtr mesh = Mesh::create();
	mesh->addBoxSurface("box_surface", Math::vec3(1.5f, 1.5f, 1.5f));
	ObjectMeshDynamicPtr my_mesh = ObjectMeshDynamic::create(mesh);
	my_mesh->release();
	editor_->addNode(my_mesh->getNode(), 1);
	mesh->clear();

	// getting the interface to material libraries
	Materials *materials = Materials::get();
	// creating a new material library
	materials->create("my_material_lib");
	// creating a new child material of the mesh_base and putting it to the created library
	materials->inheritMaterial("mesh_base", "my_material_lib", "my_mesh_base0");
	// getting a pointer to the new material named "my_mesh_base0"
	MaterialPtr  my_mesh_base = materials->findMaterial("my_mesh_base0");
	my_mesh_base->setTransparent(2);
	my_mesh_base->setBlendFunc(Gui::BLEND_SRC_ALPHA, Gui::BLEND_ONE_MINUS_SRC_ALPHA);
	my_mesh_base->setParameter(Material::PARAMETER_COLOR, Math::vec4(1.0f, 0.0f, 0.0f , 0.5f));
	// assigning a "my_mesh_base0" material to the surface 0 of the my_mesh ObjectMeshDynamic node
	my_mesh->setMaterial("my_mesh_base0", 0);
	return  1;
}

Thank you so much for guidance.

Final.png

Edited by debashis.bhandari
Added screenshot
Link to comment
  • silent changed the title to [SOLVED] How to set opacity to Mesh
×
×
  • Create New...