Esempio n. 1
0
void SceneGraphComponent::getMeshData(MeshData* data)
{
	if (m_hordeID > 0)
	{
		H3DRes geoResource = 0;
		int vertexOffset = 0;
		int indexOffset = 0;
		switch(h3dGetNodeType(m_hordeID))
		{
		case H3DNodeTypes::Mesh:
			geoResource = h3dGetNodeParamI(h3dGetNodeParent(m_hordeID), H3DModel::GeoResI);
			data->NumVertices = h3dGetNodeParamI(m_hordeID, H3DMesh::VertREndI) - h3dGetNodeParamI(m_hordeID, H3DMesh::VertRStartI) + 1;
			data->NumTriangleIndices = h3dGetNodeParamI(m_hordeID, H3DMesh::BatchCountI);		
			data->VertRStart = h3dGetNodeParamI(m_hordeID, H3DMesh::VertRStartI);
			vertexOffset = h3dGetNodeParamI(m_hordeID, H3DMesh::VertRStartI) * 3;
			indexOffset = h3dGetNodeParamI(m_hordeID, H3DMesh::BatchStartI);
			break;
		case H3DNodeTypes::Model:
			geoResource = h3dGetNodeParamI(m_hordeID, H3DModel::GeoResI);
			data->NumVertices = h3dGetResParamI(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoVertexCountI);
			data->NumTriangleIndices = h3dGetResParamI(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexCountI);		
			break;
		case H3DEXT_NodeType_Terrain:
			unloadTerrainGeoRes();
			geoResource = h3dextCreateTerrainGeoRes( 
				m_hordeID, 
				h3dGetNodeParamStr( m_hordeID, H3DNodeParams::NameStr ), 
				h3dGetNodeParamF( m_hordeID, H3DEXTTerrain::MeshQualityF, 0) );		
			data->NumVertices = h3dGetResParamI(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoVertexCountI);
			data->NumTriangleIndices = h3dGetResParamI(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexCountI);		
			m_terrainGeoRes = geoResource;
			break;
		}
		float* vb = (float*)h3dMapResStream(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoVertPosStream, true, false);
		data->VertexBase = new float[(data->NumVertices*3)];
		memcpy(data->VertexBase, vb+vertexOffset, sizeof(float)*data->NumVertices*3);
		h3dUnmapResStream(geoResource);

		//Triangle indices, must cope with 16 bit and 32 bit
		if (h3dGetResParamI(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndices16I)) {
			unsigned short* tb = (unsigned short*)h3dMapResStream(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexStream, true, false);
			data->TriangleBase16 = new unsigned short[data->NumTriangleIndices];
			memcpy(data->TriangleBase16, tb+indexOffset, sizeof(unsigned short)*data->NumTriangleIndices);
			h3dUnmapResStream(geoResource);
		} else {
			unsigned int* tb = (unsigned int*)h3dMapResStream(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexStream, true, false);
			data->TriangleBase32 = new unsigned int[data->NumTriangleIndices];
			memcpy(data->TriangleBase32, tb+indexOffset, sizeof(unsigned int)*data->NumTriangleIndices);
			h3dUnmapResStream(geoResource);
		}
		//data->TriangleMode = Horde3D::getResourceParami(geoResource, GeometryResParams::TriangleMode);
	}
}
Esempio n. 2
0
void VideoComponent::update()
{
	if (m_playing)
	{
		if (m_newData)
		{
			// Map texture stream for writing
			void *mappedData = h3dMapResStream(m_videoTexture, H3DTexRes::ImageElem, 0, H3DTexRes::ImgPixelStream, false, true );
			// Copy image data over to horde's internal buffer
			memcpy(mappedData, m_bgraData, m_resizeWidth*m_resizeHeight*4);
			// Tell horde to upload data to GL
			h3dUnmapResStream(m_videoTexture);
			// We have used all new data...
			m_newData = false;
		}
		else
			stopAvi();
	}
	if (m_startNextFrame)
	{
		// We shall start the video in this frame
		playAvi();
		m_startNextFrame = false;
	}
}
	btCollisionShape* createCollisionShape()
	{
		if (mesh->getModelNode() == 0) mesh->registerStart();

		m_btTriangleMesh = new btTriangleMesh();
		H3DNode meshNode = h3dGetNodeChild(mesh->getModelNode(), 0); //TODO handle multi-mesh stuff
		if (meshNode == 0) throw Exception("Couldn't get mesh node.\n");
		H3DRes geoRes = h3dGetNodeParamI(mesh->getModelNode(), H3DModel::GeoResI);
		unsigned int numVertices = h3dGetNodeParamI(meshNode, H3DMesh::VertREndI) - h3dGetNodeParamI(meshNode, H3DMesh::VertRStartI) + 1;//get mesh vertices count
		unsigned int numTriangleIndices = h3dGetNodeParamI(meshNode, H3DMesh::BatchCountI);//get mesh triangle indices count
		unsigned int vertRStart = h3dGetNodeParamI(meshNode, H3DMesh::VertRStartI);//get the first vertex of the mesh
		int off = 3;


		std::cout << numVertices << " vertices.\n";
		std::cout << numTriangleIndices << " indices.\n";

		int vertexOffset = vertRStart * 3;
		int indexOffset = h3dGetNodeParamI(meshNode, H3DMesh::BatchStartI);

		float* vertexBase = (float*) h3dMapResStream(geoRes, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoVertPosStream, true, false);//gets pointer to the vertex data
		h3dUnmapResStream(geoRes);//closes vertex stream

		if(vertexBase) vertexBase += vertexOffset;

		unsigned int* TriangleBase32 = nullptr;
		unsigned short* TriangleBase16 = nullptr;

		if (h3dGetResParamI(geoRes, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndices16I))
		{
			unsigned short* tb = (unsigned short*)h3dMapResStream(geoRes, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexStream, true, false);
			TriangleBase16 = new unsigned short[ numTriangleIndices ];
			memcpy(TriangleBase16, tb+indexOffset, sizeof(unsigned short)*numTriangleIndices);
			h3dUnmapResStream(geoRes);
			delete TriangleBase32;
		}
		else
		{
			unsigned int* tb = (unsigned int*)h3dMapResStream(geoRes, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexStream, true, false);
			TriangleBase32 = new unsigned int[numTriangleIndices];
			memcpy(TriangleBase32, tb+indexOffset, sizeof(unsigned int)*numTriangleIndices);
			h3dUnmapResStream(geoRes);
			delete TriangleBase16;
		}

		unsigned int indices[numTriangleIndices];

		bool index16 = false;
		if (TriangleBase16)
			index16 = true;

	    for (unsigned int i = 0; i < numTriangleIndices - 2; i += 3)
		 {
			unsigned int index1 = index16 ? (TriangleBase16[i]   - vertRStart) * 3 : (TriangleBase32[i]   - vertRStart) * 3;
			unsigned int index2 = index16 ? (TriangleBase16[i+1] - vertRStart) * 3 : (TriangleBase32[i+1] - vertRStart) * 3;
			unsigned int index3 = index16 ? (TriangleBase16[i+2] - vertRStart) * 3 : (TriangleBase32[i+2] - vertRStart) * 3;

			m_btTriangleMesh->addTriangle(
			   btVector3(vertexBase[index1], vertexBase[index1+1], vertexBase[index1+2] ),
			   btVector3(vertexBase[index2], vertexBase[index2+1], vertexBase[index2+2] ),
			   btVector3(vertexBase[index3], vertexBase[index3+1], vertexBase[index3+2]),
			   false
			);
		 }

	    return new btBvhTriangleMeshShape(m_btTriangleMesh, true, true);
	}