Exemplo n.º 1
0
 TriangleMeshWithNormals::TriangleMeshWithNormals(const Parms& parms)
   : Shape(parms)
 {
   if (Variant v = parms.getData("positions")) {
     if (!v.data || v.type != Variant::FLOAT3) throw std::runtime_error("wrong position format");
     vertices.resize(v.data->size());
     for (size_t i=0; i<v.data->size(); i++) vertices[i].p = v.data->getVector3f(i);
   }
   if (Variant v = parms.getData("normals")) {
     if (!v.data || v.type != Variant::FLOAT3) throw std::runtime_error("wrong normal format");
     vertices.resize(v.data->size());
     for (size_t i=0; i<v.data->size(); i++) vertices[i].n = v.data->getVector3f(i);
   }
   if (Variant v = parms.getData("indices")) {
     if (!v.data || v.type != Variant::INT3) throw std::runtime_error("wrong triangle format");
     triangles.resize(v.data->size());
     for (size_t i=0; i<v.data->size(); i++) triangles[i] = v.data->getVector3i(i);
   }
 }
Exemplo n.º 2
0
 TriangleMeshFull::TriangleMeshFull (const Parms& parms)
   : Shape(parms)
 {
   if (Variant v = parms.getData("positions")) {
     if (!v.data || v.type != Variant::FLOAT3) throw std::runtime_error("wrong position format");
     position.resize(v.data->size());
     for (size_t i=0; i<v.data->size(); i++) position[i] = v.data->getVector3f(i);
   }
   if (Variant v = parms.getData("motions")) {
     if (!v.data || v.type != Variant::FLOAT3) throw std::runtime_error("wrong motion vector format");
     motion.resize(v.data->size());
     for (size_t i=0; i<v.data->size(); i++) motion[i] = v.data->getVector3f(i);
   }
   if (Variant v = parms.getData("normals")) {
     if (!v.data || v.type != Variant::FLOAT3) throw std::runtime_error("wrong normal format");
     normal.resize(v.data->size());
     for (size_t i=0; i<v.data->size(); i++) normal[i] = v.data->getVector3f(i);
   }
   if (Variant v = parms.getData("tangent_x")) {
     if (!v.data || v.type != Variant::FLOAT3) throw std::runtime_error("wrong tangent format");
     tangent_x.resize(v.data->size());
     for (size_t i=0; i<v.data->size(); i++) tangent_x[i] = v.data->getVector3f(i);
   }
   if (Variant v = parms.getData("tangent_y")) {
     if (!v.data || v.type != Variant::FLOAT3) throw std::runtime_error("wrong tangent format");
     tangent_y.resize(v.data->size());
     for (size_t i=0; i<v.data->size(); i++) tangent_y[i] = v.data->getVector3f(i);
   }
   if (Variant v = parms.getData("texcoords")) {
     if (!v.data || v.type != Variant::FLOAT2) throw std::runtime_error("wrong texcoords0 format");
     texcoord.resize(v.data->size());
     for (size_t i=0; i<v.data->size(); i++) texcoord[i] = v.data->getVec2f(i);
   }
   if (Variant v = parms.getData("texcoords0")) {
     if (!v.data || v.type != Variant::FLOAT2) throw std::runtime_error("wrong texcoords0 format");
     texcoord.resize(v.data->size());
     for (size_t i=0; i<v.data->size(); i++) texcoord[i] = v.data->getVec2f(i);
   }
   if (Variant v = parms.getData("indices")) {
     if (!v.data || v.type != Variant::INT3) throw std::runtime_error("wrong triangle format");
     triangles.resize(v.data->size());
     for (size_t i=0; i<v.data->size(); i++) triangles[i] = v.data->getVector3i(i);
   }
 }