ccdemos/common_ply.h
branchpyrit
changeset 91 9d66d323c354
parent 80 907929fa9b59
child 92 9af5c039b678
equal deleted inserted replaced
90:f6a72eb99631 91:9d66d323c354
     1 #include <iostream>
     1 #include <iostream>
     2 #include <fstream>
     2 #include <fstream>
     3 #include <iomanip>
     3 #include <iomanip>
     4 
     4 
     5 void load_ply(Raytracer &rt, const char *filename, Material *mat, Vector3 scale, Vector3 transp)
     5 void load_ply(Raytracer &rt, const char *filename, Material *mat, Vector scale, Vector transp)
     6 {
     6 {
     7 	vector<NormalVertex*> vertices;
     7 	vector<NormalVertex*> vertices;
     8 	vector<Vector3> normals;
     8 	vector<Vector> normals;
     9 	vector<int> vertex_face_num;
     9 	vector<int> vertex_face_num;
    10 	ifstream f(filename);
    10 	ifstream f(filename);
    11 	string token = "a";
    11 	string token = "a";
    12 	if (!f.is_open())
    12 	if (!f.is_open())
    13 	{
    13 	{
    29 		}
    29 		}
    30 		f.ignore(1000,'\n');
    30 		f.ignore(1000,'\n');
    31 	}
    31 	}
    32 
    32 
    33 	// read vertices
    33 	// read vertices
    34 	Vector3 P;
    34 	Vector P;
    35 	int num = vertex_num;
    35 	int num = vertex_num;
    36 	while (num--)
    36 	while (num--)
    37 	{
    37 	{
    38 		f >> P.x >> P.y >> P.z;
    38 		f >> P.x >> P.y >> P.z;
    39 		P.x = scale.x*P.x + transp.x;
    39 		P.x = scale.x*P.x + transp.x;
    40 		P.y = scale.y*P.y + transp.y;
    40 		P.y = scale.y*P.y + transp.y;
    41 		P.z = scale.z*P.z + transp.z;
    41 		P.z = scale.z*P.z + transp.z;
    42 		vertices.push_back(new NormalVertex(P));
    42 		vertices.push_back(new NormalVertex(P));
    43 		normals.push_back(Vector3());
    43 		normals.push_back(Vector());
    44 		vertex_face_num.push_back(0);
    44 		vertex_face_num.push_back(0);
    45 		f.ignore(1000,'\n');
    45 		f.ignore(1000,'\n');
    46 	}
    46 	}
    47 
    47 
    48 	// read faces
    48 	// read faces