sceneview-android icon indicating copy to clipboard operation
sceneview-android copied to clipboard

ImageNode not rendering full image

Open andreas-umbricht opened this issue 1 year ago • 5 comments

I used the samples/ar-model-viewer-compose project and made some small changes. Instead of using a ModelNode I wanted to try out an ImageNode.

    fun createAnchorNode(
        engine: Engine,
        materialLoader: MaterialLoader,
        anchor: Anchor
    ): AnchorNode {
        val anchorNode = AnchorNode(engine = engine, anchor = anchor)

        val imageNode = ImageNode(
            materialLoader = materialLoader,
            imageResId = R.drawable.img_1,
            normal = Direction(0f)
        ).apply {
            transform(
                position = Position(
                    this.position.x,
                    this.position.y + 1.6f,
                    this.position.z - 2f
                )
            )
        }

        anchorNode.addChildNode(imageNode)

        return anchorNode
    }

The Image should be pointing at the camera and be located in mid air. This totally works but there is a huge problem/bug while rendering.

Screenshot_20240111_170945

As you can see, the image is diagonally cut in half. I tried with multiple files and it always resulted with the same problem.

andreas-umbricht avatar Jan 11 '24 16:01 andreas-umbricht

Also having same issue, image is diagonally cut in half.

Swithurn avatar Jan 17 '24 06:01 Swithurn

I also tried adding the image as a ViewNode, but I was not able to achieve to render anything. Nevertheless, using a ViewNode instead of the ImageNode would be a good workaround until the ImageNode issue is resolved.

@Composable
fun ar() {
	val engine = rememberEngine()
	val modelLoader = rememberModelLoader(engine)
	val context = LocalContext.current
	val childNodes = rememberNodes()

	var frame by remember { mutableStateOf<Frame?>(null) }
	var sceneView by remember { mutableStateOf<View?>(null)}

	ArScene(
		...
		...
		onSessionUpdated = {session, updatedFrame ->
			frame = updatedFrame
			
			if (childNodes.isEmpty()) {
				updatedFrame.getUpdatedPlanes()
					.firstOrNull { it.type == Plane.Type.HORIZONTAL_UPWARD_FACING }
					?.let { it.createAnchorOrNull(it.centerPose)}?.let { anchor ->
						createAnchorNode(
							engine = engine,
							anchor = anchor,
							context = context,
							modelLoader = modelLoader,
							sceneView = sceneView
						) {
							childNodes += it
						}
			}
		},
		onViewCreated = {
			sceneView = this
		}
	)
}   

 fun createAnchorNode(
        engine: Engine,
        context: Context,
        anchor: Anchor,
        modelLoader: ModelLoader,
        sceneView: View?,
        cB: (AnchorNode) -> Unit
    ) {
        val anchorNode = AnchorNode(engine = engine, anchor = anchor)

        if (sceneView == null) return

        ViewRenderable
            .builder()
            .setView(context, R.layout.test)
            .build(engine)
            .thenAccept { viewRenderable ->
                val viewNode = ViewNode(
                    engine = engine,
                    modelLoader = modelLoader,
                    viewAttachmentManager = ViewAttachmentManager(context, sceneView)
                ).apply {
                    this.setRenderable(viewRenderable)
                    this.scale = Scale(5f)
                }

                anchorNode.addChildNode(viewNode)
                
                cB(anchorNode)
            }
    }

Sadly there is no example in the sample apps where either ImageNode or ViewNode is used.

andreas-umbricht avatar Jan 17 '24 12:01 andreas-umbricht

I opened an issue https://github.com/SceneView/sceneview-android/issues/379 3 weeks ago and it should be fixed on next version. PR has been merged : https://github.com/SceneView/sceneview-android/pull/392

JeromeCHA avatar Jan 18 '24 01:01 JeromeCHA

Me too facing the same issue. Please also help me if we can create a textnode to place text content and any sample code for the same.

nallaperumal avatar Jan 18 '24 01:01 nallaperumal

Was this "fixed" in 2.0.3 with #392? I am still experiencing similar shearing of models in the latest release.

ryust avatar Feb 06 '24 22:02 ryust

Fixed in 2.0.4

ThomasGorisse avatar Mar 13 '24 13:03 ThomasGorisse

I'm not sure this is fixed or I have a different issue. In 2.0.4, I continue to see an occasional diagonal cutting off a ModelNode image when moving the camera around for a model with Google geospatial anchors.

ryust avatar Mar 13 '24 18:03 ryust