private GVRSceneObject getAsset(String[] meshes, String[] textures, boolean useMesh) { GVRSceneObject root = new GVRSceneObject(gvrContext); GVRMeshCollider collider = new GVRMeshCollider(gvrContext, true); collider.setMesh(meshMap.get(meshes[0])); root.setName(meshes[0]); root.attachCollider(collider); for (int state = SelectableBehavior.ObjectState.DEFAULT.ordinal(); state <= SelectableBehavior.ObjectState.CLICKED.ordinal(); ++state) { GVRMesh mesh = meshMap.get(meshes[state]); GVRSceneObject child = new GVRSceneObject(gvrContext, mesh); child.getRenderData().setMaterial(materialMap.get(textures[state])); child.setName(meshes[state]); root.addChildObject(child); } return root; }
private void addGroundMesh(GVRScene scene, float x, float y, float z, float mass) { try { GVRTexture texture = mGVRContext.getAssetLoader().loadTexture(new GVRAndroidResource(mGVRContext, "floor.jpg")); GVRSceneObject meshObject = new GVRSceneObject(mGVRContext, 100.0f, 100.0f, texture); meshObject.getTransform().setPosition(x, y, z); meshObject.getTransform().setRotationByAxis(-90.0f, 1.0f, 0.0f, 0.0f); // Collider GVRMeshCollider meshCollider = new GVRMeshCollider(mGVRContext, false); meshObject.attachCollider(meshCollider); // Physics body GVRRigidBody body = new GVRRigidBody(mGVRContext); body.setRestitution(0.5f); body.setFriction(1.0f); meshObject.attachComponent(body); scene.addSceneObject(meshObject); } catch (IOException exception) { Log.d("gvrf", exception.toString()); } }
private void addCube(GVRScene scene, float x, float y, float z, float mass) { GVRSceneObject cubeObject = meshWithTexture("cube.obj", "cube.jpg"); cubeObject.getTransform().setPosition(x, y, z); // Collider GVRBoxCollider boxCollider = new GVRBoxCollider(mGVRContext); boxCollider.setHalfExtents(0.5f, 0.5f, 0.5f); cubeObject.attachCollider(boxCollider); // Physics body GVRRigidBody body = new GVRRigidBody(mGVRContext, mass); body.setRestitution(0.5f); body.setFriction(1.0f); cubeObject.attachComponent(body); scene.addSceneObject(cubeObject); }
private void addSphere(GVRScene scene, float radius, float x, float y, float z, float mass) { GVRSceneObject sphereObject = meshWithTexture("sphere.obj", "sphere.jpg"); sphereObject.getTransform().setPosition(x, y, z); // Collider GVRSphereCollider sphereCollider = new GVRSphereCollider(mGVRContext); sphereCollider.setRadius(1.0f); sphereObject.attachCollider(sphereCollider); // Physics body mSphereRigidBody = new GVRRigidBody(mGVRContext, mass); mSphereRigidBody.setRestitution(1.5f); mSphereRigidBody.setFriction(0.5f); sphereObject.getEventReceiver().addListener(mCollisionHandler); sphereObject.attachComponent(mSphereRigidBody); scene.addSceneObject(sphereObject); }
public static GVRSceneObject createBall(GVRSceneObject ballProto, float x, float y, float z, float[] force) throws IOException { GVRContext context = ballProto.getGVRContext(); GVRSceneObject ballGeometry = new GVRSceneObject(context, ballProto.getRenderData().getMesh(), ballProto.getRenderData().getMaterial()); ballGeometry.getTransform().setScale(0.7f, 0.7f, 0.7f); ballGeometry.getTransform().setPosition(x, y, z); GVRSphereCollider sphereCollider = new GVRSphereCollider(context); sphereCollider.setRadius(1.0f); ballGeometry.attachCollider(sphereCollider); GVRRigidBody rigidBody = new GVRRigidBody(context, BALL_MASS, COLLISION_GROUP_BALL); rigidBody.setRestitution(1.5f); rigidBody.setFriction(0.5f); rigidBody.applyCentralForce(force[0], force[1], force[2]); ballGeometry.attachComponent(rigidBody); return ballGeometry; }
public static GVRSceneObject createCylinder(GVRContext context, float x, float y, float z, int drawable) throws IOException { GVRTexture texture = context.getAssetLoader().loadTexture(new GVRAndroidResource(context, drawable)); GVRMaterial mtl = new GVRMaterial(context, GVRMaterial.GVRShaderType.Phong.ID); GVRMesh mesh = context.getAssetLoader().loadMesh(new GVRAndroidResource(context, "cylinder.fbx")); GVRSceneObject cylinderObject = new GVRSceneObject(context, mesh, mtl); cylinderObject.getTransform().setPosition(x, y, z); cylinderObject.getTransform().setRotationByAxis(90.0f, 1.0f, 0.0f, 0.0f); mtl.setTexture("diffuseTexture", texture); // Collider GVRMeshCollider meshCollider = new GVRMeshCollider(context, false); cylinderObject.attachCollider(meshCollider); // Physics body GVRRigidBody body = new GVRRigidBody(context, CYLINDER_MASS, COLLISION_GROUP_CYLINDER); body.setRestitution(0.5f); body.setFriction(5.0f); cylinderObject.attachComponent(body); return cylinderObject; }
public static GVRSceneObject createGround(GVRContext context, float x, float y, float z) { GVRTexture texture = context.getAssetLoader().loadTexture(new GVRAndroidResource(context, R.drawable.orange)); GVRMaterial material = new GVRMaterial(context, GVRMaterial.GVRShaderType.Phong.ID); GVRSceneObject groundObject = new GVRCubeSceneObject(context, true, texture); groundObject.getRenderData().setMaterial(material); groundObject.getRenderData().getMaterial().setTexture("diffuseTexture", texture); groundObject.getRenderData().getMaterial().setMainTexture(texture); groundObject.getTransform().setScale(15.0f, 0.5f, 15.0f); groundObject.getTransform().setPosition(x, y, z); // Collider GVRMeshCollider meshCollider = new GVRMeshCollider(context, groundObject.getRenderData().getMesh()); groundObject.attachCollider(meshCollider); // Physics body GVRRigidBody body = new GVRRigidBody(context, 0.0f, COLLISION_GROUP_GROUND); body.setRestitution(0.5f); body.setFriction(1.0f); groundObject.attachComponent(body); return groundObject; }