@Override public ScriptC createScript() { ProgramFragmentFixedFunction.Builder pfb = new ProgramFragmentFixedFunction.Builder( getRS()); pfb.setVaryingColor(true); getRS().bindProgramFragment(pfb.create()); ScriptField_Snow snow = new ScriptField_Snow(mRS, SNOW_FLAKES); Mesh.AllocationBuilder smb = new Mesh.AllocationBuilder(mRS); smb.addVertexAllocation(snow.getAllocation()); smb.addIndexSetType(Mesh.Primitive.POINT); Mesh sm = smb.create(); mScript = new ScriptC_snow(mRS, getResources(), R.raw.snow); mScript.set_snowMesh(sm); mScript.bind_snow(snow); mScript.invoke_initSnow(); return mScript; }
/** * Loads geometry from a resource id. * * @param resId * @return the loaded mesh or null if it cannot be loaded */ public Mesh loadGeometry(int resId) { if (mRenderScript != null) { return mRenderScript.loadGeometry(resId); } return null; }
/** * Load A3D file from resource. If resId == 0, will clear geometry for this item. * @param n The card to set the geometry for * @param resId The resource ID for the geometry for that item * @see {@link #setDefaultGeometry} */ public void setGeometryForItem(int n, int resId) { if (mRenderScript != null) { Mesh mesh = mRenderScript.loadGeometry(resId); mRenderScript.setGeometry(n, mesh); } }
@Override public void handleMessage(Message msg) { int id = msg.arg1; if (id >= mCarouselView.getCardCount()) { Log.e(TAG, "Index out of range for set, card:" + id); return; } switch (msg.what) { case SET_TEXTURE_N: mCarouselView.setTextureForItem(id, (Bitmap) msg.obj); break; case SET_DETAIL_TEXTURE_N: DetailTextureParameters params = getDetailTextureParameters(id); float x = params != null ? params.textureOffsetX : 0.0f; float y = params != null ? params.textureOffsetY : 0.0f; float lx = params != null ? params.lineOffsetX : 0.0f; float ly = params != null ? params.lineOffsetY : 0.0f; mCarouselView.setDetailTextureForItem(id, x, y, lx, ly, (Bitmap) msg.obj); break; case SET_GEOMETRY_N: mCarouselView.setGeometryForItem(id, (Mesh) msg.obj); break; case SET_MATRIX_N: mCarouselView.setMatrixForItem(id, (float[]) msg.obj); break; } }
public void init(RenderScriptGL rs, Resources res, int width, int height) { mRS = rs; mRes = res; ProgramFragmentFixedFunction.Builder pfb = new ProgramFragmentFixedFunction.Builder(rs); pfb.setPointSpriteTexCoordinateReplacement(true); pfb.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE, ProgramFragmentFixedFunction.Builder.Format.RGBA, 0); pfb.setVaryingColor(true); mPFPoints = pfb.create(); pfb = new ProgramFragmentFixedFunction.Builder(rs); pfb.setVaryingColor(true); mPFLines = pfb.create(); android.util.Log.e("rs", "Load texture"); mPFPoints.bindTexture(loadTexture(R.drawable.flares), 0); mPoints = new ScriptField_Point(mRS, PART_COUNT, Allocation.USAGE_SCRIPT); Mesh.AllocationBuilder smb = new Mesh.AllocationBuilder(mRS); smb.addVertexAllocation(mPoints.getAllocation()); smb.addIndexSetType(Mesh.Primitive.POINT); Mesh smP = smb.create(); mPhysicsScript = new ScriptC_ball_physics(mRS, mRes, R.raw.ball_physics); mScript = new ScriptC_balls(mRS, mRes, R.raw.balls); mScript.set_partMesh(smP); mScript.set_physics_script(mPhysicsScript); mScript.bind_point(mPoints); mScript.bind_balls1(new ScriptField_Ball(mRS, PART_COUNT, Allocation.USAGE_SCRIPT)); mScript.bind_balls2(new ScriptField_Ball(mRS, PART_COUNT, Allocation.USAGE_SCRIPT)); mScript.set_gPFLines(mPFLines); mScript.set_gPFPoints(mPFPoints); createProgramVertex(); mRS.bindProgramStore(BLEND_ADD_DEPTH_NONE(mRS)); mPhysicsScript.set_gMinPos(new Float2(5, 5)); mPhysicsScript.set_gMaxPos(new Float2(width - 5, height - 5)); mScript.invoke_initParts(width, height); mRS.bindRootScript(mScript); }
/** * This geometry will be shown when no geometry has been loaded for a given slot. If not set, * a quad will be drawn in its place. It is shared for all cards. If something other than * simple planar geometry is used, consider enabling depth test with * {@link CarouselController#setForceBlendCardsWithZ(boolean)} * * @param mesh */ public void setDefaultGeometry(int resId) { mDefaultGeometry = resId; if (mRenderScript != null) { Mesh mesh = mRenderScript.loadGeometry(resId); mRenderScript.setDefaultGeometry(mesh); } }
/** * This is an intermediate version of the object to show while geometry is loading. If not set, * a quad will be drawn in its place. It is shared for all cards. If something other than * simple planar geometry is used, consider enabling depth test with * {@link CarouselView#setForceBlendCardsWithZ(boolean)} * * @param resId */ public void setLoadingGeometry(int resId) { mLoadingGeometry = resId; if (mRenderScript != null) { Mesh mesh = mRenderScript.loadGeometry(resId); mRenderScript.setLoadingGeometry(mesh); } }
/** * Loads geometry from a resource id. * * @param resId * @return the loaded mesh or null if it cannot be loaded */ public Mesh loadGeometry(int resId) { return mController.loadGeometry(resId); }
/** * Set the geometry for a given item. * @param n * @param mesh */ public void setGeometryForItem(int n, Mesh mesh) { mController.setGeometryForItem(n, mesh); }
/** * Set the geometry to show for a given slot. * @param n The card to set the geometry for * @param mesh The geometry for that item * @see {@link #setDefaultGeometry} */ public void setGeometryForItem(int n, Mesh mesh) { if (mRenderScript != null) { mRenderScript.setGeometry(n, mesh); } }
/** * Implement this method if you want to load geometry for the given card. Most subclasses * will implement this. Note: this will generally <b>not</b> be called in the UI thread, * so proper locking should be ensured. * * @param id * @return */ public Mesh getGeometry(int id) { return null; }