예제 #1
0
void transfer_bullet_shape(btTriangleMesh& dest, const objfile &src, const sf::Texture *heightfield) {
	float max_height = ATVBCube::setting<S::TeslaGeneralSetting>().maxheight_phy;
	
	sf::Image heightimage = heightfield->copyToImage();
	
	for (std::size_t i = 0; i < src.raw_faces.size(); i++) {
		glm::i32vec3 face = src.raw_faces[i];
		
		int height1 = 0, height2 = 0, height3 = 0;
		
		glm::i32vec3 texcoord = src.raw_face_uvcoords[i];
		glm::vec3 gt1 = src.raw_uvcoords[texcoord[0]], gt2 = src.raw_uvcoords[texcoord[1]], gt3 = src.raw_uvcoords[texcoord[2]];
		glm::vec3 gv1 = src.raw_verts[face[0]], gv2 = src.raw_verts[face[1]], gv3 = src.raw_verts[face[2]];
		
		gt1 /= 30.0, gt2 /= 30.0, gt3 /= 30.0;
		float heightf1 = sfImageGetPixelFloat(heightimage, gt1.x, gt1.y).r/255.0,
				heightf2 = sfImageGetPixelFloat(heightimage, gt2.x, gt2.y).r/255.0,
				heightf3 = sfImageGetPixelFloat(heightimage, gt3.x, gt3.y).r/255.0;
		
		height1 = heightf1 * max_height, height2 = heightf2 * max_height, height3 = heightf3 * max_height;
		
		gv1 *= PHY_SCALE, gv2 *= PHY_SCALE, gv3 *= PHY_SCALE;
		height1 *= PHY_SCALE, height2 *= PHY_SCALE, height3 *= PHY_SCALE;
		
		btVector3 bv1 { gv1.y, gv1.x, gv1.z+height1 }, bv2 { gv2.y, gv2.x, gv2.z+height2 }, bv3 { gv3.y, gv3.x, gv3.z+height3 };
		dest.addTriangle(bv1, bv2, bv3);
	}
}
예제 #2
0
  void createPoints(const std::string& fname)
  {
    
    // const aiScene* gWVP = importer.ReadFile(fname.c_str(), aiProcess_Triangulate | aiProcess_SortByPType);

    // const aiScene* gWVP = importer.ReadFile(fname.c_str(), aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_OptimizeMeshes | aiProcess_GenSmoothNormals | aiProcess_FlipUVs);

    const aiScene* gWVP = importer.ReadFile(fname.c_str(), aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_GenSmoothNormals );

    glm::vec3 vertex; 
    glm::vec3 face;
    glm::vec3 normal;
    glm::vec2 texture;
    
    //for each mesh loaded -->there could be multiple meshes in one obj file
    for(unsigned int i = 0; i < gWVP->mNumMeshes; i ++) {
      const aiMesh* mesh = gWVP->mMeshes[i]; //aiMesh is a struct

      /* get the vertices */
      for(unsigned int j = 0; j < mesh->mNumVertices; j ++) { 
          data.push_back(Point());
          aiVector3D temp_vertex = mesh->mVertices[j];       
          vertex.x = temp_vertex.x;
          vertex.y = temp_vertex.y;
          vertex.z = temp_vertex.z;
          data[j].vertex = vertex;
          data[j].texture = glm::vec2(vertex.x, vertex.z);  // hackish
          // vertices.push_back(vertex);
      } 

      /* get the faces */
      for(unsigned int j = 0; j < mesh->mNumFaces; j ++) {
          //aiProcess_Triangulate creates triangles out of the vertices and so
          //there are 3 indices per faces -- you can check for the number of
          //indices also with "mNumIndices" - data member aiFace 
          aiFace Face = mesh->mFaces[j];  
          btVector3 i,j,k;
          i = aiVector3TobtVector3(  mesh->mVertices[ Face.mIndices[0] ]  );
          j = aiVector3TobtVector3(  mesh->mVertices[ Face.mIndices[1] ]  );
          k = aiVector3TobtVector3(  mesh->mVertices[ Face.mIndices[2] ]  );
          bt_triangles.addTriangle(i,j,k);
          // faces.push_back(face);
      } 
      /* get the faces
      for(unsigned int j = 0; j < mesh->mNumFaces; j ++) {
          //aiProcess_Triangulate creates triangles out of the vertices and so
          //there are 3 indices per faces -- you can check for the number of
          //indices also with "mNumIndices" - data member aiFace 
          aiFace Face = mesh->mFaces[j];  
          face.x = Face.mIndices[0];      
          face.y = Face.mIndices[1];
          face.z = Face.mIndices[2];
          // faces.push_back(face);
      } */

      /* normals */
      // std::cout << "normal exists: " << mesh->HasNormals() << std::endl; 
      if(mesh->HasNormals()) {
        for(unsigned int j = 0; j < mesh->mNumVertices; j ++) { //each vertex has a normal
          aiVector3D temp_vertex = mesh->mNormals[j];
          normal.x = temp_vertex.x;
          normal.y = temp_vertex.y;
          normal.z = temp_vertex.z;
          data[j].normal = normal;
          // normals.push_back(normal);
        }
      }

    }

  }