void loadAndAddCollider(GVRContext gvrContext, String fname) throws IOException { GVRSceneObject model = gvrContext.getAssetLoader().loadModel(fname, gvrContext.getMainScene()); // This approach works fine for simple objects exported as FBX GVRSceneObject object = model.getChildByIndex(0).getChildByIndex(0); object.attachComponent(new GVRMeshCollider(object.getGVRContext(), true)); }
private GVRAnimator setupAnimation(GVRSceneObject root) { GVRSceneObject baseObject = mObjectRoot.getSceneObjectByName("Sloth_face"); GVRMeshMorph morph = (GVRMeshMorph)baseObject.getComponent(GVRMeshMorph.getComponentType()); int numBlendShapes = morph.getBlendShapeCount(); float [] keys = generateAnimationKeys(numBlendShapes, animDuration); GVRAnimator animator = (GVRAnimator) root.getComponent(GVRAnimator.getComponentType()); if (animator == null) { animator = new GVRAnimator(root.getGVRContext()); root.attachComponent(animator); } GVRMorphAnimation morphAnim = new GVRMorphAnimation(morph, keys, numBlendShapes + 1); animator.addAnimation(morphAnim); animator.setRepeatMode(GVRRepeatMode.PINGPONG); animator.setRepeatCount(1000); return animator; }
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; }