コード例 #1
1
ファイル: skpmodel.cpp プロジェクト: pulkitag/skp2obj
int SkpModel::LoadVertices(){
	SUResult res;
	int out = 0;

	for (int f=0; f<faces_.size(); f++){
		//Form the mesh
		SUMeshHelperRef mesh = SU_INVALID;
		res = SUMeshHelperCreate(&mesh, faces_[f]);
		ErrorHandler(res);
		
		// Get number of vertices. 
		size_t num_vertices;
		res = SUMeshHelperGetNumVertices(mesh, &num_vertices);
		ErrorHandler(res);

		//Get vertices.
		std::vector<SUPoint3D>   vertices(num_vertices);
		res = SUMeshHelperGetVertices(mesh, num_vertices, &vertices[0], &num_vertices);
		ErrorHandler(res);
		vertices_.add(vertices);
		
		//Get Normals
		std::vector<SUVector3D>  normals(num_vertices);
		res = SUMeshHelperGetNormals (mesh, num_vertices, &normals[0], &num_vertices);
		ErrorHandler(res);
		normals_.add(normals);

		//Front Texture Coordinates
		std::vector<SUPoint3D> texture_coords(num_vertices);
		size_t num_coords;
		res = SUMeshHelperGetFrontSTQCoords(mesh, num_vertices, &texture_coords[0], &num_coords);
		ErrorHandler(res);
		assert(num_coords == num_vertices);
		stqcoords_front_.add(texture_coords);

		//Back Texture Coordinates
		std::vector<SUPoint3D> texture_coords_back(num_vertices);
		res = SUMeshHelperGetFrontSTQCoords(mesh, num_vertices, &texture_coords_back[0], &num_coords);
		ErrorHandler(res);
		assert(num_coords == num_vertices);
		stqcoords_back_.add(texture_coords_back);

		SUMeshHelperRelease(&mesh);
		//*/
		/*
		size_t num_vertices;
		SUFaceGetNumVertices(faces_[f], &num_vertices);
		std::vector<SUVertexRef> vertices(num_vertices);
		SUFaceGetVertices(faces_[f], num_vertices, &vertices[0], &num_vertices);
		vertices_.add(vertices);
		*/

	}
	return out;
}
コード例 #2
0
ファイル: skpmodel.cpp プロジェクト: pulkitag/skp2obj
int SkpModel::Face2AttributeIndices(SUFaceRef face, std::vector<size_t>* vertIdxs,
	 								std::vector<size_t>* normalIdxs, std::vector<size_t>* fIdxs){
	int out = 0;
	SUResult res;

	//Form the mesh
	SUMeshHelperRef mesh = SU_INVALID;
	res = SUMeshHelperCreate(&mesh, face);
	ErrorHandler(res);
	
	// Get number of vertices. 
	size_t num_vertices;
	res = SUMeshHelperGetNumVertices(mesh, &num_vertices);
	ErrorHandler(res);

	//Get vertices.
	std::vector<SUPoint3D>   vertices(num_vertices);
	res = SUMeshHelperGetVertices(mesh, num_vertices, &vertices[0], &num_vertices);
	ErrorHandler(res);
	
	//Get Normals
	std::vector<SUVector3D>  normals(num_vertices);
	res = SUMeshHelperGetNormals (mesh, num_vertices, &normals[0], &num_vertices);
	ErrorHandler(res);

	//Get Front Texture indices
	std::vector<SUPoint3D>  fcoords(num_vertices);
	res = SUMeshHelperGetFrontSTQCoords(mesh, num_vertices, &fcoords[0], &num_vertices);
	ErrorHandler(res);

	SUMeshHelperRelease(&mesh);
	assert(vertIdxs->size() == num_vertices);

	for (size_t i =0; i < num_vertices; i++){
		vertIdxs->at(i)   = vertices_.get_index(vertices[i]);
		normalIdxs->at(i) = normals_.get_index(normals[i]);
		fIdxs->at(i)      = stqcoords_front_.get_index(fcoords[i]);
	}

	return out;	
}
コード例 #3
0
ファイル: ModelWriter.cpp プロジェクト: jflo/sketchup2room
void ModelWriter::writeFace(SUMeshHelperRef mesh, const Transform& transform, bool front, bool textured) {

	size_t vertexCount=0;
	SUMeshHelperGetNumVertices(mesh,&vertexCount);
	vector<SUPoint3D> verts(vertexCount);
	SUMeshHelperGetVertices(mesh,vertexCount,verts.data(),&vertexCount);

	vector<SUVector3D> normals(vertexCount);
	SUMeshHelperGetNormals(mesh,vertexCount,normals.data(),&vertexCount);

	vector<SUPoint3D> textures(vertexCount);
	
	size_t triCount = 0;
	SUMeshHelperGetNumTriangles(mesh,&triCount);

	size_t gotIndices = 0;
	vector<size_t> indicies(triCount*3);
	SUResult res = SUMeshHelperGetVertexIndices(mesh,triCount*3,indicies.data(),&gotIndices);
	assert(res == SU_ERROR_NONE);

	if(textured) {
		if(front) {
			SUMeshHelperGetFrontSTQCoords(mesh,vertexCount,textures.data(),&vertexCount);
		} else {
			SUMeshHelperGetBackSTQCoords(mesh,vertexCount,textures.data(),&vertexCount);
		}
	}
	float normalScale = 1.0f;
	if(!front) {
		normalScale = -1.0f;
	}
	
	bool flip = !front;

	SUVector3D xFlipTest = xaxis * transform;
	if(xFlipTest.x < 0) {
		flip = !flip;
	}

	SUVector3D yFlipTest = yaxis * transform;
	if(yFlipTest.y < 0) {
		flip = !flip;
	}
	
	for(size_t t = 0; t < triCount; t++) {
			
		m_Faces << "f ";

		for(int i=0; i<3; i++) {

			int j = (t*3) + (flip ? 2-i : i);
			
			m_Faces << getIndexedPos(verts[indicies[j]]*transform) << "/";
			
			if(textured)
				m_Faces << getIndexedTex(textures[indicies[j]]);
			
			m_Faces << "/" <<  getIndexedNormal(normals[indicies[j]]*normalScale*transform) << " ";
		}

		m_Faces << endl;
	}

}