Skip to content

Commit

Permalink
rajawali 3D renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
RivoLink committed Mar 23, 2020
1 parent 5f6a258 commit 785021c
Show file tree
Hide file tree
Showing 7 changed files with 1,984 additions and 14 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {

defaultConfig {
applicationId "mg.rivolink.app.aruco"
minSdkVersion 8
targetSdkVersion 8
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
Expand All @@ -22,4 +22,5 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':opencv344-contrib')
implementation 'org.rajawali3d:rajawali:1.1.970'
}
22 changes: 18 additions & 4 deletions app/src/main/java/mg/rivolink/app/aruco/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import android.app.Activity;
import android.os.Bundle;
import android.view.SurfaceView;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import mg.rivolink.app.aruco.renderer.Renderer3D;
import mg.rivolink.app.aruco.utils.CameraParameters;

import org.opencv.android.BaseLoaderCallback;
Expand All @@ -26,13 +28,14 @@
import org.opencv.core.MatOfInt;
import org.opencv.imgproc.Imgproc;

import org.rajawali3d.view.ISurface;
import org.rajawali3d.view.SurfaceView;

public class MainActivity extends Activity implements CvCameraViewListener2{

private Mat cameraMatrix;
private Mat distCoeffs;

private CameraBridgeViewBase camera;

private Mat rgb;
private Mat gray;

Expand All @@ -44,6 +47,9 @@ public class MainActivity extends Activity implements CvCameraViewListener2{
private Dictionary dictionary;
private DetectorParameters parameters;

private Renderer3D renderer;
private CameraBridgeViewBase camera;

private BaseLoaderCallback loaderCallback=new BaseLoaderCallback(this){
@Override
public void onManagerConnected(int status){
Expand Down Expand Up @@ -78,7 +84,14 @@ protected void onCreate(Bundle savedInstanceState){
camera=findViewById(R.id.main_camera);
camera.setVisibility(SurfaceView.VISIBLE);
camera.setCvCameraViewListener(this);
}

renderer=new Renderer3D(this);

SurfaceView surface=findViewById(R.id.main_surface);
surface.setTransparent(true);
surface.setSurfaceRenderer(renderer);

}

@Override
public void onResume(){
Expand Down Expand Up @@ -151,3 +164,4 @@ public void onCameraViewStopped(){

}


61 changes: 61 additions & 0 deletions app/src/main/java/mg/rivolink/app/aruco/renderer/Renderer3D.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package mg.rivolink.app.aruco.renderer;

import android.content.Context;
import android.view.MotionEvent;

import org.rajawali3d.Object3D;
import org.rajawali3d.lights.PointLight;
import org.rajawali3d.loader.LoaderOBJ;
import org.rajawali3d.loader.ParsingException;
import org.rajawali3d.math.vector.Vector3;
import org.rajawali3d.renderer.Renderer;

import mg.rivolink.app.aruco.R;

public class Renderer3D extends Renderer{

private Object3D model;
private PointLight light;

public Renderer3D(Context context){
super(context);
setFrameRate(60);
}

protected void initScene() {
light=new PointLight();
light.setPosition(0,0,4);
light.setPower(3);

try {
LoaderOBJ objParser=new LoaderOBJ(mContext.getResources(),mTextureManager,R.raw.camaro_obj);
objParser.parse();
model=objParser.getParsedObject();
model.setPosition(0,0,-5);
model.setRotation(90,90,0);
getCurrentScene().addLight(light);
getCurrentScene().addChild(model);


} catch(ParsingException e) {
e.printStackTrace();
}
}

@Override
protected void render(long ellapsedRealtime,double deltaTime){
super.render(ellapsedRealtime,deltaTime);
model.rotate(Vector3.Axis.Y,0.5);
}

@Override
public void onOffsetsChanged(float x, float y, float z, float w, int i, int j){
// TODO: Implement this method
}

@Override
public void onTouchEvent(MotionEvent p1){
// TODO: Implement this method
}

}
Binary file added app/src/main/res/drawable-nodpi/camaro.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 19 additions & 8 deletions app/src/main/res/layout/main_layout.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<org.opencv.android.JavaCameraView
<org.opencv.android.JavaCameraView
android:id="@+id/main_camera"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"/>

<org.rajawali3d.view.SurfaceView
android:id="@+id/main_surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_camera" />
android:layout_centerInParent="true"
app:frameRate="60.0"
app:renderMode="RENDER_WHEN_DIRTY"/>

</RelativeLayout>

</LinearLayout>

12 changes: 12 additions & 0 deletions app/src/main/res/raw/camaro_mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Blender3D MTL File:
# Material Count: 1
newmtl 01_-_Default_CMRO_TEX.TGA
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.000000 0.000000 0.000000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd camaro.jpg

Loading

0 comments on commit 785021c

Please sign in to comment.