添加可点击的3d物体拉贾瓦利纸板



我正在尝试使用Rajawali Libraries向我的VR应用程序添加一个简单的球体对象。我的应用程序应该显示一个简单的视图(与RajawaliCardboardRenderer,一个具有图像纹理的球体)。问题是,我能不能简单地添加一个球体或者一个3d物体到这个球体上这个球体是可点击的?

下面是我的代码:

    public class MyRenderer extends RajawaliCardboardRenderer {
    private Sphere sphere,sphere2;
    public MyRenderer(Context context) {
        super(context);
    }
    @Override
    protected void initScene() {
        sphere = createPhotoSphereWithTexture(new Texture("photo", R.drawable.panorama));
        sphere2 = new Sphere(24,24,24);
        Material m = new Material();
        m.setColor(0);
        try {
            m.addTexture(new Texture("photo",R.drawable.zvirbloniu_parkas));
        } catch ( ATexture.TextureException e) {
            e.printStackTrace();
        }
        sphere2.setMaterial(m);

        getCurrentScene().addChild(sphere);
        getCurrentScene().addChild(sphere2);
        getCurrentCamera().setPosition(Vector3.ZERO);
        getCurrentCamera().setFieldOfView(100);
    }
    @Override
    protected void onRender(long ellapsedRealtime, double deltaTime) {
        super.onRender(ellapsedRealtime, deltaTime);
        sphere2.rotate(Vector3.Axis.Y, 1.0);
    }
    private static Sphere createPhotoSphereWithTexture(ATexture texture) {
        Material material = new Material();
        material.setColor(0);
        try {
            material.addTexture(texture);
        } catch (ATexture.TextureException e) {
            throw new RuntimeException(e);
        }
        Sphere sphere = new Sphere(50, 64, 32);
        sphere.setScaleX(-1);
        sphere.setMaterial(material);
        return sphere;
    }
}

不要看代码的形式,它写得很糟糕,没有遵循任何模式!

您需要将sphere2附加为"scenario"球体的子球体,以便在场景中显示它,如下所示:

 sphere = createPhotoSphereWithTexture(new Texture("photo", .drawable.panorama));
 sphere2 = new Sphere(24,24,24);
 ...
 sphere.addChild(sphere2);
 getCurrentScene().addChild(sphere);

Rajawali的对象选择机制将处理子对象。您可以将新球体直接添加到场景中,也可以将其作为子球体添加到照片球体中,任您选择。

最新更新