The position of measurement points and lines cannot stick to the model in sceneview android

Viewed 35

I am using SceneForm Android SDK to render 3D Model in Android APP.

when i tap model, have add dot and line between two dots but the position of measurement points and lines cannot stick to the model. Can u help me resolve it? (i have research but not have way)

link video: enter link description here

enter image description here

My code:

private fun addNodeToScene(model: ModelRenderable) {
    if (sceneView != null) {
        val rotatingNode = RotatingNode()
        rotatingNode.renderable = model
        val collisionShape: Box = rotatingNode.collisionShape as Box
        var radius: Float = collisionShape.size.x
        val transformationSystem =
            TransformationSystem(resources.displayMetrics, FootprintSelectionVisualizer())
        dragTransformableNode = DragTransformableNode(radius, transformationSystem)
        dragTransformableNode?.renderable = model
        if (data?.scanningTypeID != 1) {
            dragTransformableNode?.scaleController?.maxScale = dragTransformableNode?.scaleController?.maxScale!! *3
        }
        sceneView?.scene?.addChild(dragTransformableNode)
        dragTransformableNode?.select()
        dragTransformableNode?.setOnTouchListener { hitTestResult, motionEvent ->
            if (gestureDetector.onTouchEvent(motionEvent)) {
            }
            this.hitTestResult = hitTestResult
            false
        }
        sceneView!!.getScene()
            .addOnPeekTouchListener { hitTestResult: HitTestResult?, motionEvent: MotionEvent? ->
                transformationSystem.onTouch(
                    hitTestResult,
                    motionEvent
                )
            }
    }
}

private fun addDot(hitTestResult: HitTestResult, activity: Activity){
    val color = Color(.8f, 0f, 0f)
    MaterialFactory.makeOpaqueWithColor(activity, color)
        .thenAccept { material->
            // The sphere is in local coordinate space, so make the center 0,0,0
            val sphere = ShapeFactory.makeSphere(0.02f, Vector3.zero(),
                material)
            val indicatorModel = Node()
            indicatorModel.setParent(hitTestResult.node)
            indicatorModel.localPosition = hitTestResult.point
            indicatorModel.renderable = sphere
            nodeList?.add(indicatorModel)
            if (!isResetMeasurement) {
                isResetMeasurement = true
                btResetMeasurement.visibility = View.VISIBLE
            }
        }
}
0 Answers
Related