Rajawali-天空盒的使用

距离上一篇rajawali初探过去很久了,一直没有更过,直接进入正题

与很多引擎一样,rajawali给天空盒的运用封装了一层api,直接调用即可

首先我们需要明确rajawali的使用:activity 、surface、 render是必须要有的

在render中我们要继承RajawaliRenderer并重写initScene方法,基本上所有的3D场景中的东西都在这个方法中实现


这里我们在场景中创建了一个球体,并贴上了地球的材质贴图,然后通过

getCurrentScene().setSkybox方法传入六张天空盒贴图
 public void initScene(){
        Material material = new Material();
        material.enableLighting(true);
        material.setDiffuseMethod(new DiffuseMethod.Lambert());
        material.setColor(0);
        earthSphere = new Sphere(1, 24, 24);
        earthSphere.setMaterial(material);
        getCurrentScene().addChild(earthSphere);
        getCurrentCamera().setZ(4.2f);
        Texture earthTexture = new Texture("Earth", R.drawable.earthtruecolor_nasa_big);
        try{
            material.addTexture(earthTexture);

        } catch (ATexture.TextureException error){
            Log.d("DEBUG", "TEXTURE ERROR");
        }
        try {
            getCurrentScene().setSkybox(R.drawable.posx, R.drawable.negx,
                    R.drawable.posy, R.drawable.negy, R.drawable.posz, R.drawable.negz);
        } catch (ATexture.TextureException e) {
            e.printStackTrace();
        }
        directionalLight = new DirectionalLight(1f, .2f, -1.0f);
        directionalLight.setColor(1.0f, 1.0f, 1.0f);
        directionalLight.setPower(2);
        getCurrentScene().addLight(directionalLight);

    }

到此一个最基本的rajawali的3d场景搭建完毕。

项目下载地址:https://download.youkuaiyun.com/download/liuyizhou95/10289815






### Rajawali 3D Rendering Library for Android Rajawali 是一款专为 Android 平台设计的开源 3D 渲染库,基于 OpenGL ES 技术构建。它旨在简化开发者在移动设备上创建复杂 3D 图形的过程,提供了一套易于使用的 API 和工具集来处理场景管理、材质渲染以及动画效果等问题[^1]。 #### 主要特点 - **跨平台支持**:尽管主要针对 Android 开发,但由于其依赖于标准 OpenGL ES 接口,因此理论上也可以移植到其他支持该图形规范的操作系统之上。 - **丰富的功能集合**:除了基本几何体绘制外,还包含了灯光设置、阴影投射等功能模块;同时通过扩展插件机制可以进一步增强应用表现力。 - **高性能优化**:利用底层硬件加速能力,在保证视觉质量的同时尽可能减少资源消耗,适合用于游戏开发或者虚拟现实项目当中。 以下是使用 Rajawali 创建简单立方体的一个示例代码: ```java public class SimpleCubeRenderer extends RajawaliRenderer { private Object3D mCube; @Override protected void initScene() { DirectionalLight light = new DirectionalLight(-1, -0.5f, -1); getCurrentScene().addLight(light); Material material = new Material(); try { material.setColorInfluence(1); Texture texture = new Texture("cubeTex", R.drawable.cube_texture); material.addTexture(texture); } catch (ATexture.TextureException e) {} mCube = Primitive.getCube(2); // Create a cube with side length of 2 units. mCube.setMaterial(material); getCurrentScene().addChild(mCube); Camera camera = getCurrentCamera(); camera.setPosition(0, 0, 8); camera.lookAt(mCube.getPosition()); } } ``` 此段程序展示了如何定义一个带有纹理映射的基本三维物体,并将其放置在一个由方向光源照亮的空间环境中。 ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值