在3d视图中显示设备时如何在设备屏幕中放置3D模型

问题描述 投票:0回答:1

在我的演示项目中(3D视图)。显示模型时,某些模型显示大尺寸(屏幕外),而某些模型尺寸太小。在设备屏幕上适合模型的最佳比例是多少?

我的代码是..

    ModelRenderable.builder().setSource(
        this, RenderableSource.builder()
            .setSource(this, Uri.parse(model?.modelUri), RenderableSource.SourceType.GLB)
            .setRecenterMode(RenderableSource.RecenterMode.CENTER)
            .build()
    ).setRegistryId(model?.modelUri)
     .build()
     .thenAccept { renderable ->
            hideProgress()
            addNodeToScene(renderable)
        }
        .exceptionally {
            showToast(it.localizedMessage)
            hideProgress()
            null
        }

enter image description here

android arcore sceneform
1个回答
0
投票

您可以通过检查可渲染对象的大小来控制。下面的代码将帮助您解决问题。将可渲染设置为节点后,请执行以下操作。

        val collisionShape: Box = node.collisionShape as Box
        var radius = 1f
        if (collisionShape.size.x > 2.0) {
            radius = 3f
        }
        if (collisionShape.size.y > 1.3) {
            radius = 2f
        }

说明:我在这里正在检查可渲染对象的宽度是否超​​过2.0米,我正在将相机的半径设置为3f。这将帮助我们将完整的模型容纳到屏幕中。高度(collisionShape.size.y)也是如此。

© www.soinside.com 2019 - 2024. All rights reserved.