89{
90 const char *filename= "data/cornell.glb";
91 if(argc > 1)
92 filename= argv[1];
93
94
95 GLTFScene scene= read_gltf_scene(filename);
96
97
98 std::vector<Triangle> triangles;
99 for(unsigned node_id= 0; node_id < scene.nodes.size(); node_id++)
100 {
101 const GLTFNode& node= scene.nodes[node_id];
102
105
106 const GLTFMesh& mesh= scene.meshes[mesh_id];
107 for(unsigned primitive_id= 0; primitive_id < mesh.primitives.size(); primitive_id++)
108 {
110 for(unsigned i= 0; i +2 < primitives.indices.size(); i+= 3)
111 {
112
113 int a= primitives.indices[i];
114 int b= primitives.indices[i+1];
115 int c= primitives.indices[i+2];
116
117
118 Point pa= primitives.positions[a];
119 Point pb= primitives.positions[b];
120 Point pc= primitives.positions[c];
121
122
123 pa= model( pa );
124 pb= model( pb );
125 pc= model( pc );
126
127 triangles.push_back(
Triangle(pa, pb, pc, mesh_id, primitive_id, i/3) );
128 }
129 }
130 }
131 assert(triangles.size());
132
133
134 assert(scene.cameras.size());
136 Transform projection= scene.cameras[0].projection;
137
138
139 unsigned width= 1024;
140 unsigned height= width / scene.cameras[0].aspect;
141 Image image(width, height);
142
143
147
148
149 for(unsigned y= 0; y < image.height(); y++)
150 for(unsigned x= 0; x < image.width(); x++)
151 {
152
155 Ray ray(origine, extremite);
156
157
159 for(unsigned i= 0; i < triangles.size(); i++)
160 {
161 if(
Hit h= triangles[i].intersect(ray, hit.t))
162
163
164 hit= h;
165 }
166
167 if(hit)
168
169 image(x, y)=
Color(1 - hit.u - hit.v, hit.u, hit.v);
170 }
171
173 return 0;
174}
representation d'une image.
int mesh_index
indice du maillage.
Transform model
transformation model pour dessiner le maillage.
description d'un maillage.
position et orientation d'un maillage dans la scene.
groupe de triangles d'un maillage. chaque groupe est associe a une matiere.
bool write_image(const Image &image, const char *filename, const bool flipY)
enregistre une image au format .png
Transform Inverse(const Transform &m)
renvoie l'inverse de la matrice.
Transform Viewport(const float width, const float height)
renvoie la matrice representant une transformation viewport.
Transform Identity()
construit la transformation identite.
representation d'une couleur (rgba) transparente ou opaque.
intersection avec un triangle.
representation d'un point 3d.
triangle pour le bvh, cf fonction bounds() et intersect().