在我的演示项目中(3D视图)。显示模型时,某些模型显示大尺寸(屏幕外),而某些模型尺寸太小。在设备屏幕上适合模型的最佳比例是什么。
我的代码是..
private fun createRenderAble() {
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
}
}
private fun addNodeToScenee(renderable: ModelRenderable?) {
val tempNode = Node()
tempNode.renderable = renderable
val collisionShape: Box = tempNode.collisionShape as Box
// var radius = 1f
// if (collisionShape.size.x > 2.0) {
// radius = 3f
// }
// if (collisionShape.size.y > 1.3) {
// radius = 2f
// }
radius=collisionShape.size.x
val node = DragTransformableNode(radius, transformationSystem).apply {
setParent(sceneView.scene)
this.renderable = renderable
select()
}
sceneView.scene.addChild(node)
}
答案 0 :(得分: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
}
或
val collisionShape: Box = node.collisionShape as Box
radius=collisionShape.size.x
说明:我在这里所做的是检查可渲染对象的宽度是否超过2.0米。我正在将摄影机的半径设置为3f。这将帮助我们将完整的模型容纳到屏幕中。高度(collisionShape.size.y
)也是如此。