Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
nftpro
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
胡尚
nftpro
Commits
42c71aae
提交
42c71aae
authored
5月 09, 2023
作者:
cbd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1、布局中使用GlSufaceView支持触摸缩放。
2、放入ScrowView触摸冲突处理。
上级
e891180d
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
99 行增加
和
128 行删除
+99
-128
ModelRenderer.java
.../the3deer/android_3d_model_engine/view/ModelRenderer.java
+29
-3
ModelSurfaceView.java
...e3deer/android_3d_model_engine/view/ModelSurfaceView.java
+34
-2
ModelActivity.java
widget/src/main/java/com/orange/widget/ui/ModelActivity.java
+36
-123
没有找到文件。
engine/src/main/java/org/the3deer/android_3d_model_engine/view/ModelRenderer.java
浏览文件 @
42c71aae
...
...
@@ -52,8 +52,8 @@ public class ModelRenderer implements GLSurfaceView.Renderer {
// Add 0.5f to the alpha component to the global shader so we can see through the skin
private
static
final
float
[]
BLENDING_MASK_FORCED
=
{
1.0f
,
1.0f
,
1.0f
,
0.5f
};
private
final
float
[]
backgroundColor
;
private
final
SceneLoader
scene
;
float
[]
backgroundColor
;
SceneLoader
scene
;
private
final
List
<
EventListener
>
listeners
=
new
ArrayList
<>();
...
...
@@ -70,7 +70,7 @@ public class ModelRenderer implements GLSurfaceView.Renderer {
/**
* Drawer factory to get right renderer/shader based on object attributes
*/
private
final
RendererFactory
drawer
;
private
RendererFactory
drawer
;
// frames per second
private
long
framesPerSecondTime
=
-
1
;
...
...
@@ -197,6 +197,27 @@ public class ModelRenderer implements GLSurfaceView.Renderer {
}
}
public
ModelRenderer
(
Activity
parent
,
ModelSurfaceView
modelSurfaceView
){
this
.
main
=
modelSurfaceView
;
try
{
this
.
drawer
=
new
RendererFactory
(
parent
);
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
if
(
doShadowing
)
{
try
{
this
.
shadowsRenderer
=
new
ShadowsRenderer
(
parent
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
}
public
ModelRenderer
addListener
(
EventListener
listener
)
{
this
.
listeners
.
add
(
listener
);
return
this
;
...
...
@@ -973,4 +994,8 @@ public class ModelRenderer implements GLSurfaceView.Renderer {
public
void
setOrientation
(
Quaternion
orientation
)
{
this
.
orientation
=
orientation
;
}
public
void
setScene
(
SceneLoader
scene
)
{
this
.
scene
=
scene
;
}
}
\ No newline at end of file
engine/src/main/java/org/the3deer/android_3d_model_engine/view/ModelSurfaceView.java
浏览文件 @
42c71aae
...
...
@@ -15,6 +15,7 @@ import org.the3deer.util.android.AndroidUtils;
import
org.the3deer.util.event.EventListener
;
import
org.the3deer.util.math.Quaternion
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.EventObject
;
import
java.util.List
;
...
...
@@ -28,8 +29,10 @@ import java.util.List;
public
class
ModelSurfaceView
extends
GLSurfaceView
implements
EventListener
{
private
ModelRenderer
mRenderer
;
private
float
[]
backgroundColor
=
new
float
[]{
0.0f
,
0.5f
,
0.0f
,
1.0f
};
SceneLoader
scene
;
private
final
List
<
EventListener
>
listeners
=
new
ArrayList
<>();
private
boolean
canTouch
=
false
;
public
ModelSurfaceView
(
Activity
parent
,
float
[]
backgroundColor
,
SceneLoader
scene
){
super
(
parent
);
...
...
@@ -51,10 +54,13 @@ public class ModelSurfaceView extends GLSurfaceView implements EventListener {
}
public
ModelSurfaceView
(
Context
context
,
AttributeSet
attrs
)
{
public
ModelSurfaceView
(
Context
context
,
AttributeSet
attrs
)
throws
IOException
,
IllegalAccessException
{
super
(
context
,
attrs
);
Log
.
i
(
"ModelSurfaceView"
,
"Loading [OpenGL 2] ModelSurfaceView..........."
);
setEGLContextClientVersion
(
2
);
mRenderer
=
new
ModelRenderer
((
Activity
)
context
,
this
);
mRenderer
.
addListener
(
this
);
setRenderer
(
mRenderer
);
}
public
void
addListener
(
EventListener
listener
){
...
...
@@ -69,9 +75,20 @@ public class ModelSurfaceView extends GLSurfaceView implements EventListener {
return
mRenderer
.
getViewMatrix
();
}
@Override
public
boolean
onTouchEvent
(
MotionEvent
event
)
{
// propagate event to responsible...
//NestedScrollView嵌套ModelSurfaceView,ModelSurfaceView触摸事件冲突
if
(
canTouch
){
if
(
event
.
getAction
()
==
MotionEvent
.
ACTION_DOWN
){
getParent
().
requestDisallowInterceptTouchEvent
(
true
);
}
if
(
event
.
getAction
()
==
MotionEvent
.
ACTION_MOVE
){
//通知他的父View NestedScrollView现在进行的是本控件的操作,不要对我的操作进行干扰
getParent
().
requestDisallowInterceptTouchEvent
(
true
);
}
}
AndroidUtils
.
fireEvent
(
listeners
,
new
EventObject
(
event
));
return
true
;
}
...
...
@@ -87,6 +104,19 @@ public class ModelSurfaceView extends GLSurfaceView implements EventListener {
return
true
;
}
public
void
setCanTouch
(
boolean
canTouch
)
{
this
.
canTouch
=
canTouch
;
}
public
void
setBackgroundColor
(
float
[]
backgroundColor
)
{
mRenderer
.
backgroundColor
=
backgroundColor
;
}
public
void
setScene
(
SceneLoader
scene
)
{
mRenderer
.
scene
=
scene
;
}
public
void
toggleProjection
()
{
Log
.
i
(
"ModelSurfaceView"
,
"Toggling projection..."
);
mRenderer
.
toggleProjection
();
...
...
@@ -148,4 +178,6 @@ public class ModelSurfaceView extends GLSurfaceView implements EventListener {
public
void
setOrientation
(
Quaternion
orientation
)
{
mRenderer
.
setOrientation
(
orientation
);
}
}
widget/src/main/java/com/orange/widget/ui/ModelActivity.java
浏览文件 @
42c71aae
...
...
@@ -2,7 +2,6 @@ package com.orange.widget.ui;
import
android.annotation.SuppressLint
;
import
android.annotation.TargetApi
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.hardware.Sensor
;
...
...
@@ -18,10 +17,9 @@ import android.view.MotionEvent;
import
android.view.OrientationEventListener
;
import
android.view.View
;
import
android.widget.Toast
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
androidx.appcompat.app.AppCompatActivity
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.load.DataSource
;
import
com.bumptech.glide.load.engine.GlideException
;
...
...
@@ -44,10 +42,10 @@ import org.the3deer.android_3d_model_engine.view.ViewEvent;
import
org.the3deer.util.android.ContentUtils
;
import
org.the3deer.util.android.FileUtils
;
import
org.the3deer.util.event.EventListener
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.util.ArrayList
;
import
java.util.EventObject
;
import
java.util.List
;
...
...
@@ -55,7 +53,7 @@ import java.util.List;
/**
* This activity represents the container for our 3D viewer.
*/
public
class
ModelActivity
extends
Activity
implements
EventListener
{
public
class
ModelActivity
extends
A
ppCompatA
ctivity
implements
EventListener
{
private
static
final
int
REQUEST_CODE_LOAD_TEXTURE
=
1000
;
private
static
final
int
FULLSCREEN_DELAY
=
10000
;
/**
...
...
@@ -90,6 +88,9 @@ public class ModelActivity extends Activity implements EventListener {
private
int
downloadCount
=
0
;
String
objName
=
""
;
String
mtlName
=
""
;
//是否能够触摸与缩放
private
boolean
canTouch
=
false
;
private
URI
puri
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -125,100 +126,6 @@ public class ModelActivity extends Activity implements EventListener {
datas
.
add
(
"https://appmanage.youcai168.cn/villain/villain_d.png"
);
datas
.
add
(
"https://appmanage.youcai168.cn/villain/villain_n.png"
);
load3dModel
();
// load model
// scene.init();
// Log.i("ModelActivity", "Finished loading");
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
private
void
setupOrientationListener
()
{
try
{
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
sensorManager
=
(
SensorManager
)
getSystemService
(
Context
.
SENSOR_SERVICE
);
//sensor = sensorManager.getDefaultSensor(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR);
sensor
=
sensorManager
.
getDefaultSensor
(
Sensor
.
TYPE_GAME_ROTATION_VECTOR
);
if
(
sensor
!=
null
)
{
sensorManager
.
registerListener
(
new
SensorEventListener
()
{
@Override
public
void
onSensorChanged
(
SensorEvent
event
)
{
/*Log.v("ModelActivity","sensor: "+ Arrays.toString(event.values));
Quaternion orientation = new Quaternion(event.values);
orientation.normalize();
//scene.getSelectedObject().setOrientation(orientation);
glView.setOrientation(orientation);*/
}
@Override
public
void
onAccuracyChanged
(
Sensor
sensor
,
int
accuracy
)
{
}
},
sensor
,
SensorManager
.
SENSOR_DELAY_NORMAL
,
SensorManager
.
SENSOR_DELAY_UI
);
}
OrientationEventListener
mOrientationListener
=
new
OrientationEventListener
(
getApplicationContext
())
{
@Override
public
void
onOrientationChanged
(
int
orientation
)
{
//scene.onOrientationChanged(orientation);
}
};
if
(
mOrientationListener
.
canDetectOrientation
())
{
mOrientationListener
.
enable
();
}
}
catch
(
Exception
e
)
{
Log
.
e
(
"ModelActivity"
,
"There is an issue setting up sensors"
,
e
);
}
}
@Override
protected
void
onSaveInstanceState
(
Bundle
outState
)
{
outState
.
putFloatArray
(
"camera.pos"
,
scene
.
getCamera
().
getPos
());
outState
.
putFloatArray
(
"camera.view"
,
scene
.
getCamera
().
getView
());
outState
.
putFloatArray
(
"camera.up"
,
scene
.
getCamera
().
getUp
());
outState
.
putString
(
"renderer.projection"
,
glView
.
getProjection
().
name
());
outState
.
putInt
(
"renderer.skybox"
,
glView
.
getSkyBoxId
());
}
@Override
protected
void
onRestoreInstanceState
(
Bundle
state
)
{
if
(
state
.
containsKey
(
"renderer.projection"
))
{
glView
.
setProjection
(
Projection
.
valueOf
(
state
.
getString
(
"renderer.projection"
)));
}
if
(
state
.
containsKey
(
"camera.pos"
)
&&
state
.
containsKey
(
"camera.view"
)
&&
state
.
containsKey
(
"camera.up"
)){
Log
.
d
(
"ModelActivity"
,
"onRestoreInstanceState: Restoring camera settings..."
);
scene
.
getCamera
().
set
(
state
.
getFloatArray
(
"camera.pos"
),
state
.
getFloatArray
(
"camera.view"
),
state
.
getFloatArray
(
"camera.up"
));
}
if
(
state
.
containsKey
(
"renderer.skybox"
)){
glView
.
setSkyBox
(
state
.
getInt
(
"renderer.skybox"
));
}
}
@TargetApi
(
Build
.
VERSION_CODES
.
JELLY_BEAN
)
private
void
setupOnSystemVisibilityChangeListener
()
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
JELLY_BEAN
)
{
return
;
}
getWindow
().
getDecorView
().
setOnSystemUiVisibilityChangeListener
(
visibility
->
{
// Note that system bars will only be "visible" if none of the
// LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
if
((
visibility
&
View
.
SYSTEM_UI_FLAG_FULLSCREEN
)
==
0
)
{
// The system bars are visible. Make any desired
hideSystemUIDelayed
();
}
});
}
@Override
public
void
onWindowFocusChanged
(
boolean
hasFocus
)
{
super
.
onWindowFocusChanged
(
hasFocus
);
if
(
hasFocus
)
{
hideSystemUIDelayed
();
}
}
private
void
toggleImmersive
()
{
...
...
@@ -286,6 +193,7 @@ public class ModelActivity extends Activity implements EventListener {
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
resultCode
!=
RESULT_OK
)
{
return
;
}
...
...
@@ -389,7 +297,8 @@ public class ModelActivity extends Activity implements EventListener {
// parseMtlmappic(0x0000ff,objName,mtlName);
File
objFile
=
new
File
(
this
.
getExternalFilesDir
(
"3dModel"
).
toString
(),
objName
);
if
(
objFile
.
isFile
()
&&
objFile
.
exists
()){
initScene
(
URI
.
create
(
Uri
.
parse
(
"file://"
+
objFile
.
getAbsolutePath
()).
toString
()));
Uri
uri
=
Uri
.
parse
(
"file://"
+
objFile
.
getAbsolutePath
());
initScene
(
uri
);
}
}
else
{
//下载并保存
...
...
@@ -397,9 +306,20 @@ public class ModelActivity extends Activity implements EventListener {
}
}
private
void
initScene
(
U
RI
paramU
ri
)
{
private
void
initScene
(
U
ri
u
ri
)
{
Log
.
i
(
"ModelActivity"
,
"Loading Scene..."
);
scene
=
new
SceneLoader
(
this
,
paramUri
,
paramType
);
try
{
puri
=
URI
.
create
(
uri
.
toString
());
}
catch
(
Exception
e
)
{
// info: filesystem url may contain spaces, therefore we re-encode URI
try
{
puri
=
new
URI
(
uri
.
getScheme
(),
uri
.
getAuthority
(),
uri
.
getPath
(),
uri
.
getQuery
(),
uri
.
getFragment
());
}
catch
(
URISyntaxException
ex
)
{
Toast
.
makeText
(
this
,
"Error: "
+
uri
.
toString
(),
Toast
.
LENGTH_LONG
).
show
();
return
;
}
}
scene
=
new
SceneLoader
(
this
,
puri
,
paramType
);
scene
.
addListener
(
this
);
if
(
paramUri
==
null
)
{
// final LoaderTask task = new DemoLoaderTask(this, null, scene);
...
...
@@ -409,11 +329,14 @@ public class ModelActivity extends Activity implements EventListener {
Log
.
i
(
"ModelActivity"
,
"Loading GLSurfaceView..."
);
setContentView
(
R
.
layout
.
activity_model
);
glView
=
findViewById
(
R
.
id
.
surfaceView
);
// glView = new ModelSurfaceView(this, backgroundColor, this.scene);
glView
.
setBackgroundColor
(
backgroundColor
);
glView
.
setScene
(
scene
);
glView
.
addListener
(
this
);
mRenderer
=
new
ModelRenderer
(
this
,
glView
,
backgroundColor
,
this
.
scene
);
mRenderer
.
addListener
(
this
);
glView
.
setRenderer
(
mRenderer
);
glView
.
setCanTouch
(
canTouch
);
// mRenderer = new ModelRenderer(this, glView, backgroundColor, this.scene);
// mRenderer.addListener(this);
// glView.setRenderer(mRenderer);
// glView = new ModelSurfaceView(this, backgroundColor, this.scene);
// glView.addListener(this);
// setContentView(glView);
...
...
@@ -426,13 +349,9 @@ public class ModelActivity extends Activity implements EventListener {
Log
.
i
(
"ModelActivity"
,
"Loading TouchController..."
);
touchController
=
new
TouchController
(
this
);
touchController
.
addListener
(
this
);
new
Handler
().
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
//5s后移除触摸缩放
touchController
.
removeListener
(
ModelActivity
.
this
);
}
},
1
);
if
(!
canTouch
){
touchController
.
removeListener
(
this
);
}
//touchController.addListener(glView);
}
catch
(
Exception
e
)
{
Log
.
e
(
"ModelActivity"
,
e
.
getMessage
(),
e
);
...
...
@@ -458,7 +377,6 @@ public class ModelActivity extends Activity implements EventListener {
Log
.
e
(
"ModelActivity"
,
e
.
getMessage
(),
e
);
Toast
.
makeText
(
this
,
"Error loading CameraController"
+
e
.
getMessage
(),
Toast
.
LENGTH_LONG
).
show
();
}
try
{
// TODO: finish UI implementation
Log
.
i
(
"ModelActivity"
,
"Loading GUI..."
);
...
...
@@ -471,15 +389,10 @@ public class ModelActivity extends Activity implements EventListener {
Log
.
e
(
"ModelActivity"
,
e
.
getMessage
(),
e
);
Toast
.
makeText
(
this
,
"Error loading GUI"
+
e
.
getMessage
(),
Toast
.
LENGTH_LONG
).
show
();
}
setupOnSystemVisibilityChangeListener
();
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
KITKAT
)
{
setupOrientationListener
();
}
scene
.
init
();
Log
.
i
(
"ModelActivity"
,
"Finished loading"
);
}
private
void
save3dModelResourceToLocal
(
List
<
String
>
datas
)
{
//// 发起多个请求
for
(
String
url
:
datas
)
{
...
...
@@ -519,7 +432,8 @@ public class ModelActivity extends Activity implements EventListener {
// parseMtlmappic(0x0000ff,objName,mtlName);
File
objFile
=
new
File
(
ModelActivity
.
this
.
getExternalFilesDir
(
"3dModel"
).
toString
(),
objName
);
if
(
objFile
.
isFile
()
&&
objFile
.
exists
()){
initScene
(
URI
.
create
(
Uri
.
parse
(
"file://"
+
objFile
.
getAbsolutePath
()).
toString
()));
Uri
uri
=
Uri
.
parse
(
"file://"
+
objFile
.
getAbsolutePath
());
initScene
(
uri
);
}
}
return
false
;
...
...
@@ -527,7 +441,5 @@ public class ModelActivity extends Activity implements EventListener {
})
.
preload
();
}
}
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论