android - 不知道如何用语言表达。我的应用程序在它应该将一个元素放在飞机上然后没有响应时出现故障
问题描述
链接到谷歌驱动器上的应用程序我在 gitHub 上有这个应用程序,但它与这个不完全相同,这就是为什么我在谷歌驱动器而不是 gitHub 上上传了这个版本
屏幕截图屏幕截图还包括问题摘要
新手在这里,这可能是一个简单的修复,但我只是还没有找到它。
我的屏幕底部有一个带有家具图片/图标的菜单。我希望当您单击其中一张图片并单击锚点(我可以放置对象/资产的地方)时,该对象应放置在您正在点击的锚点上
在点击锚点后,我尝试登录到调试控制台,以查看应用程序是否识别出已点击的资产/对象。
因此,例如,如果我点击椅子然后点击锚点,应用程序确实会识别出我点击了椅子。
我安装了sceneform插件我的gradle依赖项中有sceneform
对不起所有这些代码,只是不知道问题到底出在哪里。
我的猜测是它只在放置对象时出现,我想为可能需要查看缺失部分的任何人添加它
//My imports
package com.google.ar.sceneform.overlei;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.google.ar.core.Anchor;
import com.google.ar.core.HitResult;
import com.google.ar.core.Plane;
import com.google.ar.sceneform.AnchorNode;
import com.google.ar.sceneform.rendering.ModelRenderable;
import com.google.ar.sceneform.rendering.Renderable;
import com.google.ar.sceneform.samples.Overlei.R;
import com.google.ar.sceneform.ux.ArFragment;
import com.google.ar.sceneform.ux.TransformableNode;
//At this point i have installed the google sceneform plugin. This is
//whats going to help be able to work with 3D assets
public class Overlei extends AppCompatActivity {
private ArFragment fragment;
private Uri currentltySelectedObject;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//brings up hand and camera to scan environment
setContentView(R.layout.activity_ux);
fragment = (ArFragment)
getSupportFragmentManager().findFragmentById(R.id.sceneform_fragment);
initializeGallary();
fragment.setOnTapArPlaneListener((HitResult hitResult, Plane plane,
MotionEvent motionEvent) -> {
//checking if the scene being detected is horizontal
if (plane.getType() != Plane.Type.HORIZONTAL_UPWARD_FACING) {
return;
}
//creating anchor
Anchor anchor = hitResult.createAnchor();
placeObject(fragment, anchor, currentltySelectedObject);
}
);
}
//show the menu at the bottom (this works)
public void initializeGallary() {
LinearLayout gallary = findViewById(R.id.gallery_layout);
//create chair thumbnails/picturee
ImageView chair = new ImageView(this);
chair.setImageResource(R.drawable.chair_thumb);
chair.setContentDescription("chair asset");
//parsing the file, gives reference to object
chair.setOnClickListener(view -> currentltySelectedObject =
Uri.parse("chair.sfb"));
gallary.addView(chair);
//create couch picture/icon
//where im getting the image from
ImageView couch = new ImageView(this);
//imageView resource
couch.setImageResource(R.drawable.couch_thumb);
//attaching a description
couch.setContentDescription("couch asset");
//setting onclick action to set the currentlySelectedObject
couch.setOnClickListener(view -> currentltySelectedObject =
Uri.parse("couch.sfb"));
gallary.addView(couch);
//lampPost picture/icon
ImageView lampPost = new ImageView(this);
lampPost.setImageResource(R.drawable.lamp_thumb);
lampPost.setContentDescription("lampPost asset");
lampPost.setOnClickListener(view -> currentltySelectedObject =
Uri.parse("lampPost.sfb"));
gallary.addView(lampPost);
}
//anchor is where im going to place the object takes into
//this method also has 'build' call method called addNodeToScene, find
//this method below
private void placeObject(ArFragment arFragment, Anchor anchor, Uri model) {
ModelRenderable.builder().setSource(arFragment.getContext(),
model).build()
.thenAccept(renderable -> addNodeToScene(arFragment, anchor,
renderable)).exceptionally((throwable -> {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(throwable.getMessage()).setTitle("Error");
AlertDialog dialog = builder.create();
dialog.show();
return null;
}));
}
private void addNodeToScene(ArFragment arFragment, Anchor anchor,
Renderable renderable) {
//create an anchor node
AnchorNode anchorNode = new AnchorNode(anchor);
//create transformable node
TransformableNode transformableNode = new
TransformableNode(arFragment.getTransformationSystem());
transformableNode.setRenderable(renderable);
//make anchorNode parent of transformable
transformableNode.setParent(anchorNode);
//add node for interactiion
arFragment.getArSceneView().getScene().addChild(anchorNode);
transformableNode.select();
}
}
//============================XML CODE==============================
<android.support.constraint.ConstraintLayout
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="com.google.ar.sceneform.overlei.Overlei">
<fragment
android:id="@+id/sceneform_fragment"
android:name="com.google.ar.sceneform.ux.ArFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/gallery_layout"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread"
app:layout_constraintVertical_weight="9" />
<LinearLayout
android:id="@+id/gallery_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/sceneform_fragment"
app:layout_constraintVertical_chainStyle="spread"
app:layout_constraintVertical_weight="1" />
我希望当我单击家具物品的图片然后单击锚点时,该对象会出现在锚点上。相反,当我这样做时,应用程序会出现“故障”,然后我的水龙头没有得到任何响应
解决方案
因此,在对不同的设备进行了一些测试之后,我设法在其中一个设备上显示了一条错误消息,指出“没有这样的文件”。所以我认为它必须是文件定义的路径。修复后我设法让它工作
推荐阅读
- r - 如何更改 ggplot 中的标题以获取一系列情节?
- node.js - Node.js 托管:低带宽,高 CPU
- mongodb - 如何与现代 Mongo scala 驱动程序一起运行传统的 Mongo Casbah 驱动程序
- azure - 将组添加到 ADO 中的所有服务连接
- typescript - Next.js、Styled-components 和 Yandex Metrica 会话重放
- node.js - 将 socket.io 升级到 v3 后出现 express-session 问题
- merge - 使用 Spacy 的模型“en_core_web_md”时,合并跨度非常慢
- python - 在python相同长度的循环中组合两个列表
- sql - 如何在oracle plsql中对clob进行子串化
- javascript - 在 nuxt.js 身份验证中,用户始终重定向到刷新时登录