Beispiel #1
0
static void
define_offset(
   Bvert* v,
   CVertMapper& tmap,
   CVertMapper& bmap,
   CWvec& n,
   Primitive* p
   )
{
   assert(v);
   double h = compute_h(v);

   // apply the offset to top and bottom verts:
   Bvert* tv = tmap.a_to_b(v);
   assert(tv);
   tv->offset_loc(n*h);
   Bvert* bv = bmap.a_to_b(v);
   assert(bv);
   bv->offset_loc(-n*h);

   // create xf memes
   Bface_list one_ring;
   v->get_all_faces(one_ring);
   DiskMap* frame = DiskMap::create(one_ring, false, v);
   p->create_xf_meme((Lvert*)tv, frame);
   p->create_xf_meme((Lvert*)bv, frame);
   p->add_input(frame);
}
Beispiel #2
0
bool
Skin::gen_verts(CBvert_list& skel_verts,
                CVertMapper& skel_mapper)
{
   // like plain gen_verts(), but take into account skel verts that
   // are "identified" together. i.e. if s1 and s2 are skel verts that
   // are identified together, we create just a single skin vert
   // corresponding to both s1 and s2.

   // first generate skin verts for the skel verts that are
   // mapped *to* by other skel verts
   if (!gen_verts(skel_mapper.B())) {
      err_adv(debug, "Skin::gen_verts: can't replicate skel verts (pass 1)");
      return false;
   }

   // now create a skel-to-skin association of each mapped-from
   // skel vert thru its skel counterpart to the skin vert
   if (!_mapper.is_valid())
      err_msg("  invalid mapper before gen_verts");
   _mapper.add(skel_mapper.A(), _mapper.a_to_b(skel_mapper.B()));
   if (!_mapper.is_valid())
      err_msg("  invalid mapper after gen_verts");

   // now do the rest to make sure all are covered
   if (!gen_verts(skel_verts)) {
      err_adv(debug, "Skin::gen_verts: can't replicate skel verts (pass 2)");
      return false;
   }
   return true;
}
Beispiel #3
0
inline void
report(CVertMapper& mapper, Cstr_ptr& msg)
{
   err_msg("  %s: %d verts to %d verts, %d edges to %d edges",
           **msg,
           mapper.A().num(),
           mapper.B().num(),
           mapper.a_edges().num(),
           mapper.a_to_b(mapper.a_edges()).num());
}
Beispiel #4
0
inline bool
create_sides(
   CBface_list& faces,
   CVertMapper& tmap,
   CVertMapper& bmap,
   Primitive* p
   )
{
   assert(p && tmap.is_valid() && bmap.is_valid());
   Bface_list ret;

   EdgeStrip boundary = faces.get_boundary();
   assert(!boundary.empty());

   EdgeStrip top_strip = tmap.a_to_b(boundary);
   EdgeStrip bot_strip = bmap.a_to_b(boundary);
   assert(!(top_strip.empty() || bot_strip.empty()));

   UVpt a, b, c, d;
   Bedge *top_e, *bot_e;
   Bface *top_f, *bot_f;
   Bvert *v1, *v2, *v3, *v4;
   for (int i = 0; i < top_strip.num(); i++) {
      top_e = top_strip.edge(i);
      bot_e = bot_strip.edge(i);
      top_f = top_e->get_face();
      bot_f = bot_e->get_face();
      v1 = top_strip.vert(i);
      v2 = top_e->other_vertex(v1);
      v3 = bot_strip.vert(i);
      v4 = bot_e->other_vertex(v3);
      bool has_uv = UVdata::get_uvs(top_f, a, b, c);
      if (has_uv) {
         assert(top_f->is_quad() && bot_f->is_quad());
         a = UVdata::get_uv(v1, top_f);
         b = UVdata::get_uv(v2, top_f);
         c = UVdata::get_uv(v3, bot_f);
         d = UVdata::get_uv(v4, bot_f);
         if (c[0]==0 && d[0]==0) 
            c[0] = d[0] = a[0]+abs((UVdata::get_uv(top_f->other_vertex(v1, v2), top_f))[0]-a[0]);
         if (top_f->other_vertex(top_f->weak_edge()) == v1)
            p->add_quad(v1, v3, v4, v2, a, c, d, b);
         else {
            assert(top_f->other_vertex(top_f->weak_edge()) == v2);
            p->add_quad(v3, v4, v2, v1, c, d, b, a);
         }
      } else {
         p->add_quad(v1, v3, v4, v2);
      }
   }

   return true;
}
Beispiel #5
0
inline void
define_offsets(
   CBvert_list& verts,
   CVertMapper& tmap,
   CVertMapper& bmap,
   CWvec& n,
   Primitive* p
   )
{
   assert(tmap.is_valid() && bmap.is_valid());

   for (Bvert_list::size_type i=0; i<verts.size(); i++) {
      define_offset(verts[i], tmap, bmap, n, p);
   }
}
Beispiel #6
0
inline Bface_list
copy_faces(CBface_list& faces, CVertMapper& vmap, Primitive* p, bool reverse=false)
{
   assert(p && vmap.is_valid());
   Bface_list ret;

   for (Bface_list::size_type i=0; i<faces.size(); i++) {
      ret.push_back(copy_face(faces[i], vmap, p, reverse));
   }
   copy_edges(faces.get_edges(), vmap);
   return ret;
}
Beispiel #7
0
inline bool 
copy_edge(Bedge* a, CVertMapper& vmap)
{
   // copy edge attributes, e.g. from skel to skin

   Bedge* b = vmap.a_to_b(a);
   if (!(a && b))
      return false;

   if (a->is_weak())
      b->set_bit(Bedge::WEAK_BIT);

   // more?

   return true;
}
Beispiel #8
0
inline VertMapper
subdiv_mapper(CVertMapper& pmap)
{
   Bedge_list a_edges = pmap.a_edges();
   Bedge_list b_edges = pmap.a_to_b(a_edges);
   assert(a_edges.num() == b_edges.num());

   if (0 && debug) {
      err_msg("parents: verts: %d --> %d, edges: %d --> %d",
              pmap.A().num(), pmap.B().num(), a_edges.num(), b_edges.num());
      err_msg("children: verts: %d --> %d",
              (child_verts<Bvert_list,Lvert>(pmap.A()) +
               child_verts<Bedge_list,Ledge>(a_edges)).num(),
              (child_verts<Bvert_list,Lvert>(pmap.B()) +
               child_verts<Bedge_list,Ledge>(b_edges)).num());

      Bvert_list c = (child_verts<Bvert_list,Lvert>(pmap.A()) +
                      child_verts<Bedge_list,Ledge>(a_edges));
      if (c.has_duplicates()) {
         err_msg("*** child verts have duplicates ***");
         if (pmap.A().has_duplicates()) {
            err_msg("  A verts have duplicates");
         }
         if (pmap.a_edges().has_duplicates()) {
            err_msg("  A edges have duplicates");
         }
         if (child_verts<Bvert_list,Lvert>(pmap.A()).has_duplicates()) {
            err_msg("  vert children have duplicates");
         }
         if (child_verts<Bedge_list,Ledge>(pmap.a_edges()).has_duplicates()) {
            err_msg("  edge children have duplicates");
         }
         WORLD::show_pts(c.pts());
      }
   }

   return VertMapper(
      child_verts<Bvert_list,Lvert>(pmap.A()) +
      child_verts<Bedge_list,Ledge>(a_edges),
      child_verts<Bvert_list,Lvert>(pmap.B()) +
      child_verts<Bedge_list,Ledge>(b_edges)
      );
}