Skip to content

Commit 2c6ac0c

Browse files
author
lao
committed
Initial commit
0 parents  commit 2c6ac0c

File tree

362 files changed

+28145
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

362 files changed

+28145
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
compileSdkVersion 30
7+
buildToolsVersion "30.0.3"
8+
9+
defaultConfig {
10+
applicationId "com.aotem.threejsdemo"
11+
minSdkVersion 19
12+
targetSdkVersion 30
13+
versionCode 1
14+
versionName "1.0"
15+
16+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
}
30+
31+
dependencies {
32+
33+
implementation 'androidx.appcompat:appcompat:1.2.0'
34+
implementation 'com.google.android.material:material:1.2.1'
35+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
36+
implementation project(path: ':threejs')
37+
testImplementation 'junit:junit:4.+'
38+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
39+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
40+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.aotem.threejsdemo;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.aotem.threejsdemo", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.aotem.threejsdemo">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/Theme.ThreeJsDemo">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package com.aotem.threejsdemo;
2+
3+
import android.app.Activity;
4+
import android.app.ActivityManager;
5+
import android.content.Context;
6+
import android.content.pm.ConfigurationInfo;
7+
import android.opengl.GLSurfaceView;
8+
import android.os.Bundle;
9+
import android.util.Log;
10+
import android.view.MotionEvent;
11+
import android.view.View;
12+
import android.view.ViewGroup;
13+
import android.widget.AdapterView;
14+
import android.widget.ArrayAdapter;
15+
import android.widget.ListView;
16+
import android.widget.Toast;
17+
18+
import java.lang.ref.WeakReference;
19+
20+
import com.aotem.threejsdemo.renderer.BaseRender;
21+
import com.aotem.threejsdemo.renderer.LambertPhongLightRender;
22+
import com.aotem.threejsdemo.renderer.RaycastCameraControlView;
23+
import com.aotem.threejsdemo.renderer.SpriteTextDemo;
24+
import com.aotem.threejsdemo.renderer.TextureDemo;
25+
import com.aotem.threejs.three.renderers.GLRenderer;
26+
import com.aotem.threejs.util.RawShaderLoader;
27+
28+
import static android.opengl.GLSurfaceView.DEBUG_CHECK_GL_ERROR;
29+
import static android.opengl.GLSurfaceView.DEBUG_LOG_GL_CALLS;
30+
31+
public class MainActivity extends Activity implements AdapterView.OnItemClickListener {
32+
33+
GLSurfaceView glSurfaceView;
34+
BaseRender renderer;
35+
ViewGroup root;
36+
ListView listView;
37+
@Override
38+
protected void onCreate(Bundle savedInstanceState) {
39+
super.onCreate(savedInstanceState);
40+
setContentView(R.layout.activity_main);
41+
42+
RawShaderLoader.mContext = new WeakReference<>(getApplicationContext());
43+
root = findViewById(R.id.main_root);
44+
listView = findViewById(R.id.main_list);
45+
ArrayAdapter<MainListItems.Item> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
46+
android.R.id.text1, MainListItems.ITEMS);
47+
listView.setAdapter(adapter);
48+
listView.setOnItemClickListener(this);
49+
50+
// int position = MainListItems.getIndex(SpriteTextDemo.class);
51+
//// int position = MainListItems.getIndex(LambertPhongLightRender.class);
52+
// listView.performItemClick(adapter.getView(position, null, listView), position,
53+
// adapter.getItemId(position));
54+
55+
}
56+
57+
@Override
58+
public boolean onTouchEvent(MotionEvent event) {
59+
if (glSurfaceView != null) {
60+
glSurfaceView.onTouchEvent(event);
61+
}
62+
return true;
63+
}
64+
65+
@Override
66+
protected void onPause() {
67+
if (glSurfaceView != null && renderer != null) {
68+
glSurfaceView.queueEvent(new Runnable() {
69+
@Override
70+
public void run() {
71+
renderer.onPause();
72+
}
73+
});
74+
}
75+
super.onPause();
76+
77+
if (glSurfaceView != null) {
78+
glSurfaceView.onPause();
79+
}
80+
}
81+
82+
@Override
83+
protected void onResume() {
84+
super.onResume();
85+
86+
if (glSurfaceView != null) {
87+
glSurfaceView.onResume();
88+
}
89+
}
90+
91+
@Override
92+
public void onBackPressed() {
93+
if (glSurfaceView != null) {
94+
int childCount = root.getChildCount();
95+
int i = 0;
96+
while (i < childCount) {
97+
if (root.getChildAt(i) != listView) {
98+
root.removeViewAt(i);
99+
childCount--;
100+
i--;
101+
}
102+
i++;
103+
}
104+
glSurfaceView = null;
105+
} else {
106+
super.onBackPressed();
107+
}
108+
}
109+
110+
@Override
111+
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
112+
Class clickClass = MainListItems.getClass(position);
113+
glSurfaceView = new GLSurfaceView(this);
114+
root.addView(glSurfaceView);
115+
116+
// Create an OpenGL ES 3.0 context.
117+
glSurfaceView.setEGLContextClientVersion(3);
118+
glSurfaceView.setEGLConfigChooser(true);
119+
glSurfaceView.setDebugFlags(BuildConfig.DEBUG ? DEBUG_LOG_GL_CALLS : DEBUG_CHECK_GL_ERROR);
120+
121+
renderer = (BaseRender) MainListItems.getRenderer(clickClass, glSurfaceView);
122+
if (renderer == null) {
123+
Toast.makeText(this, "java reflection construction failure.", Toast.LENGTH_SHORT).show();
124+
return;
125+
}
126+
glSurfaceView.setRenderer(renderer);
127+
glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
128+
glSurfaceView.setOnTouchListener(new View.OnTouchListener() {
129+
@Override
130+
public boolean onTouch(View v, MotionEvent event) {
131+
renderer.onTouchEvent(event);
132+
return true;
133+
}
134+
});
135+
}
136+
}

0 commit comments

Comments
 (0)