# 3D
## Google 关键词
### 关键词
- OpenGL
- Unity3D
- EasyAR
- Android
### 搜索关键字
- OpenGL ES 2.0 for Android
- OpenGL ES应用开发实践指南
## 安卓与EasyAR交互显示Unity3D
- [EasyAR4.0使用说明--02--平面图像跟踪](https://www.bilibili.com/video/BV1VZ4y147kj/)
- [配置EasyAR Sense Unity Plugin](https://help.easyar.cn/EasyAR%20Sense/v4/GettingStartedUnity/Setting-up-EasyAR-Unity-Package.html)
- [上传图片,检测可识别度](https://www.easyar.cn/targetcode.html)
- [Unity加载网络图片为Image贴图,并保存本地。](https://blog.csdn.net/weixin_42540271/article/details/95337041)
- [Unity3d EasyAR开发案例系列教程](https://www.cnblogs.com/qq764424567/p/9178125.html)
- 前提条件
- Unity 2019.3.8f1
- Android Studio 3.6.3
- 操作步骤如下
- 下载Unity后导入EasyAR Sense Unity Plugin
- 拖拉 EasyAR_ImageTracker-1 和 ImageTarget 到 Hierachy 里。
- 拖拉一个Cube在ImageTarget下为一个子对象
- 新建脚本 first_run 拖拉到 Cube上
- 脚本如下:
```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class first_run : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
// Vector3 v = transform.position;
// v.z -= 0.1f;
// transform.position = v;
if (Input.GetMouseButtonDown(0))
{//判断是否是点击事件
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo))
{
//如果是一根手指触摸屏幕而且是刚开始触摸屏幕
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began)
{
if (Input.GetTouch(0).tapCount == 1)
{//判断点击的次数
//Destroy(hitInfo.collider.gameObject);//销毁场景中的模型
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
string name = jo.Call<string>("getName", "成功调用android方法");
setNum(name);
}
}
}
}
}
void setNum(string num)
{
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
string name = jo.Call<string>("getName1", num);
}
}
```
- 在Unity里配置 [Preferences]里配置
- External Tools: Visual Studio
- Android JDk: 1.8
- Android SDK
- 在Unity菜单: File > Build Settings里设置
- Android 勾选 Export Project
- 点击 Player Settings 按钮
- 点选Tab: Player
- 修改 Company Name: sletech
- 修改 Product Name: itasktour
- 修改 Default Icon
- 修改 Other Settings
- 修改identification > Package Name: com.sletech.itasktour
- 点选导出: Export 导出Android 工程
- Android Studio 新建一个工程
- 修改配置文件 build.gradle :
```
android {
............
defaultConfig {
minSdkVersion 21
............
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
defaultConfig {
ndk {
abiFilters 'armeabi-v7a'
}
}
............
}
```
- Android Studio 菜单选择 File > New > Import Module :: Source Directory 选择之前导出的工程下的目录: unityLibrary
- 修改配置文件 build.gradle :
```
android {
............
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
ndk {
abiFilters 'armeabi-v7a'
}
............
packagingOptions {
doNotStrip '*/armeabi-v7a/*.so'
}
............
}
```
- 从工程中复制res目录下的mipmap目录和values目录下的strings.xml到module下的res目录下
- 修改Module里的AndroidManifest.xml文件以下内容
```
<application android:label="@string/app_name">
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false">
</activity>
```
- 修改文件:com.unity3d.player.UnityPlayerActivity
```
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
// return mUnityPlayer.injectEvent(event);
if (keyCode == KeyEvent.KEYCODE_BACK) {
onDestroy();
}
return true;
}
public String getName(final String str) {
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// Toast.makeText(UnityPlayerActivity.this, str, Toast.LENGTH_SHORT).show();
// }
// });
return "我是甩锅男Android中的数据" + (++num);
}
public String getName1(final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(UnityPlayerActivity.this, str, Toast.LENGTH_SHORT).show();
}
});
return "";
}
```
- 修改项目工程里的文件:
```
package com.sletech.itasktour;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import com.unity3d.player.UnityPlayerActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, UnityPlayerActivity.class));
}
});
}
}
```
- 当修改了Unity里的内容或者脚本需要替换以下内容
- unityLibrary/libs
- unityLibrary/src/main/assets
- unityLibrary/src/main/jniLibs/armeabi-v7a
## 参考
- Math
- [OpenGL 的空间变换(上):矩阵在空间几何中的应用](https://www.cnblogs.com/ojo-blogs/p/6754589.html)
- [齐次坐标](https://zh.wikipedia.org/wiki/%E9%BD%90%E6%AC%A1%E5%9D%90%E6%A0%87)
- OpenGL
- [安卓 OpenGL ES 2.0 完全入门(一):基本概念和 hello world](https://blog.piasy.com/2016/06/07/Open-gl-es-android-2-part-1/index.html)
- [欢迎来到OpenGL的世界](https://learnopengl-cn.github.io/)
- [Welcome to OpenGL](https://learnopengl.com/)
- [Learn C++](https://www.learncpp.com/)
- [《OpenGL ES 2.0 for Android》读书笔记](https://juejin.im/post/5aefdb2c51882522835e6542)
- [OpenGL ES](https://developer.android.com/guide/topics/graphics/opengl)
- [Book: OpenGL ES 2.0 for Android](https://www.amazon.com/OpenGL-Android-Quick-Start-Pragmatic-Programmers/dp/1937785343)
- [OpenGL ES应用开发实践指南](https://github.com/Canber/OpenGL-ES-for-android)
- [OpenGL-ES-2.0-for-Android](https://github.com/wxdut/OpenGL-ES-2.0-for-Android)
- [Learn OpenGL ES](http://www.learnopengles.com/)
- Unity
- [Unity](https://unity.com/)
- [Unity Cn](https://unity.com/cn)
- [Unity中文](https://www.unity.cn/)
- [Unity User Manual](https://docs.unity3d.com/Manual/UnityManual.html)
- [John Lemon's Haunted Jaunt 项目教程 (适用于3D初学者)](https://learn.unity.com/project/john-lemon-s-haunted-jaunt-3d-beginner-1)
- [Unity3D从安装到运行第一个程序](https://blog.csdn.net/q943520218/article/details/100939733?utm_source=distribute.pc_relevant.none-task)
- [Unity Technologies China](https://github.com/unity-cn)
- [史上最全Unity3D教程](https://www.bilibili.com/video/BV12s411g7gU?p=120)
- [unity3d从入门到大佬最全教程[特效实战篇]](https://www.bilibili.com/video/BV1z441157Lf/?spm_id_from=333.788.videocard.1)
- [Unity官方实例教程 Roll-a-Ball](https://www.jianshu.com/p/6e4b0435e30e)
- [Unity官方实例教程 Space Shooter](https://www.jianshu.com/p/8cc3a2109d3b)
- [Unity3D官方教程](https://www.w3cschool.cn/unity3d_jc/)
- [[Unity3D] 2D像素游戏(一) Hello Unity!](https://blog.csdn.net/qq_37398834/article/details/81948376?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task)
- [Vuforia for Unity 入门教程](https://blog.csdn.net/slj2017/article/details/79730378)
- [Vuforia Developer Library](https://library.vuforia.com/getting-started/overview.html)
- 3D免费模型
- [专业人士的3D模型](https://www.turbosquid.com/zh_cn/)
- [CG 3D网](https://www.cg99.cn/)
- [知末网3d模型](https://3d.znzmo.com/3dmoxing.html?keyword=%E5%AE%9D%E7%AE%B1&st=0)
- [哪个网站有免费的 3D 模型素材?](https://www.zhihu.com/question/19959438)
- [3D侠](https://www.3dxia.com/)
- [Free3D](https://free3d.com/zh/)
- [Sketchfab - Publish & find 3D models online](https://sketchfab.com/)
- [Free 3D Models](https://www.turbosquid.com/Search/3D-Models/free/)
- Android 3D
- [Android与Unity交互研究](https://blog.csdn.net/crazy1235/article/details/46733221)
- [实现Unity和Android进行交互](https://www.jianshu.com/p/7e46fe7485bb)
- [Unity3D与Android间的相互调用](https://github.com/DingMouRen/UnityDemo)
- EasyAR
- [EasyAR官网](https://www.easyar.cn/)
- [概览 — EasyAR Sense 4.0.0 文档](https://help.easyar.cn/EasyAR%20Sense/v4/ApiReference/Overview.html)
- [使用手册 — EasyAR Sense 4.0.0 文档](https://help.easyar.cn/EasyAR%20Sense/v4/Guides/Guides.html)
- [重磅 | 完备的EasyAR学习路线,最详细的资源整理](https://mp.weixin.qq.com/s/8YcKuDLuyIcwyj0GcyEoqQ)
- [EasyAR4.0报错VIOCameraDevice不可用]
- [Motion Tracking支持的设备](https://help.easyar.cn/EasyAR%20Sense/v4/Guides/EasyAR-Motion-Tracking-Supported-Devices.html)
- [EasyAR SpatialMap空间地图开发](https://forum.easyar.cn/?p=149)
- [EasyAR UnityPlugin 视频教程合集](https://forum.easyar.cn/?p=42)
- [EasyAR4.0使用说明--07--稀疏空间地图](https://www.bilibili.com/video/BV1Xg4y1z7d8/)
- [EasyAR4.0使用说明--08--稠密空间地图](https://www.bilibili.com/video/BV1sf4y1S7sp)