update manual object?

Problems building or running the engine, queries about how to use features etc.
Post Reply
kneeride
Bugbear
Posts: 807
Joined: Sun May 14, 2006 2:24 pm
Location: Melbourne, Australia

update manual object?

Post by kneeride »

I'm creating a manual object. My code looks similar to the following:

Code: Select all

	m_pManual = scene->m_pSceneManager->createManualObject("Test");
	m_pManual->begin("BaseWhiteNoLighting", RenderOperation::OT_TRIANGLE_LIST);

	m_pManual->position(Vector(...));
	m_pManual->position(Vector(...));
	m_pManual->position(Vector(...));
	m_pManual->position(Vector(...));

	// join the 4 vertices created above to form a quad.
	m_pManual->quad(point_index, point_index + 1, point_index + 2, point_index + 3);
	point_index += 4;

	m_pManual->end();

Can I add more points and quads to this object later?

I'm fairly proficient with the Manual object, so I'd rather avoid the MeshPtr. I'd prefer to destroy the old manual object and then rebuilding a new manual object (if performance not too heavy of course).

Is it also possible to also update points in the manual object. eg I'd like to update the position at index X.


Thanks
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

See ManualObject::beginUpdate().
kneeride
Bugbear
Posts: 807
Joined: Sun May 14, 2006 2:24 pm
Location: Melbourne, Australia

Post by kneeride »

sorry sinbad. I've read heaps of docs but am having trouble getting it to work.

is this the basic usage? ie call beginUpdate(), rebuild the data and then call end(). i couldnt really find any routines that edited existing points. so I've assume that I call position again for each point. (I hope that isnt adding more points...)

Code: Select all

m_pManual->updateBegin(0);
m_pManual->position(...); 
m_pManual->position(...); 
m_pManual->position(...); 
m_pManual->position(...); 
m_pManual->quad(...);
m_pManual->end();
Oh yes, i've called setDynamic when creating the manual object

Code: Select all

m_pManual = m_pSceneManager->createManualObject(...);
m_pManual->setDynamic(true);
m_pManual->begin(...);
...
m_pManual->end();
I have a feeling I'm not using this object correctly
kneeride
Bugbear
Posts: 807
Joined: Sun May 14, 2006 2:24 pm
Location: Melbourne, Australia

Post by kneeride »

it's all working. i found this helpful

http://www.ogre3d.org/wiki/index.php/TerrainMeshDecal

the wiki never called setDynamic(true);
i'm not sure if that is an issue...
User avatar
Tabarn@kdeca.lis
Halfling
Posts: 63
Joined: Wed Jul 26, 2006 8:13 pm
Location: Montr�al, Qu�bec

Post by Tabarn@kdeca.lis »

Tabarn@kdeca.lis wrote:Hi,
Here is a serious lacking class of the Ogre Engine that should be implemented in future versions. Seriously, I don't get why Ogre support that well models and bones animation, with user friendly and clean code, but you need three days of work to be able to draw a simple line.
http://www.ogre3d.org/phpBB2/viewtopic. ... highlight=
Thanks for the implementation of such an helpful feature!
User avatar
prinz
Gnoblar
Posts: 13
Joined: Tue May 22, 2007 2:51 pm
Location: BecksTown, Germany

What I'm doing wrong?

Post by prinz »

Hi.

I'm trying to alter the mesh of a simple cube wich I created with ManualObject (whereas the vertices, normals and indices are copied from this codesnippet: http://www.ogre3d.org/wiki/index.php/GeneratingAMesh)
Before setting the vertices and normals I set dynamic 'true' and after that I set the indices. The cube is built correctly - so far, so good.
Now I made a function to move a vertex of this cube to test ManualObject::beginUpdate(). I call this function after attaching the manual cube mesh to a scene node. But the mesh doesn't change :x

Here is my code:

# Create the mesh:

Code: Select all

