gpt4 book ai didi

java - 无法在运行时加载我的 3D 对象(GLTF)

转载 作者:行者123 更新时间:2023-12-02 08:49:04 29 4
gpt4 key购买 nike

无法在运行时加载我的 3D 对象 (GLTF)。或者我可能无法从服务器获取 3D 对象(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

据我所知,只要网址合法,就不需要特殊类型的网址。尝试将您的 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com