Exemplo n.º 1
0
 private static Color col(Message buf) {
   return (new Color(
       (int) (buf.cpfloat() * 255.0),
       (int) (buf.cpfloat() * 255.0),
       (int) (buf.cpfloat() * 255.0),
       (int) (buf.cpfloat() * 255.0)));
 }
Exemplo n.º 2
0
 public Res cons(final Resource res, Message buf) {
   int id = buf.uint16();
   Res ret = new Res(res, id);
   GLState light = Light.deflight;
   while (!buf.eom()) {
     String thing = buf.string().intern();
     if (thing == "col") {
       Color amb = col(buf);
       Color dif = col(buf);
       Color spc = col(buf);
       double shine = buf.cpfloat();
       Color emi = col(buf);
       ret.states.add(new Colors(amb, dif, spc, emi, (float) shine));
     } else if (thing == "linear") {
       ret.linear = true;
     } else if (thing == "mipmap") {
       ret.mipmap = true;
     } else if (thing == "nofacecull") {
       ret.states.add(nofacecull);
     } else if (thing == "tex") {
       final int tid = buf.uint16();
       ret.left.add(
           new Res.Resolver() {
             public void resolve(Collection<GLState> buf) {
               for (Resource.Image img : res.layers(Resource.imgc)) {
                 if (img.id == tid) {
                   buf.add(img.tex().draw());
                   buf.add(img.tex().clip());
                   return;
                 }
               }
               throw (new RuntimeException(
                   String.format("Specified texture %d not found in %s", tid, res)));
             }
           });
     } else if (thing == "texlink") {
       final String nm = buf.string();
       final int ver = buf.uint16();
       final int tid = buf.uint16();
       ret.left.add(
           new Res.Resolver() {
             public void resolve(Collection<GLState> buf) {
               Indir<Resource> tres = res.pool.load(nm, ver);
               for (Resource.Image img : tres.get().layers(Resource.imgc)) {
                 if (img.id == tid) {
                   buf.add(img.tex().draw());
                   buf.add(img.tex().clip());
                   return;
                 }
               }
               throw (new RuntimeException(
                   String.format(
                       "Specified texture %d for %s not found in %s", tid, res, tres)));
             }
           });
     } else if (thing == "light") {
       String l = buf.string();
       if (l.equals("pv")) {
         light = Light.vlights;
       } else if (l.equals("pp")) {
         light = Light.plights;
       } else if (l.equals("n")) {
         light = null;
       } else {
         throw (new Resource.LoadException("Unknown lighting type: " + thing, res));
       }
     } else {
       throw (new Resource.LoadException("Unknown material part: " + thing, res));
     }
   }
   if (light != null) ret.states.add(light);
   return (ret);
 }