Untitled

mail@pastecode.io avatar
unknown
plain_text
23 days ago
1.8 kB
2
Indexable
Never
dependencies {
    implementation 'org.rajawali3d:rajawali:1.1.970'
}


import org.rajawali3d.renderer.RajawaliRenderer;
import org.rajawali3d.materials.Material;
import org.rajawali3d.materials.textures.Texture;
import org.rajawali3d.primitives.Object3D;
import org.rajawali3d.loader.LoaderOBJ;
import org.rajawali3d.loader.ParsingException;
import org.rajawali3d.scene.Scene;
import android.content.Context;

public class MyRenderer extends RajawaliRenderer {

    private Object3D mObject;

    public MyRenderer(Context context) {
        super(context);
    }

    @Override
    protected void initScene() {
        try {
            LoaderOBJ objParser = new LoaderOBJ(mContext.getResources(), mTextureManager, R.raw.your_obj_file);
            objParser.parse();
            mObject = objParser.getParsedObject();
            Material material = new Material();
            material.enableLighting(true);
            mObject.setMaterial(material);
            getCurrentScene().addChild(mObject);
        } catch (ParsingException e) {
            e.printStackTrace();
        }
        getCurrentCamera().setPosition(0, 0, 7);
        getCurrentCamera().setLookAt(0, 0, 0);
    }
}


import android.app.Activity;
import android.os.Bundle;
import org.rajawali3d.view.SurfaceView;

public class MainActivity extends Activity {

    private MyRenderer mRenderer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SurfaceView surface = new SurfaceView(this);
        surface.setFrameRate(60.0);
        surface.setRenderMode(ISurface.RENDERMODE_CONTINUOUSLY);

        mRenderer = new MyRenderer(this);
        surface.setSurfaceRenderer(mRenderer);

        setContentView(surface);
    }
}
Leave a Comment