FileDocCategorySizeDatePackage
Scene.javaAPI DocAndroid 5.1 API12907Thu Mar 12 22:22:44 GMT 2015com.android.scenegraph

Scene

public class Scene extends SceneGraphBase
hide

Fields Summary
private static String
TIMER_TAG
com.android.scenegraph.CompoundTransform
mRootTransforms
HashMap
mTransformMap
ArrayList
mRenderPasses
ArrayList
mLights
ArrayList
mCameras
ArrayList
mFragmentShaders
ArrayList
mVertexShaders
ArrayList
mRenderables
HashMap
mRenderableMap
ArrayList
mTextures
HashMap
mRenderableMeshMap
ScriptField_SgTransform
mTransformRSData
android.renderscript.RenderScriptGL
mRS
android.content.res.Resources
mRes
ScriptField_RenderPass_s
mRenderPassAlloc
Constructors Summary
public Scene()


      
        mRenderPasses = new ArrayList<RenderPass>();
        mLights = new ArrayList<LightBase>();
        mCameras = new ArrayList<Camera>();
        mFragmentShaders = new ArrayList<FragmentShader>();
        mVertexShaders = new ArrayList<VertexShader>();
        mRenderables = new ArrayList<RenderableBase>();
        mRenderableMap = new HashMap<String, RenderableBase>();
        mRenderableMeshMap = new HashMap<String, ArrayList<Renderable> >();
        mTextures = new ArrayList<Texture2D>();
        mRootTransforms = new CompoundTransform();
        mRootTransforms.setName("_scene_root_");
        mTransformMap = new HashMap<String, Transform>();
    
Methods Summary
private voidaddDrawables(android.renderscript.RenderScriptGL rs, android.content.res.Resources res, com.android.scenegraph.SceneManager sceneManager)

        Allocation drawableData = Allocation.createSized(rs,
                                                         Element.ALLOCATION(rs),
                                                         mRenderables.size());
        Allocation[] drawableAllocs = new Allocation[mRenderables.size()];
        for (int i = 0; i < mRenderables.size(); i ++) {
            Renderable dI = (Renderable)mRenderables.get(i);
            addToMeshMap(dI);
            drawableAllocs[i] = dI.getRsField(rs, res).getAllocation();
        }
        drawableData.copyFrom(drawableAllocs);
        sceneManager.mRenderLoop.set_gRenderableObjects(drawableData);

        initRenderPassRS(rs, sceneManager);
    
private voidaddShaders(android.renderscript.RenderScriptGL rs, android.content.res.Resources res, com.android.scenegraph.SceneManager sceneManager)

        if (mVertexShaders.size() > 0) {
            Allocation shaderData = Allocation.createSized(rs, Element.ALLOCATION(rs),
                                                           mVertexShaders.size());
            Allocation[] shaderAllocs = new Allocation[mVertexShaders.size()];
            for (int i = 0; i < mVertexShaders.size(); i ++) {
                VertexShader sI = mVertexShaders.get(i);
                shaderAllocs[i] = sI.getRSData().getAllocation();
            }
            shaderData.copyFrom(shaderAllocs);
            sceneManager.mRenderLoop.set_gVertexShaders(shaderData);
        }

        if (mFragmentShaders.size() > 0) {
            Allocation shaderData = Allocation.createSized(rs, Element.ALLOCATION(rs),
                                                           mFragmentShaders.size());
            Allocation[] shaderAllocs = new Allocation[mFragmentShaders.size()];
            for (int i = 0; i < mFragmentShaders.size(); i ++) {
                FragmentShader sI = mFragmentShaders.get(i);
                shaderAllocs[i] = sI.getRSData().getAllocation();
            }
            shaderData.copyFrom(shaderAllocs);
            sceneManager.mRenderLoop.set_gFragmentShaders(shaderData);
        }
    
