Jump to content

[SOLVED] From parent node (NodeDummy) - set material of a child of type ObjectMeshStatic.


photo

Recommended Posts

Hello Guys,

can someone please help me on how to do it?

In my project I have a Node (NodeDummy) with a C++ component attached.

In this script I want to set material of the child of this node (ObjectMeshStatic "LED" which has a mesh "box_1.mesh").

This is the only child of the node.

image.png.c0941b141dfc1ecf2b8332b82154bfd8.png



// here I can see that the child exists, and it of a type ObjectMeshStatic
Log::message("                        ");
Log::message("Sensor Beam Children                  %d               .", node->getNumChildren());	//"1"
Log::message("Child 0 Name              %s             .", node->getChild(0)->getName());			//"LED"
Log::message("Child 0 Type              %d             .", (node->getChild(0)->getType()));			// " 36"
Log::message("Child 0 Type              %s            .", (node->getChild(0)->getTypeName()));		// "ObjectMeshStatic"


//But the code below doesnt work
node->getChild(0)->setMaterialPath("vr_sample/props/Conveyors/materials/sensor-beam.mat", "*");

 

image.thumb.png.aba0c587ec0bba9836ff9d461b2029fb.png

 

My question is why setMaterialPath can't be used here but can be used for meshes generated with code like below?


	if (obj)
	{
		Math::Vec3 p = intersection->getPoint();

		mesh = ObjectMeshDynamic::create();

		mesh->setWorldTransform(translate(Vec3(0.0f, 0.0f, 0.3f)));

		mesh->addTriangleQuads(1);

		mesh->addVertex(vec3(0.0f, -1.0f, 0.0f));
		mesh->addTexCoord(vec4(0, 0, 0, 0));

		mesh->addVertex(vec3(0.03f, -1.0f, 0.0f));
		mesh->addTexCoord(vec4(1, 0, 0, 0));

		mesh->addVertex(vec3(0.03f, 1.0f, 0.0f));
		mesh->addTexCoord(vec4(1, 1, 0, 0));

		mesh->addVertex(vec3(0.0f, 1.0f, 0.0f));
		mesh->addTexCoord(vec4(0, 1, 0, 0));

		mesh->updateTangents();
		mesh->updateBounds();


// Set Material..
		mesh->setMaterialPath("Materials/plane_0_mesh_base_0.mat", "*");


	}

 

Link to comment
  • silent changed the title to [SOLVED] From parent node (NodeDummy) - set material of a child of type ObjectMeshStatic.
×
×
  • Create New...