FileDocCategorySizeDatePackage
Object3D.javaAPI DocAndroid 1.5 API6935Wed May 06 22:42:00 BST 2009android.opengl

Object3D

public abstract class Object3D extends Object
{@hide}

Fields Summary
private boolean
mHasTexcoords
private float
mBoundsMinX
private float
mBoundsMaxX
private float
mBoundsMinY
private float
mBoundsMaxY
private float
mBoundsMinZ
private float
mBoundsMaxZ
private IntBuffer
mVertexBuffer
private IntBuffer
mNormalBuffer
private IntBuffer
mTexcoordBuffer
private Map
mGroups
private Map
mMaterials
private Map
mTextures
Constructors Summary
public Object3D()


      
        reset();
    
Methods Summary
public voiddraw(GL10 gl)

        Iterator<Group> iter = mGroups.values().iterator();
        while (iter.hasNext()) {
            iter.next().draw(gl);
        }
    
public floatgetBoundsMaxX()

        return mBoundsMaxX;
    
public floatgetBoundsMaxY()

        return mBoundsMaxY;
    
public floatgetBoundsMaxZ()

        return mBoundsMaxZ;
    
public floatgetBoundsMinX()

        return mBoundsMinX;
    
public floatgetBoundsMinY()

        return mBoundsMinY;
    
public floatgetBoundsMinZ()

        return mBoundsMinZ;
    
public MaterialgetMaterial(java.lang.String name)

        Material mat = mMaterials.get(name);
        return mat;
    
public java.nio.IntBuffergetNormalBuffer()

        return mNormalBuffer;
    
public intgetNumTriangles()

        int numTriangles = 0;
        Iterator<Group> iter = mGroups.values().iterator();
        while (iter.hasNext()) {
            numTriangles += iter.next().getNumTriangles();
        }
        return numTriangles;
    
public java.nio.IntBuffergetTexcoordBuffer()

        return mTexcoordBuffer;
    
public TexturegetTexture(java.lang.String name)

        return mTextures.get(name);
    
public java.nio.IntBuffergetVertexBuffer()

        return mVertexBuffer;
    
public booleanhasTexcoords()

        return mHasTexcoords;
    
public voidload(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 voidloadTexture(java.lang.String name)

        InputStream is = readFile(name + ".raw");
        Texture texture = new Texture(is);
        mTextures.put(name, texture);
    
public abstract java.io.InputStreamreadFile(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 voidreset()

        mVertexBuffer = mNormalBuffer = mTexcoordBuffer = null;

        mGroups = new HashMap<String,Group>();
        mMaterials = new HashMap<String,Material>();
        mTextures = new HashMap<String,Texture>();
    
private static voidverifyByte(java.io.DataInputStream dis, int b)

        int x = dis.read() & 0xff;
        if (x != b) {
            throw new RuntimeException("Bad byte: " +
                    x +
                    " (expected " + b + ")");
        }