Beispiel #1
0
 /**
  * @param id
  * @param data @Info Stocke le FloatBuffer dans le GPU
  */
 public void bufferData() {
   buffer = BufferUtils.createFloatBuffer(floatlist.size());
   for (Float f : floatlist) {
     buffer.put(f);
   }
   buffer.flip();
   glBindBuffer(GL_ARRAY_BUFFER, vboID);
   glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
   //		glBufferSubData(vboID, 0, buffer);
   glBindBuffer(GL_ARRAY_BUFFER, 0);
   bufferSize = buffer.limit() / 7; // 7 = 3 vertex(x,y,z) + 4 color (r,g,b,a)
 }
 /**
  * BVertexチャンクの読み込み
  *
  * @param br 読み込みストリーム
  * @return 頂点配列
  * @param scale モデルの倍率
  * @throws Exception
  */
 private KGLPoint[] readBvertex(multiInput br, float scale) throws Exception {
   KGLPoint[] ret = null;
   String line = null;
   String[] s;
   int p;
   int pe;
   int datasize = 0;
   try {
     while ((line = br.readLine().trim()) != null) {
       if (line.length() <= 0) continue;
       s = line.split(" ");
       if (s[0].equals("Vector")) {
         if (s.length != 3) {
           line = null;
           break;
         }
         p = s[2].indexOf("[");
         pe = s[2].indexOf("]");
         datasize = Integer.parseInt(s[2].substring(p + 1, pe));
         break;
       }
     }
   } catch (Exception e) {
     Log.e("KGLMetaseq", "MQOファイル フォーマットエラー(Object>Bvertex)[" + line + "]");
     throw new KGLException(e);
   }
   if (line == null) {
     return null;
   }
   if (datasize == 0) return null;
   byte[] bbuf = new byte[datasize];
   if (datasize != br.read(bbuf)) return null;
   ByteBuffer bb;
   bb = ByteBuffer.wrap(bbuf);
   bb.order(ByteOrder.LITTLE_ENDIAN); // MQOファイルのエンディアンはIntel形式
   FloatBuffer fb = bb.asFloatBuffer();
   ret = new KGLPoint[fb.limit() / 3];
   fb.position(0);
   float[] wf = new float[3];
   for (int i = 0; i < ret.length; i++) {
     fb.get(wf);
     ret[i] = KGLPoint.create(wf).scale(scale);
   }
   while ((line = br.readLine().trim()) != null) {
     if (line.equals("}")) break;
   }
   return ret;
 }
Beispiel #3
0
 public Buffer getUV() {
   float v[] = new float[uv.size()];
   for (int i = 0; i < uv.size(); i++) {
     v[i] = (uv.elementAt(i)).floatValue();
   }
   return FloatBuffer.wrap(v);
 }
Beispiel #4
0
 public Buffer getVertices() {
   float v[] = new float[points.size()];
   for (int i = 0; i < points.size(); i++) {
     v[i] = (points.elementAt(i)).floatValue();
   }
   return FloatBuffer.wrap(v);
 }
Beispiel #5
0
 public Buffer getNormals() {
   float v[] = new float[normals.size()];
   for (int i = 0; i < normals.size(); i++) {
     v[i] = (normals.elementAt(i)).floatValue();
   }
   return FloatBuffer.wrap(v);
 }
Beispiel #6
0
  @SuppressWarnings("unchecked")
  public Mesh(LinkedHashMap mesh, User user) {

    this.mesh = mesh;
    this.user = user;

    try {
      title = getStringFromHash(mesh, "title", "Some Object");

      ArrayList<Float> vs = new ArrayList<Float>(256);
      ArrayList<Float> ns = new ArrayList<Float>(256);
      ArrayList<Float> tp = new ArrayList<Float>(256);

      LinkedList verts = getListFromHash(mesh, "vertices");
      for (Object vert : verts) {
        vs.add(getFloatFromList(vert, 0, 0f));
        vs.add(getFloatFromList(vert, 1, 0f));
        vs.add(getFloatFromList(vert, 2, 0f));
      }
      LinkedList norms = getListFromHash(mesh, "normals");
      for (Object norm : norms) {
        ns.add(getFloatFromList(norm, 0, 0f));
        ns.add(getFloatFromList(norm, 1, 0f));
        ns.add(getFloatFromList(norm, 2, 0f));
      }
      LinkedList texts = getListFromHash(mesh, "texturepoints");
      for (Object text : texts) {
        tp.add(getFloatFromList(text, 0, 0f));
        tp.add(getFloatFromList(text, 1, 0f));
      }
      ArrayList<Float> vnt = new ArrayList<Float>(1024);
      ArrayList<Short> ind = new ArrayList<Short>(1024);
      short index = 0;
      LinkedList faces = getListFromHash(mesh, "faces");
      for (Object face : faces) {
        for (int i = 0; i < 3; i++) {
          String f = getStringFromList(face, i, "1/1/2");
          StringTokenizer st = new StringTokenizer(f, "/");
          int fv = Integer.parseInt(st.nextToken()) - 1;
          int ft = Integer.parseInt(st.nextToken()) - 1;
          int fn = Integer.parseInt(st.nextToken()) - 1;

          vnt.add(vs.get(fv * 3));
          vnt.add(vs.get(fv * 3 + 1));
          vnt.add(vs.get(fv * 3 + 2));

          vnt.add(ns.get(fn * 3));
          vnt.add(ns.get(fn * 3 + 1));
          vnt.add(ns.get(fn * 3 + 2));

          vnt.add(tp.get(ft * 2));
          vnt.add(tp.get(ft * 2 + 1));

          ind.add(index++);
        }
      }
      vnt.trimToSize();
      float[] va = new float[vnt.size()];
      for (int i = 0; i < vnt.size(); i++) va[i] = vnt.get(i);

      ind.trimToSize();
      short[] ia = new short[ind.size()];
      for (int i = 0; i < ind.size(); i++) ia[i] = ind.get(i);

      vb = ByteBuffer.allocateDirect(va.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
      vb.put(va).position(0);

      ib = ByteBuffer.allocateDirect(ia.length * 2).order(ByteOrder.nativeOrder()).asShortBuffer();
      ib.put(ia).position(0);

      il = ia.length;

      textures = getListFromHash(mesh, "textures");
      if (textures.size() == 0) textures = list("placeholder");
      vertexShader = user.shaders.get(getStringFromHash(mesh, "vertex-shader", ""));
      fragmentShader = user.shaders.get(getStringFromHash(mesh, "fragment-shader", ""));
      subObjects = getListFromHash(mesh, "sub-items");
      rotationX = getFloatFromList(getListFromHash(mesh, "rotation"), 0, 0f);
      rotationY = getFloatFromList(getListFromHash(mesh, "rotation"), 1, 0f);
      rotationZ = getFloatFromList(getListFromHash(mesh, "rotation"), 2, 0f);
      scaleX = getFloatFromList(getListFromHash(mesh, "scale"), 0, 1f);
      scaleY = getFloatFromList(getListFromHash(mesh, "scale"), 1, 1f);
      scaleZ = getFloatFromList(getListFromHash(mesh, "scale"), 2, 1f);
      lightR = getFloatFromList(getListFromHash(mesh, "light"), 0, 0f);
      lightG = getFloatFromList(getListFromHash(mesh, "light"), 1, 0f);
      lightB = getFloatFromList(getListFromHash(mesh, "light"), 2, 0f);

    } catch (Exception e) {
      e.printStackTrace();
      Log.e("Mesh Constructor", e.getLocalizedMessage());
      return;
    }
  }