voidaddToMeshMap(com.android.scenegraph.Renderable d)

        ArrayList<Renderable> entries = mRenderableMeshMap.get(d.mMeshName);
        if (entries == null) {
            entries = new ArrayList<Renderable>();
            mRenderableMeshMap.put(d.mMeshName, entries);
        }
        entries.add(d);
    
public voidaddToTransformMap(Transform t)

        mTransformMap.put(t.getName(), t);
    
public voidappendCamera(com.android.scenegraph.Camera c)

        if (c == null) {
            throw new RuntimeException("Adding null object");
        }
        mCameras.add(c);
    
public voidappendLight(LightBase l)

        if (l == null) {
            throw new RuntimeException("Adding null object");
        }
        mLights.add(l);
    
public com.android.scenegraph.CameraappendNewCamera()

        Camera c = new Camera();
        appendCamera(c);
        return c;
    
public com.android.scenegraph.CompoundTransformappendNewCompoundTransform()

        CompoundTransform t = new CompoundTransform();
        appendTransform(t);
        return t;
    
public MatrixTransformappendNewMatrixTransform()

        MatrixTransform t = new MatrixTransform();
        appendTransform(t);
        return t;
    
public com.android.scenegraph.RenderPassappendNewRenderPass()

        RenderPass p = new RenderPass();
        appendRenderPass(p);
        return p;
    
public com.android.scenegraph.RenderableappendNewRenderable()

        Renderable r = new Renderable();
        appendRenderable(r);
        return r;
    
public voidappendRenderPass(com.android.scenegraph.RenderPass p)

        if (p == null) {
            throw new RuntimeException("Adding null object");
        }
        mRenderPasses.add(p);
    
public voidappendRenderable(RenderableBase d)

        if (d == null) {
            throw new RuntimeException("Adding null object");
        }
        mRenderables.add(d);
        if (d.getName() != null) {
            mRenderableMap.put(d.getName(), d);
        }
    
public voidappendShader(FragmentShader f)

        if (f == null) {
            throw new RuntimeException("Adding null object");
        }
        mFragmentShaders.add(f);
    
public voidappendShader(VertexShader v)

        if (v == null) {
            throw new RuntimeException("Adding null object");
        }
        mVertexShaders.add(v);
    
public voidappendTextures(Texture2D tex)

        if (tex == null) {
            throw new RuntimeException("Adding null object");
        }
        mTextures.add(tex);
    
public voidappendTransform(Transform t)

        if (t == null) {
            throw new RuntimeException("Adding null object");
        }
        mRootTransforms.appendChild(t);
    
public voidassignRenderState(RenderState renderState)

        int numRenderables = mRenderables.size();
        for (int i = 0; i < numRenderables; i ++) {
            Renderable shape = (Renderable)mRenderables.get(i);
            shape.setRenderState(renderState);
        }
    
public voidassignRenderStateToMaterial(RenderState renderState, java.lang.String regex)

        Pattern pattern = Pattern.compile(regex);
        int numRenderables = mRenderables.size();
        for (int i = 0; i < numRenderables; i ++) {
            Renderable shape = (Renderable)mRenderables.get(i);
            Matcher m = pattern.matcher(shape.mMaterialName);
            if (m.find()) {
                shape.setRenderState(renderState);
            }
        }
    
public voidclearRenderPasses()

        mRenderPasses.clear();
    
public voiddestroyRS()

        SceneManager sceneManager = SceneManager.getInstance();
        mTransformRSData = null;
        sceneManager.mRenderLoop.bind_gRootNode(mTransformRSData);
        sceneManager.mRenderLoop.set_gRenderableObjects(null);
        mRenderPassAlloc = null;
        sceneManager.mRenderLoop.set_gRenderPasses(null);
        sceneManager.mRenderLoop.bind_gFrontToBack(null);
        sceneManager.mRenderLoop.bind_gBackToFront(null);
        sceneManager.mRenderLoop.set_gCameras(null);

        mTransformMap = null;
        mRenderPasses = null;
        mLights = null;
        mCameras = null;
        mRenderables = null;
        mRenderableMap = null;
        mTextures = null;
        mRenderableMeshMap = null;
        mRootTransforms = null;
    
