如何在 ARCore sceneform 中将视图渲染到父节点的右侧
How to render a View to the right of parent node in ARCore sceneform
我正在使用 ViewRenderable 渲染布局文件。我给布局文件定了宽高
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="500dp"
android:layout_height="50dp"
android:background="@android:color/transparent">
// Add design
</android.support.constraint.ConstraintLayout>
现在我正在将布局构建为 ViewRenderable
// Build a renderable from a 2D View.
CompletableFuture<ViewRenderable> meterOne =
ViewRenderable.builder().setView(this, R.layout.meter).build();
CompletableFuture.allOf(circle,
meterOne, meterTwo)
.handle(
(notUsed, throwable) -> {
// When you build a Renderable, Sceneform loads its resources in the background while
// returning a CompletableFuture. Call handle(), thenAccept(), or check isDone()
// before calling get().
if (throwable != null) {
DemoUtils.displayError(this, "Unable to load renderable", throwable);
return null;
}
try {
Meters.add(meterOne.get());
} catch (InterruptedException | ExecutionException ex) {
DemoUtils.displayError(this, "Unable to load renderable", ex);
}
之后我需要将这个 ViewRenderable
对象渲染到节点
Node sunVisual = new Node();
sunVisual.setParent(sun);
sunVisual.setRenderable(Meters.get(0)); // View
sunVisual.setLocalScale(new Vector3(0.5f, 0.5f, 0.5f));
现在我需要在 sunVisual 节点的右侧添加另一个节点
Node node = new Node();
node.setParent(sunVisual );
node.setRenderable(Meters.get(1));
node.setLocalPosition(new Vector3(2.0f, 0.0f, 0.0f));
此代码在 google pixel 2 设备上运行良好,但我在 nokia x6 设备 space 上变小了
Google像素2截图
诺基亚 x6 截图
如何获取以米为单位的渲染视图宽度和高度?
如何根据父节点渲染视图大小设置局部位置在父节点右侧
帮我解决这个问题提前谢谢
我找到了解决上述问题的方法。
Node node = new Node();
node.setParent(parent);
Renderable renderable = Meters.get(i);
renderable.setShadowReceiver(false);
renderable.setShadowCaster(false);
((ViewRenderable) renderable).setSizer(new FixedWidthViewSizer(2));
node.setRenderable(renderable);
node.setLocalPosition(new Vector3(2.0f, 0.0f, 0.0f));
我们可以使用setSizer来设置ViewRendarable
的宽度和高度
((ViewRenderable) renderable).setSizer(new FixedWidthViewSizer(2));
我正在使用 ViewRenderable 渲染布局文件。我给布局文件定了宽高
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="500dp"
android:layout_height="50dp"
android:background="@android:color/transparent">
// Add design
</android.support.constraint.ConstraintLayout>
现在我正在将布局构建为 ViewRenderable
// Build a renderable from a 2D View.
CompletableFuture<ViewRenderable> meterOne =
ViewRenderable.builder().setView(this, R.layout.meter).build();
CompletableFuture.allOf(circle,
meterOne, meterTwo)
.handle(
(notUsed, throwable) -> {
// When you build a Renderable, Sceneform loads its resources in the background while
// returning a CompletableFuture. Call handle(), thenAccept(), or check isDone()
// before calling get().
if (throwable != null) {
DemoUtils.displayError(this, "Unable to load renderable", throwable);
return null;
}
try {
Meters.add(meterOne.get());
} catch (InterruptedException | ExecutionException ex) {
DemoUtils.displayError(this, "Unable to load renderable", ex);
}
之后我需要将这个 ViewRenderable
对象渲染到节点
Node sunVisual = new Node();
sunVisual.setParent(sun);
sunVisual.setRenderable(Meters.get(0)); // View
sunVisual.setLocalScale(new Vector3(0.5f, 0.5f, 0.5f));
现在我需要在 sunVisual 节点的右侧添加另一个节点
Node node = new Node();
node.setParent(sunVisual );
node.setRenderable(Meters.get(1));
node.setLocalPosition(new Vector3(2.0f, 0.0f, 0.0f));
此代码在 google pixel 2 设备上运行良好,但我在 nokia x6 设备 space 上变小了
Google像素2截图
诺基亚 x6 截图
如何获取以米为单位的渲染视图宽度和高度?
如何根据父节点渲染视图大小设置局部位置在父节点右侧
帮我解决这个问题提前谢谢
我找到了解决上述问题的方法。
Node node = new Node();
node.setParent(parent);
Renderable renderable = Meters.get(i);
renderable.setShadowReceiver(false);
renderable.setShadowCaster(false);
((ViewRenderable) renderable).setSizer(new FixedWidthViewSizer(2));
node.setRenderable(renderable);
node.setLocalPosition(new Vector3(2.0f, 0.0f, 0.0f));
我们可以使用setSizer来设置ViewRendarable
((ViewRenderable) renderable).setSizer(new FixedWidthViewSizer(2));