void MeshGenerator::createManualObj(Ogre::String name) {
	using namespace Ogre;

	String objMaterial = xmlConf->getValue("manObjMaterial");

	/* Set the vertices and normals of the cube */
	const float sqrt13 = 0.577350269f; /* sqrt(1/3) */
	int i = 0;
	cubeVertices.push_back(Vector3(-100.0,100.0,-100.0));
	cubeNormals.push_back(Vector3(-sqrt13,sqrt13,-sqrt13));

	cubeVertices.push_back(Vector3(100.0,100.0,-100.0));
	cubeNormals.push_back(Vector3(sqrt13,sqrt13,-sqrt13));

	cubeVertices.push_back(Vector3(100.0,-100.0,-100.0));
	cubeNormals.push_back(Vector3(sqrt13,-sqrt13,-sqrt13));

	cubeVertices.push_back(Vector3(-100.0,-100.0,-100.0));
	cubeNormals.push_back(Vector3(-sqrt13,-sqrt13,-sqrt13));

	cubeVertices.push_back(Vector3(-100.0,100.0,100.0));
	cubeNormals.push_back(Vector3(-sqrt13,sqrt13,sqrt13));

	cubeVertices.push_back(Vector3(100.0,100.0,100.0));
	cubeNormals.push_back(Vector3(sqrt13,sqrt13,sqrt13));

	cubeVertices.push_back(Vector3(100.0,-100.0,100.0));
	cubeNormals.push_back(Vector3(sqrt13,-sqrt13,sqrt13));

	cubeVertices.push_back(Vector3(-100.0,-100.0,100.0));
	cubeNormals.push_back(Vector3(-sqrt13,-sqrt13,sqrt13));

	/* Define 12 triangles (two triangles per cube face) */
	const size_t ibufCount = 36;
	unsigned short faces[ibufCount] = {
		0,2,3,
		0,1,2,
		1,6,2,
		1,5,6,
		4,6,5,
		4,7,6,
		0,7,4,
		0,3,7,
		0,5,1,
		0,4,5,
		2,7,3,
		2,6,7
	};

	/* Create a ManualObject with the given name */
	obj = new ManualObject(name);
	
	/* setDynamic = true - to alter the geometry after creating manualObject */
	obj->setDynamic(true);

	/* Start a new section - CUBE */
	obj->begin(objMaterial, RenderOperation::OT_TRIANGLE_LIST);
	
	/* Set the vertices and normals of the cube in the object*/
	for(i = 0; i < 8; i++) {
		obj->position(cubeVertices[i]);
		obj->normal(cubeNormals[i]);
	} // for(i = 0; i < 8; i++)
	/* Set the faces (triangles) of the cube */
	for (i = 0; i < ibufCount; i++) {
		obj->index(faces[i]);
	}

	/* Finish object creation */
	obj->end();

	/* Convert object to a mesh, so we can create many instances of it */
	MeshPtr mesh = obj->convertToMesh(name);
}

# Manipulate the mesh

Code: Select all

void MeshGenerator::manipulateObject() {
	using namespace Ogre;

	const size_t ibufCount = 36;
	unsigned short faces[ibufCount] = {
		0,2,3,
		0,1,2,
		1,6,2,
		1,5,6,
		4,6,5,
		4,7,6,
		0,7,4,
		0,3,7,
		0,5,1,
		0,4,5,
		2,7,3,
		2,6,7
	};

	/* Move some vertices for testing */
	cubeVertices[1] = Vector3(1000.0,1000.0,-1000.0);
	cubeVertices[2] = Vector3(500.0,-500.0,-500.0);

	obj->beginUpdate(0);

	/* Set the vertices and normals of the cube in the object*/
	for(int i = 0; i < 8; i++) {
		obj->position(cubeVertices[i]);
		obj->normal(cubeNormals[i]);
	} // for(i = 0; i < 8; i++)
	/* Set the faces (triangles) of the cube */
	for (int i = 0; i < ibufCount; i++) {
		obj->index(faces[i]);
	}

	obj->end();
}
# In createScene():

Code: Select all

[...]
	mg->createManualObj("manualObject");

	ent1 = mSceneMgr->createEntity("manualObject_1", "manualObject");
	node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	node1->attachObject(ent1);

	mg->manipulateObject();
[...]
The manipulateOject() function works fine, if I convert the manualObject ( MeshPtr mesh = obj->convertToMesh("manualObject"); ) at the end of this function instead of the end of createManualObj() and call mg->manipulateObject() directly after mg->createManualObj("manualObject") - then the vertices of the cube mesh are moved as expected.
Have I missed anything?
Post Reply