public java.util.ArrayListgetCameras()

        return mCameras;
    
public java.util.ArrayListgetLights()

        return mLights;
    
public RenderableBasegetRenderableByName(java.lang.String name)

        return mRenderableMap.get(name);
    
public java.util.ArrayListgetRenderables()

        return mRenderables;
    
public TransformgetTransformByName(java.lang.String name)

        return mTransformMap.get(name);
    
public voidinitRS()

        SceneManager sceneManager = SceneManager.getInstance();
        mRS = SceneManager.getRS();
        mRes = SceneManager.getRes();
        long start = System.currentTimeMillis();
        mTransformRSData = mRootTransforms.getRSData();
        long end = System.currentTimeMillis();
        Log.v(TIMER_TAG, "Transform init time: " + (end - start));

        start = System.currentTimeMillis();

        sceneManager.mRenderLoop.bind_gRootNode(mTransformRSData);
        end = System.currentTimeMillis();
        Log.v(TIMER_TAG, "Script init time: " + (end - start));

        start = System.currentTimeMillis();
        addDrawables(mRS, mRes, sceneManager);
        end = System.currentTimeMillis();
        Log.v(TIMER_TAG, "Renderable init time: " + (end - start));

        addShaders(mRS, mRes, sceneManager);

        Allocation opaqueBuffer = null;
        if (mRenderables.size() > 0) {
            opaqueBuffer = Allocation.createSized(mRS, Element.U32(mRS), mRenderables.size());
        }
        Allocation transparentBuffer = null;
        if (mRenderables.size() > 0) {
            transparentBuffer = Allocation.createSized(mRS, Element.U32(mRS), mRenderables.size());
        }

        sceneManager.mRenderLoop.bind_gFrontToBack(opaqueBuffer);
        sceneManager.mRenderLoop.bind_gBackToFront(transparentBuffer);

        if (mCameras.size() > 0) {
            Allocation cameraData;
            cameraData = Allocation.createSized(mRS, Element.ALLOCATION(mRS), mCameras.size());
            Allocation[] cameraAllocs = new Allocation[mCameras.size()];
            for (int i = 0; i < mCameras.size(); i ++) {
                cameraAllocs[i] = mCameras.get(i).getRSData().getAllocation();
            }
            cameraData.copyFrom(cameraAllocs);
            sceneManager.mRenderLoop.set_gCameras(cameraData);
        }

        if (mLights.size() > 0) {
            Allocation lightData = Allocation.createSized(mRS,
                                                          Element.ALLOCATION(mRS),
                                                          mLights.size());
            Allocation[] lightAllocs = new Allocation[mLights.size()];
            for (int i = 0; i < mLights.size(); i ++) {
                lightAllocs[i] = mLights.get(i).getRSData().getAllocation();
            }
            lightData.copyFrom(lightAllocs);
            sceneManager.mRenderLoop.set_gLights(lightData);
        }
    
public voidinitRenderPassRS(android.renderscript.RenderScriptGL rs, com.android.scenegraph.SceneManager sceneManager)

        if (mRenderPasses.size() != 0) {
            mRenderPassAlloc = new ScriptField_RenderPass_s(mRS, mRenderPasses.size());
            for (int i = 0; i < mRenderPasses.size(); i ++) {
                mRenderPassAlloc.set(mRenderPasses.get(i).getRsField(mRS, mRes), i, false);
            }
            mRenderPassAlloc.copyAll();
            sceneManager.mRenderLoop.set_gRenderPasses(mRenderPassAlloc.getAllocation());
        }
    
public voidmeshLoaded(android.renderscript.Mesh m)

        ArrayList<Renderable> entries = mRenderableMeshMap.get(m.getName());
        int numEntries = entries.size();
        for (int i = 0; i < numEntries; i++) {
            Renderable d = entries.get(i);
            d.resolveMeshData(m);
        }