Methods Summary |
---|
public void | draw(GL10 gl)
Iterator<Group> iter = mGroups.values().iterator();
while (iter.hasNext()) {
iter.next().draw(gl);
}
|
public float | getBoundsMaxX()
return mBoundsMaxX;
|
public float | getBoundsMaxY()
return mBoundsMaxY;
|
public float | getBoundsMaxZ()
return mBoundsMaxZ;
|
public float | getBoundsMinX()
return mBoundsMinX;
|
public float | getBoundsMinY()
return mBoundsMinY;
|
public float | getBoundsMinZ()
return mBoundsMinZ;
|
public Material | getMaterial(java.lang.String name)
Material mat = mMaterials.get(name);
return mat;
|
public java.nio.IntBuffer | getNormalBuffer()
return mNormalBuffer;
|
public int | getNumTriangles()
int numTriangles = 0;
Iterator<Group> iter = mGroups.values().iterator();
while (iter.hasNext()) {
numTriangles += iter.next().getNumTriangles();
}
return numTriangles;
|
public java.nio.IntBuffer | getTexcoordBuffer()
return mTexcoordBuffer;
|
public Texture | getTexture(java.lang.String name)
return mTextures.get(name);
|
public java.nio.IntBuffer | getVertexBuffer()
return mVertexBuffer;
|
public boolean | hasTexcoords()
return mHasTexcoords;
|
public void | load(java.lang.String filename)
reset();
DataInputStream dis = new DataInputStream(readFile(filename));
verifyByte(dis, 'g" + 128);
verifyByte(dis, 'l");
verifyByte(dis, 'e");
verifyByte(dis, 's");
int numTuples = dis.readInt();
this.mBoundsMinX = dis.readFloat();
this.mBoundsMaxX = dis.readFloat();
this.mBoundsMinY = dis.readFloat();
this.mBoundsMaxY = dis.readFloat();
this.mBoundsMinZ = dis.readFloat();
this.mBoundsMaxZ = dis.readFloat();
this.mHasTexcoords = dis.readInt() == 1;
int intsPerTuple = mHasTexcoords ? 8 : 6;
int numInts = numTuples*intsPerTuple;
int len = 4*numTuples*(mHasTexcoords ? 8 : 6);
byte[] tmp = new byte[len];
int tidx = 0;
while (tidx < len) {
tidx += dis.read(tmp, tidx, len - tidx);
}
if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
for (int i = 0; i < len; i += 4) {
byte tmp0 = tmp[i];
byte tmp1 = tmp[i + 1];
byte tmp2 = tmp[i + 2];
byte tmp3 = tmp[i + 3];
tmp[i] = tmp3;
tmp[i + 1] = tmp2;
tmp[i + 2] = tmp1;
tmp[i + 3] = tmp0;
}
}
ByteBuffer allbb = ByteBuffer.allocateDirect(len);
allbb.order(ByteOrder.nativeOrder());
allbb.put(tmp);
allbb.position(0);
allbb.limit(4*3*numTuples);
ByteBuffer vbb = allbb.slice();
this.mVertexBuffer = vbb.asIntBuffer();
mVertexBuffer.position(0);
if (mHasTexcoords) {
allbb.position(allbb.limit());
allbb.limit(allbb.position() + 4*2*numTuples);
ByteBuffer tbb = allbb.slice();
this.mTexcoordBuffer = tbb.asIntBuffer();
mTexcoordBuffer.position(0);
}
allbb.position(allbb.limit());
allbb.limit(allbb.position() + 4*3*numTuples);
ByteBuffer nbb = allbb.slice();
this.mNormalBuffer = nbb.asIntBuffer();
mNormalBuffer.position(0);
int numMaterials = dis.readInt();
for (int i = 0; i < numMaterials; i++) {
Material mat = new Material(this);
mat.load(dis);
mMaterials.put(mat.getName(), mat);
}
int numGroups = dis.readInt();
for (int i = 0; i < numGroups; i++) {
Group g = new Group(this);
g.load(dis);
mGroups.put(g.getName(), g);
}
|
public void | loadTexture(java.lang.String name)
InputStream is = readFile(name + ".raw");
Texture texture = new Texture(is);
mTextures.put(name, texture);
|
public abstract java.io.InputStream | readFile(java.lang.String filename)Override this method with an implementation that contructs
and InputStream from the given filename. For example, if the
source files are to be retrieved using an AssetManager,
the implementation would use AssetManager.load() to
get the input stream.
|
private void | reset()
mVertexBuffer = mNormalBuffer = mTexcoordBuffer = null;
mGroups = new HashMap<String,Group>();
mMaterials = new HashMap<String,Material>();
mTextures = new HashMap<String,Texture>();
|
private static void | verifyByte(java.io.DataInputStream dis, int b)
int x = dis.read() & 0xff;
if (x != b) {
throw new RuntimeException("Bad byte: " +
x +
" (expected " + b + ")");
}
|