Bug-i found that hkpShape::getUserData only return range 0~255

Bug-i found that hkpShape::getUserData only return range 0~255

Bild des Benutzers jins l.

                    i have create a terrain triangles list shapes,and used hkpBvCompressedMeshShape to create it.in set info code

TerrainConstructionInfo cInfo( &geometry);
{
cInfo.m_convexRadius = 1.0f;
cInfo.m_weldingType = hkpWeldingUtility::WELDING_TYPE_NONE;

cInfo.m_collisionFilterInfoMode = hkpBvCompressedMeshShape::PER_PRIMITIVE_DATA_PALETTE;

cInfo.m_userDataMode = hkpBvCompressedMeshShape::PER_PRIMITIVE_DATA_PALETTE;
}

// Construct the mesh shape using our construction info

//m_meshShape = hkRefNew<hkpBvCompressedMeshShape>(createBvCompressedMeshShape());
hkpBvCompressedMeshShape* pShape = new hkpBvCompressedMeshShape( cInfo );
//hkpSimpleMeshShape* pShape = new hkpSimpleMeshShape()
// Create body with the mesh shape
{
hkpRigidBodyCinfo info;
info.m_shape = pShape;
info.m_motionType = hkpMotion::MOTION_FIXED;
info.m_friction = 0.5f;
info.m_position.set(0.0f,0.0f,0.0f);
hkpRigidBody* pMeshBody = new hkpRigidBody(info);
m_pWorld->addEntity(pMeshBody);
pMeshBody->removeReference();

}

in raycast ,the keycode

mys3_bool hit = false;
if(rayOutput->hasHit())
{
hit = true;
const hkpShape* pShape = command->m_results->m_rootCollidable->getShape();
if (pShape->getType() == hkcdShapeType::BV_COMPRESSED_MESH)
{
// Retrive child shape.
hkpShapeBuffer shapeBuffer;
const hkpShape* childShape = reinterpret_cast<hkpBvCompressedMeshShape*>(it->second.pShape)->getChildShape(rayOutput->m_shapeKeys[0], shapeBuffer);

//triangle_index = childShape->getUserData();
hkArray<hkUint32> & userData = reinterpret_cast<hkpBvCompressedMeshShape*>(it->second.pShape)->accessUserDataPalette();
triangle_index = reinterpret_cast<hkpBvCompressedMeshShape*>(it->second.pShape)->getPrimitiveUserData(rayOutput->m_shapeKeys[0]);//return max value is 255

}

but i want to return the real triangle index,how can i do? 

10 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers HavokTim

Hi Jins I.--

It looks like getPrimitiveUserData() is returning the userDataIndex of the primitive data because you have not initialized the user data palette to any value (getUserDataIndex, setUserDataIndex). It is in fact the case that user data index can only by one of 256 unique values, but you can map these indices outside the range of 0 to 255 using the userdatapallete.

If, on the other hand, you are looking for unique identifiers for each individual triangle, you can use the shape key directly, or set up your own map from shape keys to values. It would be helpful to know how you intend to use this information so I can provided guidance about which solution makes the most sense. Why do you need triangle indices?

Thanks,
--Tim

Bild des Benutzers jins l.

Thank you,HavokTim.
now i had solved my problem,i used a way as this:


hkArray* tri_index_array = new hkArray;

TerrainConstructionInfo cInfo( &geometry);

	{

		cInfo.m_convexRadius = 1.0f;

		cInfo.m_weldingType = hkpWeldingUtility::WELDING_TYPE_NONE;

		// We will use 8 bits per primitive for collision filter infos as we have only 4 collision layers (1 to 4)

		cInfo.m_collisionFilterInfoMode = hkpBvCompressedMeshShape::PER_PRIMITIVE_DATA_PALETTE;
		// We will use 8 bits per primitive for the user data because all our user data values are in the range [0,255]

		cInfo.m_userDataMode = hkpBvCompressedMeshShape::PER_PRIMITIVE_DATA_PALETTE;

		cInfo.m_triangleIndexToShapeKeyMap = tri_index_array;

	}

//.....

physic_body_struct.index_map = new stdext::hash_map;

		hkUint32* pIt = cInfo.m_triangleIndexToShapeKeyMap->begin();

		for (int i = 0; i < cInfo.m_triangleIndexToShapeKeyMap->getSize();++i)

		{

			physic_body_struct.index_map->insert(make_pair(*pIt,i));

			pIt++;

		}	
		delete tri_index_array;


when i used it,i call like this:

stdext::hash_map::iterator itKey = it->second.index_map->find(output->m_shapeKeys[0]);

			if (itKey != it->second.index_map->end())

			{

				triangle_indexs[iOut] = itKey->second;

			}

			else

			{

				triangle_indexs[iOut] = 0xffffffff;

			}


i need this function to terrain mouse pick,and edit terrain etc.
but now,i fond a new error.when i want to update my shape in rigidbody.

class mys3_shape_modifier:public hkpShapeModifier

{

public:

	mys3_shape_modifier(const mys3_uint* vertex_indexs,const mys3_float3* vertexs,mys3_uint vertex_num):

	  m_vertex_indexs(vertex_indexs),

		  m_vertexs(vertexs),

		  m_vertex_num(vertex_num)

	{

	}
	void modifyShape(hkpShape* shapeInOut)

	{

		hkGeometry *pGem = hkpShapeConverter::toSingleGeometry(shapeInOut);

		if(NULL != pGem)

		{

			if (NULL != m_vertex_indexs)

			{

				for (mys3_uint i = 0;i < m_vertex_num; ++i)

				{

					pGem->m_vertices[m_vertex_indexs[i]].set(m_vertexs[i].flag.coord.x,m_vertexs[i].flag.coord.y,m_vertexs[i].flag.coord.z);

				}

			}

			else

			{

				assert(m_vertex_num <= pGem->m_vertices.getSize());

				for (mys3_uint i = 0;i < m_vertex_num; ++i)

				{

					pGem->m_vertices[i].set(m_vertexs[i].flag.coord.x,m_vertexs[i].flag.coord.y,m_vertexs[i].flag.coord.z);

				}

			}

		}

	}

private:

	const mys3_uint * m_vertex_indexs;

	const mys3_float3* m_vertexs;

	mys3_uint m_vertex_num;

};
mys3_void MYSAPI mys3_instance_physic_havok_body::mys3ModifyPhysicVertexs(mys3_uint obj_hash,const mys3_uint* vertex_indexs,const mys3_float3* vertexs,mys3_uint vertex_num)

{

	stdext::hash_map::iterator it = m_PhysicBodyMap.find(obj_hash);

	if(it == m_PhysicBodyMap.end())

	{

		return ;

	}
	m_pWorld->lock();

	mys3_shape_modifier shapeModifier(vertex_indexs,vertexs,vertex_num);

	it->second.pRigidBody->updateShape(&shapeModifier);//when this step,app crash

	m_pWorld->unlock();

}


To forgive I understand little English.:)

