Jump to content

[SOLVED] How to Render Mesh Dynamic?


photo

Recommended Posts

Hello There,

I am trying following code to use and render MeshDynamic. But I am not able to render it. What could be the problem?

//There are my declarations

MeshDynamicPtr m_objMeshDynamic;
MeshDynamic::Attribute m_objMeshDynamicAttributes[1];
MaterialPtr m_objMaterial;

Here is an init method

m_objMeshDynamicAttributes[0].offset = 0;
m_objMeshDynamicAttributes[0].type = MeshDynamic::TYPE_FLOAT;
m_objMeshDynamicAttributes[0].size = 3;

m_objMeshDynamic = MeshDynamic::create(MeshDynamic::DYNAMIC_ALL);

m_objMeshDynamic->setVertexFormat(m_objMeshDynamicAttributes, 1);
m_objMeshDynamic->allocateVertex(3);
m_objMeshDynamic->allocateIndices(3);

m_objMeshDynamic->clearVertex();
m_objMeshDynamic->clearIndices();

//Vertex 1:
m_objMeshDynamic->addVertexFloat4(0, 10, 10, 10);

//Vertex 2: 
m_objMeshDynamic->addVertexFloat4(0, -10, 10, 10);

//Vertex 3: 
m_objMeshDynamic->addVertexFloat4(0, 10, 10, -10);

m_objMeshDynamic->addTriangles(1);

//front
m_objMeshDynamic->addIndex(0);
m_objMeshDynamic->addIndex(2);
m_objMeshDynamic->addIndex(1);

m_objMeshDynamic->flushVertex();
m_objMeshDynamic->flushIndices();

m_objMaterial = Materials::findBaseMaterial("mesh_base");

In the render method

    RenderState::saveState();
	RenderState::clearStates();
	RenderState::flushStates();

	RenderState::setMaterial(m_objMaterial);
	RenderState::setPolygonCull(RenderState::CULL_NONE);

	m_objMeshDynamic->bind();

	m_objMeshDynamic->render(MeshDynamic::MODE_TRIANGLES, MeshDynamic::FLUSH_ALL);
	
	m_objMeshDynamic->unbind();

	RenderState::restoreState();

Nothing is visible. Am I doing something wrong. Or I mapped wrong perception between MeshDynamic and DX11 calls that might be called behind?

Please advise.

Rohit

Edited by rohit.gonsalves
Changed the topic to solved.
Link to comment

Hello Rohit,

1. Maybe you should check if you are using addTriangles correctly. After reading the documentation of the other add* methods I think you do not need to use this here.

2. It is possible that you have to write a custom shader for your vertex format. For example the documentation of ObjectDynamic contains this:

Quote

ObjectDynamic class requires a custom shader for rendering, no built-in shaders are available.

Maybe the mesh_base material can not handle this.

Best regards

Link to comment

Thank you for pointing the mistake in the code above @ipg_rom.

I could able to get it work. I have created an ObjectExtern and in the render call for passes, it is using the custom deferred material and rendering mesh dynamic.

Rohit

Edited by rohit.gonsalves
Link to comment
  • silent changed the title to [SOLVED] How to Render Mesh Dynamic?
×
×
  • Create New...