无法在运行时加载我的3D对象(GLTF)。否则我可能无法从服务器获取3D object(Gltf)。 。 。
我正在尝试从实时服务器中获取3D对象,然后尝试将该对象加载到我的Scenefoam中。但我无法加载和显示3D对象。当我尝试加载对象时,出现以下错误提示,我的应用没有崩溃,但仍然无法加载3D模型(GLTF)。或者从api获取对象时,我需要从服务器获取一些特殊类型的Url或其他内容?
这是我的代码(java)
///ARObjectActivity.java
public class ARObjectActivity extends AppCompatActivity {
private ArFragment arFragment;
private String Asset_3D = "";
String imageUri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_a_r_object);
arFragment=(ArFragment) getSupportFragmentManager().findFragmentById(R.id.arFragment);
WebServiceFactory.getInstance().getARObject(2).enqueue(new Callback<ARObject>() {
@Override
public void onResponse(Call<ARObject> call, Response<ARObject> response) {
if (response.body().getFlag() ==1){
Asset_3D = response.body().getFILES().getFilePath();
imageUri = "http://abc.example.pk"+Asset_3D;
Log.e("3dObject",imageUri );
arFragment.setOnTapArPlaneListener((hitResult, plane, motionEvent) ->
placeModel(hitResult.createAnchor()));
}
}
@Override
public void onFailure(Call<ARObject> call, Throwable t) {
}
});
}
private void placeModel(Anchor anchor) {
Toast.makeText(this, ""+imageUri, Toast.LENGTH_SHORT).show();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
ModelRenderable.builder()
.setSource(ARObjectActivity.this, RenderableSource.builder()
.setSource(ARObjectActivity.this,
Uri.parse(imageUri),
RenderableSource.SourceType.GLTF2)
.setScale(0.5f)
.setRecenterMode(RenderableSource.RecenterMode.ROOT)
.build()
)
.setRegistryId(Asset_3D)
.build()
.thenAccept(modelRenderable -> addNoteToScene(modelRenderable,anchor))
.exceptionally(throwable -> {
AlertDialog.Builder builder = new AlertDialog.Builder(ARObjectActivity.this);
builder.setMessage(throwable.getMessage()).show();
return null;
});
}
}
private void addNoteToScene(ModelRenderable modelRenderable, Anchor anchor) {
AnchorNode anchorNode = new AnchorNode();
anchorNode.setRenderable(modelRenderable);
arFragment.getArSceneView().getScene().addChild(anchorNode);
}
}
ARObject.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activities.ARObjectActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/arFragment"
android:name="com.google.ar.sceneform.ux.ArFragment"/>
</LinearLayout>
这些是我在logcat中遇到的错误
2020-03-28 17:40:32.929 7301-7301/com.adroit.asle E/native: hit_test.cc:381 generic::internal: No
point hit.
2020-03-28 17:40:32.953 7301-7980/com.adroit.asle E/ModelRenderable: Unable to load Renderable
registryId='/CONTENT/PRODUCT/MODELS/model23329.gltf'
java.util.concurrent.CompletionException: java.util.concurrent.CompletionException:
java.io.FileNotFoundException: http://abc.example.pk/CONTENT/PRODUCT/MODELS/model23329.gltf
at com.google.ar.sceneform.utilities.SceneformBufferUtils.inputStreamToByteBuffer(SourceFile:48)
at com.google.ar.sceneform.rendering.LoadRenderableFromSfbTask.
lambda$downloadAndProcessRenderable$0$LoadRenderableFromSfbTask
(LoadRenderableFromSfbTask.java:118)
at com.google.ar.sceneform.rendering.
-$$Lambda$LoadRenderableFromSfbTask$0DkaOpfpmr8DYlbaxWogZtUpKTw.get(Unknown Source:4)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1625)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.util.concurrent.CompletionException: java.io.FileNotFoundException:
http://abc.example.pk/CONTENT/PRODUCT/MODELS/model23329.gltf
at com.google.ar.sceneform.assets.RenderableSource.downloadUri(Unknown Source:26)
at com.google.ar.sceneform.assets.RenderableSource.call(Unknown Source:53)
at com.google.ar.sceneform.assets.RenderableSource.call(Unknown Source:0)
at com.google.ar.sceneform.utilities.SceneformBufferUtils.inputStreamToByteBuffer(SourceFile:42)
at com.google.ar.sceneform.rendering.LoadRenderableFromSfbTask.
lambda$downloadAndProcessRenderable$0$LoadRen derableFromSfbTask(LoadRenderableFromSfbTask.java:118)
at
com.google.ar.sceneform.rendering.
-$$Lambda$LoadRenderableFromSfbTask$0DkaOpfpmr8DYlbaxWogZtUpKTw.get(Unknown Source:4)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1625)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.io.FileNotFoundException:
http://abc.example.pk/CONTENT/PRODUCT/MODELS/model23329.gltf
at
com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251)
at com.google.ar.sceneform.utilities.LoadHelper
.lambda$remoteUriToInputStreamCreator$3$LoadHelper(SourceFile:124)
at com.google.ar.sceneform.utilities.c.call(Unknown Source:2)
at com.google.ar.sceneform.assets.RenderableSource.downloadUri(Unknown Source:13)
at com.google.ar.sceneform.assets.RenderableSource.call(Unknown Source:53)
at com.google.ar.sceneform.assets.RenderableSource.call(Unknown Source:0)
at com.google.ar.sceneform.utilities.SceneformBufferUtils.inputStreamToByteBuffer(SourceFile:42)
at com.google.ar.sceneform.rendering.LoadRenderableFromSfbTask
.lambda$downloadAndProcessRenderable$0$LoadRenderableFromSfbTask
(LoadRenderableFromSfbTask.java:118)
at
com.google.ar.sceneform.rendering.
-$$Lambda$LoadRenderableFromSfbTask$0DkaOpfpmr8DYlbaxWogZtUpKTw.get(Unknown Source:4)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1625)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
2020-03-28 17:40:32.962 7301-7301/com.adroit.asle E/native: hit_test.cc:381 generic::internal: No
point hit.
最佳答案
好吧,错误logcat会自我说明。没有文件
Caused by: java.util.concurrent.CompletionException: java.io.FileNotFoundException:
http://abc.example.pk/CONTENT/PRODUCT/MODELS/model23329.gltf
AFAIK只要URL是合法的,就不需要某些特殊类型的Url。尝试将您的
imageUri
硬编码为https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/Duck/glTF/Duck.gltf
,然后看看会发生什么。 (来源:Load 3D models at runtime)关于java - 无法在运行时加载我的3D对象(GLTF),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60901493/