Bild des Benutzers HavokTim

Hi jins l.--

Sorry, it's not clear to me what error you're getting. Is it crashing, or asserting, or something else entirely?

Also, you can use the [ cpp ] and [ / cpp ] tags (remove spaces) to format text as C++ code.

Best regards,
--Tim

Bild des Benutzers jins l.

HI HavokTim.
can you show me a right code to change the hkshape's gem already in hkRigidBody?

Bild des Benutzers jins l.

show me a keycode
this function is very Important for me.
please!Tim

Bild des Benutzers jins l.

this is my new test to update shape data:


m_pWorld->lock();

	hkWorldOperation::UpdateWorldObjectShape shapeUpdateOpera;

	mys3_shape_modifier shapeModifier(vertex_indexs,vertexs,vertex_num);

	shapeUpdateOpera.m_shapeModifier = &shapeModifier;

	it->second.pRigidBody->markForWrite();

	shapeUpdateOpera.m_worldObject = it->second.pRigidBody;

	m_pWorld->lockCriticalOperations();

	m_pWorld->queueOperation(shapeUpdateOpera);

	m_pWorld->attemptToExecutePendingOperations();

	m_pWorld->unlockCriticalOperations();

	it->second.pRigidBody->unmarkForWrite();

        m_pWorld->unlock();

mys3_shape_modifier struct is this:


class mys3_shape_modifier:public hkpShapeModifier

{

public:

	mys3_shape_modifier(const mys3_uint* vertex_indexs,const mys3_float3* vertexs,mys3_uint vertex_num):

	  m_vertex_indexs(vertex_indexs),

		  m_vertexs(vertexs),

		  m_vertex_num(vertex_num)

	{

	}
	void modifyShape(hkpShape* shapeInOut)

	{

		hkGeometry *pGem = hkpShapeConverter::toSingleGeometry(shapeInOut);

		if(NULL != pGem)

		{

			if (NULL != m_vertex_indexs)

			{

				for (mys3_uint i = 0;i < m_vertex_num; ++i)

				{

					pGem->m_vertices[m_vertex_indexs[i]].set(m_vertexs[i].flag.coord.x,m_vertexs[i].flag.coord.y,m_vertexs[i].flag.coord.z);

				}

			}

			else

			{

				assert(m_vertex_num <= pGem->m_vertices.getSize());

				for (mys3_uint i = 0;i < m_vertex_num; ++i)

				{

					pGem->m_vertices[i].set(m_vertexs[i].flag.coord.x,m_vertexs[i].flag.coord.y,m_vertexs[i].flag.coord.z);

				}

			}

		}

	}

private:

	const mys3_uint * m_vertex_indexs;

	const mys3_float3* m_vertexs;

	mys3_uint m_vertex_num;

};

Bild des Benutzers jins l.

the code just i send was not working.what can i do for the right code?

Bild des Benutzers HavokTim

Hi Jins l.--

In what way does this code fail to work? Does it crash? Does it assert? Does it simply not do what you intend it to do? What error message do you get? Do you have a callstack?

I'm afraid I need more information to be able to help you.

Thanks,
--Tim

Bild des Benutzers jins l.

i am sorry.i am busy keep a lot of time this monthes.i will make a test after some days.and i can comment some report and log to you on that time.

Melden Sie sich an, um einen Kommentar zu hinterlassen.