@Override public void onInit(GVRContext gvrContext) throws IOException { mAnimationEngine = gvrContext.getAnimationEngine(); mMainScene = gvrContext.getNextMainScene( new Runnable() { @Override public void run() { for (GVRAnimation animation : mAnimations) { animation.start(mAnimationEngine); } mAnimations = null; } }); // Apply frustum culling mMainScene.setFrustumCulling(true); GVRCameraRig mainCameraRig = mMainScene.getMainCameraRig(); mainCameraRig.getLeftCamera().setBackgroundColor(Color.BLACK); mainCameraRig.getRightCamera().setBackgroundColor(Color.BLACK); mainCameraRig.getTransform().setPosition(0.0f, 0.0f, 0.0f); // Model with texture GVRSceneObject astroBoyModel = gvrContext.getAssimpModel("astro_boy.dae"); // Model with color GVRSceneObject benchModel = gvrContext.getAssimpModel("bench.dae"); ModelPosition astroBoyModelPosition = new ModelPosition(); astroBoyModelPosition.setPosition(0.0f, -0.4f, -0.5f); astroBoyModel.getTransform().setScale(3, 3, 3); astroBoyModel .getTransform() .setPosition(astroBoyModelPosition.x, astroBoyModelPosition.y, astroBoyModelPosition.z); astroBoyModel.getTransform().setRotationByAxis(180.0f, 0.0f, 1.0f, 0.0f); ModelPosition benchModelPosition = new ModelPosition(); benchModelPosition.setPosition(0.0f, -4.0f, -30.0f); benchModel .getTransform() .setPosition(benchModelPosition.x, benchModelPosition.y, benchModelPosition.z); benchModel.getTransform().setRotationByAxis(180.0f, 0.0f, 1.0f, 0.0f); mMainScene.addSceneObject(astroBoyModel); mMainScene.addSceneObject(benchModel); rotateModel(astroBoyModel, 10f, astroBoyModelPosition); }
/** * Constructor. * * @param gvrContext The GVR Context. * @param language The language of the script file. Please use the constants {@code LANG_*} * defined in {@link GVRScriptManager}, such as {@code LANG_LUA}, {@code LANG_JAVASCRIPT}, and * so on. */ public GVRScriptFile(GVRContext gvrContext, String language) { mGvrContext = gvrContext; mLanguage = language; // Get an engine because some impl. requires a new engine to // enforce context ScriptEngine engine = mGvrContext.getScriptManager().getEngine(mLanguage); mLocalEngine = engine.getFactory().getScriptEngine(); // Add globals mGvrContext.getScriptManager().addGlobalBindings(mLocalEngine); }
@Override public void onInit(GVRContext gvrContext) { this.gvrContext = gvrContext; random = new Random(); mainScene = gvrContext.getNextMainScene(); shaderManager = new CustomShaderManager(gvrContext); mainScene.getMainCameraRig().getLeftCamera().setBackgroundColor(1.0f, 1.0f, 1.0f, 1.0f); mainScene.getMainCameraRig().getRightCamera().setBackgroundColor(1.0f, 1.0f, 1.0f, 1.0f); addSurroundings(gvrContext, mainScene); // set up the input manager for the main scene GVRInputManager inputManager = gvrContext.getInputManager(); inputManager.addCursorControllerListener(this); for (GVRCursorController cursor : inputManager.getCursorControllers()) { onCursorControllerAdded(cursor); } // set the default text setTextOnMainThread(SELECT_TEXT); GVRViewSceneObject text = new GVRViewSceneObject(gvrContext, textView, gvrContext.createQuad(30.0f, 20.0f)); text.getTransform().setPosition(0.0f, 17.0f, -35.0f); text.getRenderData().setRenderingOrder(10002); mainScene.addSceneObject(text); GVRSceneObject cube1 = new Cube(gvrContext, "Cube 1", shaderManager); cube1.getTransform().setPosition(0.0f, 1.0f, -10.0f); mainScene.addSceneObject(cube1); // add the sensor to the cube addSensor(cube1); GVRSceneObject cube2 = new Cube(gvrContext, "Cube 2", shaderManager); cube2.getTransform().setPosition(0.0f, 1.0f, -12.0f); cube2.getTransform().rotateByAxisWithPivot(-15.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f); cube2.getTransform().setRotation(1.0f, 0.0f, 0.0f, 0.0f); mainScene.addSceneObject(cube2); // add the sensor to the cube addSensor(cube2); GVRSceneObject cube3 = new Cube(gvrContext, "Cube 3", shaderManager); cube3.getTransform().setPosition(0.0f, 1.0f, -15.0f); cube3.getTransform().rotateByAxisWithPivot(15.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f); cube3.getTransform().rotateByAxisWithPivot(15.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); cube3.getTransform().setRotation(1.0f, 0.0f, 0.0f, 0.0f); mainScene.addSceneObject(cube3); // add the sensor to the cube addSensor(cube3); }
// The assets for the Cubemap are taken from the Samsung Developers website: // http://www.samsung.com/us/samsungdeveloperconnection/developer-resources/ // gear-vr/apps-and-games/exercise-2-creating-the-splash-scene.html private void addSurroundings(GVRContext gvrContext, GVRScene scene) { FutureWrapper<GVRMesh> futureQuadMesh = new FutureWrapper<GVRMesh>(gvrContext.createQuad(CUBE_WIDTH, CUBE_WIDTH)); Future<GVRTexture> futureCubemapTexture = gvrContext.loadFutureCubemapTexture(new GVRAndroidResource(gvrContext, R.raw.earth)); GVRMaterial cubemapMaterial = new GVRMaterial(gvrContext, GVRMaterial.GVRShaderType.Cubemap.ID); cubemapMaterial.setMainTexture(futureCubemapTexture); // surrounding cube GVRSceneObject frontFace = new GVRSceneObject(gvrContext, futureQuadMesh, futureCubemapTexture); frontFace.getRenderData().setMaterial(cubemapMaterial); frontFace.setName("front"); scene.addSceneObject(frontFace); frontFace.getTransform().setPosition(0.0f, 0.0f, -CUBE_WIDTH * 0.5f); GVRSceneObject backFace = new GVRSceneObject(gvrContext, futureQuadMesh, futureCubemapTexture); backFace.getRenderData().setMaterial(cubemapMaterial); backFace.setName("back"); scene.addSceneObject(backFace); backFace.getTransform().setPosition(0.0f, 0.0f, CUBE_WIDTH * 0.5f); backFace.getTransform().rotateByAxis(180.0f, 0.0f, 1.0f, 0.0f); GVRSceneObject leftFace = new GVRSceneObject(gvrContext, futureQuadMesh, futureCubemapTexture); leftFace.getRenderData().setMaterial(cubemapMaterial); leftFace.setName("left"); scene.addSceneObject(leftFace); leftFace.getTransform().setPosition(-CUBE_WIDTH * 0.5f, 0.0f, 0.0f); leftFace.getTransform().rotateByAxis(90.0f, 0.0f, 1.0f, 0.0f); GVRSceneObject rightFace = new GVRSceneObject(gvrContext, futureQuadMesh, futureCubemapTexture); rightFace.getRenderData().setMaterial(cubemapMaterial); rightFace.setName("right"); scene.addSceneObject(rightFace); rightFace.getTransform().setPosition(CUBE_WIDTH * 0.5f, 0.0f, 0.0f); rightFace.getTransform().rotateByAxis(-90.0f, 0.0f, 1.0f, 0.0f); GVRSceneObject topFace = new GVRSceneObject(gvrContext, futureQuadMesh, futureCubemapTexture); topFace.getRenderData().setMaterial(cubemapMaterial); topFace.setName("top"); scene.addSceneObject(topFace); topFace.getTransform().setPosition(0.0f, CUBE_WIDTH * 0.5f, 0.0f); topFace.getTransform().rotateByAxis(90.0f, 1.0f, 0.0f, 0.0f); GVRSceneObject bottomFace = new GVRSceneObject(gvrContext, futureQuadMesh, futureCubemapTexture); bottomFace.getRenderData().setMaterial(cubemapMaterial); bottomFace.setName("bottom"); scene.addSceneObject(bottomFace); bottomFace.getTransform().setPosition(0.0f, -CUBE_WIDTH * 0.5f, 0.0f); bottomFace.getTransform().rotateByAxis(-90.0f, 1.0f, 0.0f, 0.0f); }
public CustomShaderManager(GVRContext gvrContext) { final GVRMaterialShaderManager shaderManager = gvrContext.getMaterialShaderManager(); shaderId = shaderManager.addShader(R.raw.vertex, R.raw.fragment); GVRMaterialMap customShader = shaderManager.getShaderMap(shaderId); customShader.addUniformVec3Key("u_color", COLOR_KEY); customShader.addTextureKey("u_texture", TEXTURE_KEY); }
private static synchronized GVRPostEffectShaderId getShaderId(GVRContext gvrContext) { if (shaderId == null) { GVRPostEffectShaderManager shaderManager = gvrContext.getPostEffectShaderManager(); shaderId = shaderManager.addShader(R.raw.posteffect_quad, R.raw.hud_console); shaderMap = shaderManager.getShaderMap(shaderId); shaderMap.addTextureKey("u_overlay", MAIN_TEXTURE); } return shaderId; }
private void setTextOnMainThread(final String text) { gvrContext .getActivity() .runOnUiThread( new Runnable() { @Override public void run() { textView.setText(text); } }); }
public Cube(GVRContext gvrContext, String name, CustomShaderManager shaderManager) { super(gvrContext, true); Future<GVRTexture> texture = gvrContext.loadFutureTexture(new GVRAndroidResource(gvrContext, R.raw.cube_texture)); GVRMaterial material = getRenderData().getMaterial(); material.setShaderType(shaderManager.getShaderId()); setColor(material, 0.7f, 0.7f, 0.7f); material.setTexture(CustomShaderManager.TEXTURE_KEY, texture); getTransform().setScale(2.0f, 2.0f, 2.0f); setName(name); }
static { GVRContext.addResetOnRestartHandler( new Runnable() { @Override public void run() { shaderId = null; // should be enough shaderMap = null; // can't hurt } }); }
private String enterLanguage(String language) { ScriptEngine engine = mGVRContext.getScriptManager().getEngine(language); if (engine == null) { return "Cannot find the language engine for " + language; } mScriptHandler = new ScriptHandler(mGVRContext, language, engine); mShell.setLineProcessor(mScriptHandler); return null; }
@Override public void onCursorControllerAdded(final GVRCursorController controller) { GVRSceneObject sceneObject = new GVRSceneObject(gvrContext); Future<GVRTexture> texture = gvrContext.loadFutureTexture(new GVRAndroidResource(gvrContext, R.raw.earthmap1k)); GVRMaterial material = new GVRMaterial(gvrContext, shaderManager.getShaderId()); // stay away from the darker colors for the cursor float r = random.nextFloat() / 2.0f + 0.5f; float g = random.nextFloat() / 2.0f + 0.5f; float b = random.nextFloat() / 2.0f + 0.5f; material.setVec3(CustomShaderManager.COLOR_KEY, r, g, b); material.setTexture(CustomShaderManager.TEXTURE_KEY, texture); material.setMainTexture(texture); Future<GVRMesh> futureCursorMesh = gvrContext.loadFutureMesh(new GVRAndroidResource(gvrContext, R.raw.cursor)); GVRRenderData cursorRenderData = new GVRRenderData(gvrContext); cursorRenderData.setMesh(futureCursorMesh); cursorRenderData.setMaterial(material); sceneObject.attachRenderData(cursorRenderData); mainScene.addSceneObject(sceneObject); controller.setSceneObject(sceneObject); // set the initial cursor position controller.setPosition( INITIAL_CURSOR_POSITION[0], INITIAL_CURSOR_POSITION[1], INITIAL_CURSOR_POSITION[2]); // set the min cursor depth controller.setNearDepth(NEAR_DEPTH); // set the max cursor depth controller.setFarDepth(FAR_DEPTH); }
public PhongShader2(GVRContext gvrContext) { final GVRMaterialShaderManager shaderManager = gvrContext.getMaterialShaderManager(); mShaderId = shaderManager.addShader(VERTEX_SHADER, FRAGMENT_SHADER); mCustomShader = shaderManager.getShaderMap(mShaderId); mCustomShader.addUniformVec4Key("u_color", COLOR_KEY); mCustomShader.addUniformVec3Key("u_light", LIGHT_KEY); mCustomShader.addUniformVec3Key("u_eye", EYE_KEY); mCustomShader.addUniformFloatKey("u_radius", RADIUS_KEY); mCustomShader.addTextureKey("intexture", TEXTURE_KEY); mCustomShader.addUniformVec4Key("u_mat1", MAT1_KEY); mCustomShader.addUniformVec4Key("u_mat2", MAT2_KEY); mCustomShader.addUniformVec4Key("u_mat3", MAT3_KEY); mCustomShader.addUniformVec4Key("u_mat4", MAT4_KEY); }
public Dashboard(GVRContext gvrContext, int gVRAndroidResourceTexture) { super( gvrContext, HIGHT, WIDTH, gvrContext.loadTexture(new GVRAndroidResource(gvrContext, gVRAndroidResourceTexture))); setName(SceneObjectNames.DASHBOARD); Dashboard.currentDashboardHashCode = this.hashCode(); originalRotationX = getTransform().getRotationX(); originalRotationY = getTransform().getRotationY(); originalRotationZ = getTransform().getRotationZ(); originalRotationW = getTransform().getRotationW(); attachEyePointeeHolder(); }
public TransparentButtonShaderThreeStates(GVRContext gvrContext) { final GVRMaterialShaderManager shaderManager = gvrContext.getMaterialShaderManager(); mShaderId = shaderManager.addShader(VERTEX_SHADER, FRAGMENT_SHADER); mCustomShader = shaderManager.getShaderMap(mShaderId); mCustomShader.addTextureKey("texture", TEXTURE_KEY); mCustomShader.addTextureKey("textureHover", TEXTURE_HOVER_KEY); mCustomShader.addTextureKey("textHoverTexture", TEXTURE_TEXT_HOVER_KEY); mCustomShader.addTextureKey("textUpperTexture", TEXTURE_TEXT_UPPER_KEY); mCustomShader.addTextureKey("textHoverUpperTexture", TEXTURE_TEXT_HOVER_UPPER_KEY); mCustomShader.addTextureKey(TEXTURE_TEXT_SPECIAL_KEY, TEXTURE_TEXT_SPECIAL_KEY); mCustomShader.addTextureKey(TEXTURE_TEXT_HOVER_SPECIAL_KEY, TEXTURE_TEXT_HOVER_SPECIAL_KEY); mCustomShader.addTextureKey("textTexture", TEXTURE_TEXT_KEY); mCustomShader.addUniformFloatKey("opacity", OPACITY); mCustomShader.addUniformFloatKey("textureSwitch", TEXTURE_SWITCH); }
private void processMouseEvent(float x, float y, float z, boolean active) { GVRScene scene = context.getMainScene(); if (scene != null) { float depth = this.z; if (((depth + z) <= getNearDepth()) && ((depth + z) >= getFarDepth())) { float frustumWidth, frustumHeight; depth = depth + z; // calculate the frustum using the aspect ratio and FOV // http://docs.unity3d.com/Manual/FrustumSizeAtDistance.html float aspectRatio = scene.getMainCameraRig().getCenterCamera().getAspectRatio(); float fovY = scene.getMainCameraRig().getCenterCamera().getFovY(); float frustumHeightMultiplier = (float) Math.tan(Math.toRadians(fovY / 2)) * 2.0f; frustumHeight = frustumHeightMultiplier * depth; frustumWidth = frustumHeight * aspectRatio; this.x = frustumWidth * -x; this.y = frustumHeight * -y; this.z = depth; } setActive(active); super.setPosition(this.x, this.y, this.z); } }
void close() { gvrContext.getInputManager().removeCursorControllerListener(this); }
private static double calculateScaleRateBasedOnCurrentNativeFontScale(GVRContext gvrContext) { float fontScale = gvrContext.getContext().getResources().getConfiguration().fontScale; return (fontScale / LARGEST_FONT_SCALE); }
@Override public void onInit(GVRContext gvrContext) { mGVRContext = gvrContext; mMetalOnlyShader = new MetalOnlyShader(mGVRContext); mDiffuseShader = new DiffuseShader(mGVRContext); mGlassShader = new GlassShader(mGVRContext); mReflectionShader = new ReflectionShader(mGVRContext); mPhongShader = new PhongShader(mGVRContext); mMetalShader2 = new MetalShader2(mGVRContext); mDiffuseShader2 = new DiffuseShader2(mGVRContext); mGlassShader2 = new GlassShader2(mGVRContext); mPhongShader2 = new PhongShader2(mGVRContext); mPhongShader3 = new PhongShader3(mGVRContext); GVRScene mainScene = mGVRContext.getNextMainScene(); mainScene.getMainCameraRig().getLeftCamera().setBackgroundColor(1.0f, 1.0f, 1.0f, 1.0f); mainScene.getMainCameraRig().getRightCamera().setBackgroundColor(1.0f, 1.0f, 1.0f, 1.0f); try { GVRTexture env_tex = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "env.jpg")); mReflectionMaterial = new GVRMaterial(mGVRContext, mReflectionShader.getShaderId()); mReflectionMaterial.setVec4(ReflectionShader.COLOR_KEY, 1.0f, 1.0f, 1.0f, 1.0f); mReflectionMaterial.setFloat(ReflectionShader.RADIUS_KEY, 10.0f); mReflectionMaterial.setTexture(ReflectionShader.TEXTURE_KEY, env_tex); // ------------------------------------------------------ set // materials // watch mMetalMaterial = new GVRMaterial(mGVRContext, mMetalOnlyShader.getShaderId()); mMetalMaterial.setVec4(MetalOnlyShader.COLOR_KEY, 1.7f, 1.4f, 1.0f, 1.0f); mMetalMaterial.setFloat(MetalOnlyShader.RADIUS_KEY, 10.0f); mMetalMaterial.setTexture(MetalOnlyShader.TEXTURE_KEY, env_tex); mGlassMaterial = new GVRMaterial(mGVRContext, mGlassShader.getShaderId()); mGlassMaterial.setVec4(GlassShader.COLOR_KEY, 1.0f, 1.0f, 1.0f, 1.0f); mGlassMaterial.setFloat(MetalOnlyShader.RADIUS_KEY, 10.0f); mGlassMaterial.setTexture(GlassShader.TEXTURE_KEY, env_tex); GVRTexture board_tex = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "watch/board.jpg")); mDiffuseMaterial = new GVRMaterial(mGVRContext, mDiffuseShader.getShaderId()); mDiffuseMaterial.setVec4(DiffuseShader.COLOR_KEY, 1.0f, 1.0f, 1.0f, 1.0f); mDiffuseMaterial.setTexture(DiffuseShader.TEXTURE_KEY, board_tex); // jar mPhongMaterial = new GVRMaterial(mGVRContext, mPhongShader.getShaderId()); mPhongMaterial.setVec4(PhongShader.COLOR_KEY, 1.2f, 1.2f, 1.3f, 1.0f); mPhongMaterial.setFloat(PhongShader.RADIUS_KEY, 10.0f); mPhongMaterial.setTexture(PhongShader.TEXTURE_KEY, env_tex); // car GVRTexture car_body_tex = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "car/body.jpg")); mCarBodyMaterial = new GVRMaterial(mGVRContext, mPhongShader3.getShaderId()); mCarBodyMaterial.setFloat(PhongShader3.RADIUS_KEY, 10.0f); mCarBodyMaterial.setTexture(PhongShader3.ENV_KEY, env_tex); mCarBodyMaterial.setTexture(PhongShader3.TEXTURE_KEY, car_body_tex); mCarWheelMaterial = new GVRMaterial(mGVRContext, mMetalShader2.getShaderId()); mCarWheelMaterial.setVec4(MetalShader2.COLOR_KEY, 1.2f, 1.2f, 1.2f, 1.0f); mCarWheelMaterial.setFloat(MetalShader2.RADIUS_KEY, 10.0f); mCarWheelMaterial.setTexture(MetalShader2.TEXTURE_KEY, env_tex); mCarGlassMaterial = new GVRMaterial(mGVRContext, mGlassShader2.getShaderId()); mCarGlassMaterial.setVec4(GlassShader2.COLOR_KEY, 1.0f, 1.0f, 1.0f, 1.0f); mCarGlassMaterial.setFloat(GlassShader2.RADIUS_KEY, 10.0f); mCarGlassMaterial.setTexture(GlassShader2.TEXTURE_KEY, env_tex); GVRTexture default_tex = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "car/default.bmp")); mCarTireMaterial = new GVRMaterial(mGVRContext, mDiffuseShader2.getShaderId()); mCarTireMaterial.setVec4(DiffuseShader2.COLOR_KEY, 0.1f, 0.1f, 0.1f, 1.0f); mCarTireMaterial.setTexture(DiffuseShader2.TEXTURE_KEY, default_tex); GVRTexture back_tex = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "car/back.jpg")); mCarBackMaterial = new GVRMaterial(mGVRContext, mDiffuseShader2.getShaderId()); mCarBackMaterial.setVec4(DiffuseShader2.COLOR_KEY, 1.0f, 1.0f, 1.0f, 1.0f); mCarBackMaterial.setTexture(DiffuseShader2.TEXTURE_KEY, back_tex); GVRTexture grill_tex = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "car/grill.jpg")); mCarGrillMaterial = new GVRMaterial(mGVRContext, mDiffuseShader2.getShaderId()); mCarGrillMaterial.setVec4(DiffuseShader2.COLOR_KEY, 1.0f, 1.0f, 1.0f, 1.0f); mCarGrillMaterial.setTexture(DiffuseShader2.TEXTURE_KEY, grill_tex); mCarLightMaterial = new GVRMaterial(mGVRContext, mGlassShader2.getShaderId()); mCarLightMaterial.setVec4(GlassShader2.COLOR_KEY, 2.5f, 2.5f, 2.5f, 1.0f); mCarLightMaterial.setFloat(GlassShader2.RADIUS_KEY, 10.0f); mCarLightMaterial.setTexture(GlassShader2.TEXTURE_KEY, env_tex); mCarInsideMaterial = new GVRMaterial(mGVRContext, mPhongShader2.getShaderId()); mCarInsideMaterial.setVec4(PhongShader2.COLOR_KEY, 0.0f, 0.0f, 0.0f, 1.0f); mCarInsideMaterial.setFloat(PhongShader2.RADIUS_KEY, 10.0f); mCarInsideMaterial.setTexture(PhongShader2.TEXTURE_KEY, env_tex); // robot GVRTexture robot_head_tex = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "robot/head.jpg")); mRobotHeadMaterial = new GVRMaterial(mGVRContext, mPhongShader3.getShaderId()); mRobotHeadMaterial.setFloat(PhongShader3.RADIUS_KEY, 10.0f); mRobotHeadMaterial.setTexture(PhongShader3.ENV_KEY, env_tex); mRobotHeadMaterial.setTexture(PhongShader3.TEXTURE_KEY, robot_head_tex); mRobotMetalMaterial = new GVRMaterial(mGVRContext, mMetalShader2.getShaderId()); mRobotMetalMaterial.setVec4(MetalShader2.COLOR_KEY, 1.5f, 1.5f, 1.5f, 1.0f); mRobotMetalMaterial.setFloat(MetalShader2.RADIUS_KEY, 10.0f); mRobotMetalMaterial.setTexture(MetalShader2.TEXTURE_KEY, env_tex); mRobotBodyMaterial = new GVRMaterial(mGVRContext, mPhongShader2.getShaderId()); mRobotBodyMaterial.setVec4(PhongShader2.COLOR_KEY, 1.0f, 1.0f, 1.0f, 1.0f); mRobotBodyMaterial.setFloat(PhongShader2.RADIUS_KEY, 10.0f); mRobotBodyMaterial.setTexture(PhongShader2.TEXTURE_KEY, env_tex); mRobotRubberMaterial = new GVRMaterial(mGVRContext, mDiffuseShader2.getShaderId()); mRobotRubberMaterial.setVec4(DiffuseShader2.COLOR_KEY, 0.3f, 0.3f, 0.3f, 1.0f); mRobotRubberMaterial.setTexture(DiffuseShader2.TEXTURE_KEY, default_tex); // leaf GVRTexture leaf_box_tex = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "leaf/box.jpg")); mLeafBoxMaterial = new GVRMaterial(mGVRContext, mPhongShader3.getShaderId()); mLeafBoxMaterial.setFloat(PhongShader3.RADIUS_KEY, 10.0f); mLeafBoxMaterial.setTexture(PhongShader3.ENV_KEY, env_tex); mLeafBoxMaterial.setTexture(PhongShader3.TEXTURE_KEY, leaf_box_tex); mLeafBodyMaterial = new GVRMaterial(mGVRContext, mMetalShader2.getShaderId()); mLeafBodyMaterial.setVec4(MetalShader2.COLOR_KEY, 2.5f, 2.5f, 2.5f, 1.0f); mLeafBodyMaterial.setFloat(MetalShader2.RADIUS_KEY, 10.0f); mLeafBodyMaterial.setTexture(MetalShader2.TEXTURE_KEY, env_tex); // ------------------------------------------------------ set // objects for (int i = 0; i < THUMBNAIL_NUM; i++) Objects[i] = new GVRSceneObject(mGVRContext); // --------------watch GVRSceneObject obj1 = new GVRSceneObject(mGVRContext); GVRRenderData renderData1 = new GVRRenderData(mGVRContext); GVRMesh mesh1 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "watch/frame.obj")); renderData1.setMesh(mesh1); renderData1.setMaterial(mMetalMaterial); obj1.attachRenderData(renderData1); Objects[2].addChildObject(obj1); GVRSceneObject obj2 = new GVRSceneObject(mGVRContext); GVRRenderData renderData2 = new GVRRenderData(mGVRContext); GVRMesh mesh2 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "watch/board.obj")); renderData2.setMesh(mesh2); renderData2.setMaterial(mDiffuseMaterial); obj2.attachRenderData(renderData2); Objects[2].addChildObject(obj2); GVRSceneObject obj3 = new GVRSceneObject(mGVRContext); GVRRenderData renderData3 = new GVRRenderData(mGVRContext); GVRMesh mesh3 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "watch/glass.obj")); renderData3.setMesh(mesh3); renderData3.setMaterial(mGlassMaterial); obj3.attachRenderData(renderData3); obj3.getRenderData().setRenderingOrder(3000); Objects[2].addChildObject(obj3); Objects[2].getTransform().setPosition(0.0f, 0.0f, -EYE_TO_OBJECT); mainScene.addSceneObject(Objects[2]); // --------------jar GVRSceneObject obj5 = new GVRSceneObject(mGVRContext); GVRRenderData renderData5 = new GVRRenderData(mGVRContext); GVRMesh mesh5 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "jar/jar.obj")); renderData5.setMesh(mesh5); renderData5.setMaterial(mPhongMaterial); obj5.attachRenderData(renderData5); Objects[1].addChildObject(obj5); GVRSceneObject obj4 = new GVRSceneObject(mGVRContext); GVRRenderData renderData4 = new GVRRenderData(mGVRContext); GVRMesh mesh4 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "jar/edge.obj")); renderData4.setMesh(mesh4); renderData4.setMaterial(mMetalMaterial); obj4.attachRenderData(renderData4); obj4.getRenderData().setRenderingOrder(3000); Objects[1].addChildObject(obj4); Objects[1].getTransform().setPosition(0.0f, 0.0f, -EYE_TO_OBJECT); mainScene.addSceneObject(Objects[1]); // --------------car GVRSceneObject obj6 = new GVRSceneObject(mGVRContext); GVRRenderData renderData6 = new GVRRenderData(mGVRContext); GVRMesh mesh6 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "car/body.obj")); renderData6.setMesh(mesh6); renderData6.setMaterial(mCarBodyMaterial); obj6.attachRenderData(renderData6); obj6.getRenderData().setCullTest(false); Objects[3].addChildObject(obj6); GVRSceneObject obj9 = new GVRSceneObject(mGVRContext); GVRRenderData renderData9 = new GVRRenderData(mGVRContext); GVRMesh mesh9 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "car/tire.obj")); renderData9.setMesh(mesh9); renderData9.setMaterial(mCarTireMaterial); obj9.attachRenderData(renderData9); Objects[3].addChildObject(obj9); GVRSceneObject obj10 = new GVRSceneObject(mGVRContext); GVRRenderData renderData10 = new GVRRenderData(mGVRContext); GVRMesh mesh10 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "car/glass.obj")); renderData10.setMesh(mesh10); renderData10.setMaterial(mCarGlassMaterial); obj10.attachRenderData(renderData10); obj10.getRenderData().setCullTest(false); obj10.getRenderData().setRenderingOrder(3000); Objects[3].addChildObject(obj10); GVRSceneObject obj11 = new GVRSceneObject(mGVRContext); GVRRenderData renderData11 = new GVRRenderData(mGVRContext); GVRMesh mesh11 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "car/wheel.obj")); renderData11.setMesh(mesh11); renderData11.setMaterial(mCarWheelMaterial); obj11.attachRenderData(renderData11); Objects[3].addChildObject(obj11); GVRSceneObject obj12 = new GVRSceneObject(mGVRContext); GVRRenderData renderData12 = new GVRRenderData(mGVRContext); GVRMesh mesh12 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "car/back.obj")); renderData12.setMesh(mesh12); renderData12.setMaterial(mCarBackMaterial); obj12.attachRenderData(renderData12); Objects[3].addChildObject(obj12); GVRSceneObject obj13 = new GVRSceneObject(mGVRContext); GVRRenderData renderData13 = new GVRRenderData(mGVRContext); GVRMesh mesh13 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "car/grill.obj")); renderData13.setMesh(mesh13); renderData13.setMaterial(mCarGrillMaterial); obj13.attachRenderData(renderData13); obj10.getRenderData().setRenderingOrder(3000); Objects[3].addChildObject(obj13); GVRSceneObject obj14 = new GVRSceneObject(mGVRContext); GVRRenderData renderData14 = new GVRRenderData(mGVRContext); GVRMesh mesh14 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "car/glass2.obj")); renderData14.setMesh(mesh14); renderData14.setMaterial(mCarLightMaterial); obj14.attachRenderData(renderData14); obj14.getRenderData().setRenderingOrder(4000); Objects[3].addChildObject(obj14); GVRSceneObject obj19 = new GVRSceneObject(mGVRContext); GVRRenderData renderData19 = new GVRRenderData(mGVRContext); GVRMesh mesh19 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "car/inside.obj")); renderData19.setMesh(mesh19); renderData19.setMaterial(mCarInsideMaterial); obj19.attachRenderData(renderData19); Objects[3].addChildObject(obj19); Objects[3].getTransform().setPosition(0.0f, -2.0f, -EYE_TO_OBJECT - 3.0f); mainScene.addSceneObject(Objects[3]); // robot GVRSceneObject obj15 = new GVRSceneObject(mGVRContext); GVRRenderData renderData15 = new GVRRenderData(mGVRContext); GVRMesh mesh15 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "robot/body.obj")); renderData15.setMesh(mesh15); renderData15.setMaterial(mRobotBodyMaterial); obj15.attachRenderData(renderData15); Objects[4].addChildObject(obj15); GVRSceneObject obj16 = new GVRSceneObject(mGVRContext); GVRRenderData renderData16 = new GVRRenderData(mGVRContext); GVRMesh mesh16 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "robot/head.obj")); renderData16.setMesh(mesh16); renderData16.setMaterial(mRobotHeadMaterial); obj16.attachRenderData(renderData16); Objects[4].addChildObject(obj16); GVRSceneObject obj17 = new GVRSceneObject(mGVRContext); GVRRenderData renderData17 = new GVRRenderData(mGVRContext); GVRMesh mesh17 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "robot/metal.obj")); renderData17.setMesh(mesh17); renderData17.setMaterial(mRobotMetalMaterial); obj17.attachRenderData(renderData17); obj17.getRenderData().setRenderingOrder(3000); Objects[4].addChildObject(obj17); GVRSceneObject obj18 = new GVRSceneObject(mGVRContext); GVRRenderData renderData18 = new GVRRenderData(mGVRContext); GVRMesh mesh18 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "robot/rubber.obj")); renderData18.setMesh(mesh18); renderData18.setMaterial(mRobotRubberMaterial); obj18.attachRenderData(renderData18); Objects[4].addChildObject(obj18); Objects[4].getTransform().setPosition(0.0f, 0.0f, -EYE_TO_OBJECT); mainScene.addSceneObject(Objects[4]); // leaf GVRSceneObject obj20 = new GVRSceneObject(mGVRContext); GVRRenderData renderData20 = new GVRRenderData(mGVRContext); GVRMesh mesh20 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "leaf/leaf.obj")); renderData20.setMesh(mesh20); renderData20.setMaterial(mLeafBodyMaterial); obj20.attachRenderData(renderData20); Objects[0].addChildObject(obj20); GVRSceneObject obj21 = new GVRSceneObject(mGVRContext); GVRRenderData renderData21 = new GVRRenderData(mGVRContext); GVRMesh mesh21 = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "leaf/box.obj")); renderData21.setMesh(mesh21); renderData21.setMaterial(mLeafBoxMaterial); obj21.attachRenderData(renderData21); Objects[0].addChildObject(obj21); Objects[0].getTransform().setPosition(0.0f, 0.0f, -EYE_TO_OBJECT); mainScene.addSceneObject(Objects[0]); for (int I = 0; I < THUMBNAIL_NUM; I++) for (int i = 0; i < Objects[I].getChildrenCount(); i++) Objects[I].getChildByIndex(i).getRenderData().setRenderMask(0); // ------------------------------------------------------ set // thumbnails ThumbnailTextures[0] = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "leaf/leaf.jpg")); ThumbnailTextures[1] = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "jar/jar.png")); ThumbnailTextures[2] = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "watch/watch.png")); ThumbnailTextures[3] = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "car/car.bmp")); ThumbnailTextures[4] = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "robot/robot.jpg")); ThumbnailTargetPosition[0][0] = -2.2f; ThumbnailTargetPosition[0][1] = 0.0f; ThumbnailTargetPosition[0][2] = -EYE_TO_OBJECT - 2.8f; ThumbnailTargetPosition[1][0] = -1.0f; ThumbnailTargetPosition[1][1] = 0.0f; ThumbnailTargetPosition[1][2] = -EYE_TO_OBJECT - 1.5f; ThumbnailTargetPosition[2][0] = 0.0f; ThumbnailTargetPosition[2][1] = 0.0f; ThumbnailTargetPosition[2][2] = -EYE_TO_OBJECT - 0.0f; ThumbnailTargetPosition[3][0] = 1.0f; ThumbnailTargetPosition[3][1] = 0.0f; ThumbnailTargetPosition[3][2] = -EYE_TO_OBJECT - 1.5f; ThumbnailTargetPosition[4][0] = 2.2f; ThumbnailTargetPosition[4][1] = 0.0f; ThumbnailTargetPosition[4][2] = -EYE_TO_OBJECT - 2.8f; for (int i = 0; i < THUMBNAIL_NUM; i++) for (int j = 0; j < 3; j++) ThumbnailCurrentPosition[i][j] = ThumbnailTargetPosition[i][j]; for (int i = 0; i < THUMBNAIL_NUM; i++) ThumbnailTargetIndex[i] = i; ThumbnailOrder[0] = 10000; ThumbnailOrder[1] = 10001; ThumbnailOrder[2] = 10002; ThumbnailOrder[3] = 10001; ThumbnailOrder[4] = 10000; GVRMesh glass_mesh = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "glass.obj")); GVRMesh board_mesh = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "board.obj")); GVRMesh picks_mesh = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "pick.obj")); for (int i = 0; i < THUMBNAIL_NUM; i++) { ThumbnailObject[i] = new GVRSceneObject(mGVRContext); ThumbnailRotation[i] = new GVRSceneObject(mGVRContext); GVRSceneObject obj = new GVRSceneObject(mGVRContext); ThumbnailGlasses[i] = new GVRRenderData(mGVRContext); ThumbnailGlasses[i].setMesh(glass_mesh); ThumbnailGlasses[i].setMaterial(mReflectionMaterial); obj.attachRenderData(ThumbnailGlasses[i]); obj.getRenderData().setRenderingOrder(ThumbnailOrder[i]); ThumbnailRotation[i].addChildObject(obj); ThumbnailObject[i].addChildObject(ThumbnailRotation[i]); Thumbnails[i] = new GVRSceneObject(mGVRContext, board_mesh, ThumbnailTextures[i]); Thumbnails[i].getRenderData().setRenderingOrder(ThumbnailOrder[i] - 100); Thumbnails[i].getRenderData().setCullTest(false); Thumbnails[i].getTransform().setScale(1.0f, 1.2f, 1.0f); ThumbnailRotation[i].addChildObject(Thumbnails[i]); ThumbnailObject[i] .getTransform() .setPosition( ThumbnailTargetPosition[i][0], ThumbnailTargetPosition[i][1], ThumbnailTargetPosition[i][2]); mainScene.addSceneObject(ThumbnailObject[i]); GVREyePointeeHolder eyePointeeHolder = new GVREyePointeeHolder(gvrContext); GVRMeshEyePointee eyePointee = new GVRMeshEyePointee(gvrContext, picks_mesh); eyePointeeHolder.addPointee(eyePointee); ThumbnailObject[i].attachEyePointeeHolder(eyePointeeHolder); } GVRTexture m360 = mGVRContext.loadTexture(new GVRAndroidResource(mGVRContext, "env.jpg")); GVRMesh sphere = mGVRContext.loadMesh(new GVRAndroidResource(mGVRContext, "sphere.obj")); GVRSceneObject env_object = new GVRSceneObject(mGVRContext, sphere, m360); env_object.getRenderData().setCullTest(false); mainScene.addSceneObject(env_object); GVRSceneObject headTracker = new GVRSceneObject( gvrContext, gvrContext.createQuad(0.1f, 0.1f), gvrContext.loadTexture( new GVRAndroidResource(mGVRContext, "Headtracking_pointer.png"))); headTracker.getTransform().setPosition(0.0f, 0.0f, -EYE_TO_OBJECT); headTracker.getRenderData().setDepthTest(false); headTracker.getRenderData().setRenderingOrder(100000); mainScene.getMainCameraRig().getOwnerObject().addChildObject(headTracker); } catch (IOException e) { e.printStackTrace(); mActivity.finish(); Log.e(TAG, "Assets were not loaded. Stopping application!"); } // activity was stored in order to stop the application if the mesh is // not loaded. Since we don't need anymore, we set it to null to reduce // chance of memory leak. mActivity = null; }
@Override public void onStep() { FPSCounter.tick(); boolean isButtonDown = mIsButtonDown; boolean isSingleTapped = mIsSingleTapped; mIsButtonDown = false; mIsSingleTapped = false; if (isButtonDown) mGVRContext.getMainScene().getMainCameraRig().resetYaw(); // ---------------------------------------thumbnail motion boolean MoveActive = false; if (Math.abs( ThumbnailTargetPosition[ThumbnailTargetIndex[0]][0] - ThumbnailCurrentPosition[0][0]) < 0.2f) MoveActive = true; if (SelectionActive && MoveActive) { if (ThumbnailCurrentPosition[ThumbnailSelected][0] < -0.5f) { for (int i = 0; i < THUMBNAIL_NUM; i++) { ThumbnailTargetIndex[i]++; if (ThumbnailTargetIndex[i] >= THUMBNAIL_NUM) ThumbnailTargetIndex[i] = ThumbnailTargetIndex[i] - THUMBNAIL_NUM; if (ThumbnailTargetIndex[i] < 0) ThumbnailTargetIndex[i] = ThumbnailTargetIndex[i] + THUMBNAIL_NUM; } } else if (ThumbnailCurrentPosition[ThumbnailSelected][0] > 0.5f) { for (int i = 0; i < THUMBNAIL_NUM; i++) { ThumbnailTargetIndex[i]--; if (ThumbnailTargetIndex[i] >= THUMBNAIL_NUM) ThumbnailTargetIndex[i] = ThumbnailTargetIndex[i] - THUMBNAIL_NUM; if (ThumbnailTargetIndex[i] < 0) ThumbnailTargetIndex[i] = ThumbnailTargetIndex[i] + THUMBNAIL_NUM; } } } for (int i = 0; i < THUMBNAIL_NUM; i++) { float speed = 0.08f; for (int j = 0; j < 3; j++) ThumbnailCurrentPosition[i][j] += speed * (ThumbnailTargetPosition[ThumbnailTargetIndex[i]][j] - ThumbnailCurrentPosition[i][j]); ThumbnailObject[i] .getTransform() .setPosition( ThumbnailCurrentPosition[i][0], ThumbnailCurrentPosition[i][1], ThumbnailCurrentPosition[i][2]); } // if( // Math.abs(ThumbnailTargetPosition[ThumbnailTargetIndex[0]][0]-ThumbnailCurrentPosition[0][0]) // > 0.02f ) // { // if( THUMBNAIL_ROT > 180.0f ) // THUMBNAIL_ROT += 0.05f*( 360.0f - THUMBNAIL_ROT ); // else // THUMBNAIL_ROT += 0.05f*( 0.0f - THUMBNAIL_ROT ); // } // else // { // THUMBNAIL_ROT += -1.0f; // if( THUMBNAIL_ROT > 360.0f ) THUMBNAIL_ROT = THUMBNAIL_ROT - 360.0f; // } THUMBNAIL_ROT = -1.0f; for (int i = 0; i < THUMBNAIL_NUM; i++) ThumbnailRotation[i].getTransform().rotateByAxis(THUMBNAIL_ROT, 0.0f, 1.0f, 0.0f); // ---------------------------------------object motion OBJECT_ROT = -1.0f; for (int i = 0; i < THUMBNAIL_NUM; i++) Objects[i].getTransform().rotateByAxis(OBJECT_ROT, 0.0f, 1.0f, 0.0f); float[] light = new float[4]; light[0] = 6.0f; light[1] = 10.0f; light[2] = 10.0f; light[3] = 1.0f; float[] eye = new float[4]; eye[0] = 0.0f; eye[1] = 0.0f; eye[2] = 3.0f * EYE_TO_OBJECT; eye[3] = 1.0f; float[] matT = ThumbnailRotation[0].getTransform().getModelMatrix(); float[] matO = Objects[ThumbnailSelected].getTransform().getModelMatrix(); // ---------------------------- watch, jar float x = matO[0] * light[0] + matO[1] * light[1] + matO[2] * light[2] + matO[3] * light[3]; float y = matO[4] * light[0] + matO[5] * light[1] + matO[6] * light[2] + matO[7] * light[3]; float z = matO[8] * light[0] + matO[9] * light[1] + matO[10] * light[2] + matO[11] * light[3]; float mag = (float) Math.sqrt(x * x + y * y + z * z); mMetalMaterial.setVec3(MetalOnlyShader.LIGHT_KEY, x / mag, y / mag, z / mag); mDiffuseMaterial.setVec3(DiffuseShader.LIGHT_KEY, x / mag, y / mag, z / mag); mGlassMaterial.setVec3(GlassShader.LIGHT_KEY, x / mag, y / mag, z / mag); mPhongMaterial.setVec3(PhongShader.LIGHT_KEY, x / mag, y / mag, z / mag); x = matO[0] * eye[0] + matO[1] * eye[1] + matO[2] * eye[2] + matO[3] * eye[3]; y = matO[4] * eye[0] + matO[5] * eye[1] + matO[6] * eye[2] + matO[7] * eye[3]; z = matO[8] * eye[0] + matO[9] * eye[1] + matO[10] * eye[2] + matO[11] * eye[3]; mag = (float) Math.sqrt(x * x + y * y + z * z); mMetalMaterial.setVec3(MetalOnlyShader.EYE_KEY, x / mag, y / mag, z / mag); mDiffuseMaterial.setVec3(DiffuseShader.EYE_KEY, x / mag, y / mag, z / mag); mGlassMaterial.setVec3(GlassShader.EYE_KEY, x / mag, y / mag, z / mag); mPhongMaterial.setVec3(PhongShader.EYE_KEY, x / mag, y / mag, z / mag); // ---------------------------- robot mRobotHeadMaterial.setVec4(PhongShader3.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mRobotHeadMaterial.setVec4(PhongShader3.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mRobotHeadMaterial.setVec4(PhongShader3.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mRobotHeadMaterial.setVec4(PhongShader3.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mRobotHeadMaterial.setVec3(PhongShader3.LIGHT_KEY, light[0], light[1], light[2]); mRobotHeadMaterial.setVec3(PhongShader3.EYE_KEY, eye[0], eye[1], eye[2]); mRobotMetalMaterial.setVec4(MetalShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mRobotMetalMaterial.setVec4(MetalShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mRobotMetalMaterial.setVec4(MetalShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mRobotMetalMaterial.setVec4(MetalShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mRobotMetalMaterial.setVec3(MetalShader2.LIGHT_KEY, light[0], light[1], light[2]); mRobotMetalMaterial.setVec3(MetalShader2.EYE_KEY, eye[0], eye[1], eye[2]); mRobotBodyMaterial.setVec4(PhongShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mRobotBodyMaterial.setVec4(PhongShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mRobotBodyMaterial.setVec4(PhongShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mRobotBodyMaterial.setVec4(PhongShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mRobotBodyMaterial.setVec3(PhongShader2.LIGHT_KEY, light[0], light[1], light[2]); mRobotBodyMaterial.setVec3(PhongShader2.EYE_KEY, eye[0], eye[1], eye[2]); mRobotRubberMaterial.setVec4(DiffuseShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mRobotRubberMaterial.setVec4(DiffuseShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mRobotRubberMaterial.setVec4(DiffuseShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mRobotRubberMaterial.setVec4(DiffuseShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mRobotRubberMaterial.setVec3(DiffuseShader2.LIGHT_KEY, light[0], light[1], light[2]); mRobotRubberMaterial.setVec3(DiffuseShader2.EYE_KEY, eye[0], eye[1], eye[2]); // ---------------------------- leaf mLeafBodyMaterial.setVec4(MetalShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mLeafBodyMaterial.setVec4(MetalShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mLeafBodyMaterial.setVec4(MetalShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mLeafBodyMaterial.setVec4(MetalShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mLeafBodyMaterial.setVec3(MetalShader2.LIGHT_KEY, light[0], light[1], light[2]); mLeafBodyMaterial.setVec3(MetalShader2.EYE_KEY, eye[0], eye[1], eye[2]); mLeafBoxMaterial.setVec4(PhongShader3.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mLeafBoxMaterial.setVec4(PhongShader3.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mLeafBoxMaterial.setVec4(PhongShader3.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mLeafBoxMaterial.setVec4(PhongShader3.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mLeafBoxMaterial.setVec3(PhongShader3.LIGHT_KEY, light[0], light[1], light[2]); mLeafBoxMaterial.setVec3(PhongShader3.EYE_KEY, eye[0], eye[1], eye[2]); // ---------------------------- car eye[0] = 4.0f; eye[1] = 0.0f; eye[2] = 3.0f * EYE_TO_OBJECT; eye[3] = 1.0f; mCarBodyMaterial.setVec4(PhongShader3.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarBodyMaterial.setVec4(PhongShader3.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarBodyMaterial.setVec4(PhongShader3.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarBodyMaterial.setVec4(PhongShader3.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarBodyMaterial.setVec3(PhongShader3.LIGHT_KEY, light[0], light[1], light[2]); mCarBodyMaterial.setVec3(PhongShader3.EYE_KEY, eye[0], eye[1], eye[2]); mCarTireMaterial.setVec4(DiffuseShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarTireMaterial.setVec4(DiffuseShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarTireMaterial.setVec4(DiffuseShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarTireMaterial.setVec4(DiffuseShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarTireMaterial.setVec3(DiffuseShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarTireMaterial.setVec3(DiffuseShader2.EYE_KEY, eye[0], eye[1], eye[2]); mCarGlassMaterial.setVec4(GlassShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarGlassMaterial.setVec4(GlassShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarGlassMaterial.setVec4(GlassShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarGlassMaterial.setVec4(GlassShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarGlassMaterial.setVec3(GlassShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarGlassMaterial.setVec3(GlassShader2.EYE_KEY, eye[0], eye[1], eye[2]); mCarWheelMaterial.setVec4(MetalShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarWheelMaterial.setVec4(MetalShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarWheelMaterial.setVec4(MetalShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarWheelMaterial.setVec4(MetalShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarWheelMaterial.setVec3(MetalShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarWheelMaterial.setVec3(MetalShader2.EYE_KEY, eye[0], eye[1], eye[2]); mCarBackMaterial.setVec4(DiffuseShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarBackMaterial.setVec4(DiffuseShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarBackMaterial.setVec4(DiffuseShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarBackMaterial.setVec4(DiffuseShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarBackMaterial.setVec3(DiffuseShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarBackMaterial.setVec3(DiffuseShader2.EYE_KEY, eye[0], eye[1], eye[2]); mCarGrillMaterial.setVec4(DiffuseShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarGrillMaterial.setVec4(DiffuseShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarGrillMaterial.setVec4(DiffuseShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarGrillMaterial.setVec4(DiffuseShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarGrillMaterial.setVec3(DiffuseShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarGrillMaterial.setVec3(DiffuseShader2.EYE_KEY, eye[0], eye[1], eye[2]); mCarLightMaterial.setVec4(GlassShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarLightMaterial.setVec4(GlassShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarLightMaterial.setVec4(GlassShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarLightMaterial.setVec4(GlassShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarLightMaterial.setVec3(GlassShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarLightMaterial.setVec3(GlassShader2.EYE_KEY, eye[0], eye[1], eye[2]); mCarInsideMaterial.setVec4(PhongShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarInsideMaterial.setVec4(PhongShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarInsideMaterial.setVec4(PhongShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarInsideMaterial.setVec4(PhongShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarInsideMaterial.setVec3(PhongShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarInsideMaterial.setVec3(PhongShader2.EYE_KEY, eye[0], eye[1], eye[2]); // ---------------------------- thumbnail glasses eye[0] = 0.0f; eye[1] = 0.0f; eye[2] = EYE_TO_OBJECT; eye[3] = 1.0f; mReflectionMaterial.setVec4(ReflectionShader.MAT1_KEY, matT[0], matT[4], matT[8], matT[12]); mReflectionMaterial.setVec4(ReflectionShader.MAT2_KEY, matT[1], matT[5], matT[9], matT[13]); mReflectionMaterial.setVec4(ReflectionShader.MAT3_KEY, matT[2], matT[6], matT[10], matT[14]); mReflectionMaterial.setVec4(ReflectionShader.MAT4_KEY, matT[3], matT[7], matT[11], matT[15]); mReflectionMaterial.setVec3(ReflectionShader.LIGHT_KEY, light[0], light[1], light[2]); mReflectionMaterial.setVec3(ReflectionShader.EYE_KEY, eye[0], eye[1], eye[2]); GVREyePointeeHolder pickedHolders[] = GVRPicker.pickScene(mGVRContext.getMainScene()); if (SelectionMode && pickedHolders.length > 0) { GVRSceneObject pickedObject = pickedHolders[0].getOwnerObject(); for (int i = 0; i < THUMBNAIL_NUM; ++i) if (ThumbnailObject[i].equals(pickedObject)) { ThumbnailSelected = i; break; } SelectionActive = true; } else SelectionActive = false; if (isSingleTapped) { SelectionMode = !SelectionMode; if (SelectionMode) { for (int i = 0; i < THUMBNAIL_NUM; ++i) { ThumbnailGlasses[i].setRenderMask(GVRRenderMaskBit.Left | GVRRenderMaskBit.Right); Thumbnails[i] .getRenderData() .setRenderMask(GVRRenderMaskBit.Left | GVRRenderMaskBit.Right); } for (int I = 0; I < THUMBNAIL_NUM; I++) for (int i = 0; i < Objects[I].getChildrenCount(); i++) Objects[I].getChildByIndex(i).getRenderData().setRenderMask(0); } else { for (int i = 0; i < THUMBNAIL_NUM; ++i) { ThumbnailGlasses[i].setRenderMask(0); Thumbnails[i].getRenderData().setRenderMask(0); } for (int I = 0; I < THUMBNAIL_NUM; I++) for (int i = 0; i < Objects[I].getChildrenCount(); i++) Objects[I].getChildByIndex(i).getRenderData().setRenderMask(0); for (int i = 0; i < Objects[ThumbnailSelected].getChildrenCount(); i++) Objects[ThumbnailSelected] .getChildByIndex(i) .getRenderData() .setRenderMask(GVRRenderMaskBit.Left | GVRRenderMaskBit.Right); } } }
/** * Create a console, specifying the initial eye mode. * * @param gvrContext The GVR context. * @param startMode The initial eye mode; you can change this <i>via</i> {@link * #setEyeMode(EyeMode)} */ public GVRConsole(GVRContext gvrContext, EyeMode startMode) { this(gvrContext, startMode, gvrContext.getMainScene()); }