0

I'm working with the Sceneform and was able to build custom made polygons filled with triangles (in my case, I'm taking first anchor and fill a triangle with a pair of next anchors (1-2-3, 1-3-4, 1-4-5 etc).

That builds a polygon for me, but the texture that is applied is aligned towards the first point, and I need it to always look in the same direction for all triangles.

The code for triangles I have from here: How to draw a polygon with Sceneform, ARCore?

    private fun makeTriangleWithAnchors(anchorNodes: List<AnchorNode>, material: Material): ModelRenderable {
        check(anchorNodes.size == 3) { "Different count of anchorsList than 3" }

        val p0 = anchorNodes[0].worldPosition
        val p1 = anchorNodes[1].worldPosition
        val p2 = anchorNodes[2].worldPosition
        val up = Vector3.up()
        val uvTop = UvCoordinate(0.5f, 1.0f)
        val uvBotLeft = UvCoordinate(0.0f, 0.0f)
        val uvBotRight = UvCoordinate(1.0f, 0.0f)
        val vertices = ArrayList(listOf(
            Vertex
                .builder()
                .setPosition(p0)
                .setNormal(up)
                .setUvCoordinate(uvTop)
                .build(),
            Vertex
                .builder()
                .setPosition(p1)
                .setNormal(up)
                .setUvCoordinate(uvBotRight)
                .build(),
            Vertex
                .builder()
                .setPosition(p2)
                .setNormal(up)
                .setUvCoordinate(uvBotLeft)
                .build()
        ))
        val triangleIndices = ArrayList<Int>(3)
        triangleIndices.add(0)
        triangleIndices.add(2)
        triangleIndices.add(1)
        triangleIndices.add(0)
        triangleIndices.add(1)
        triangleIndices.add(2)
        val submesh = Submesh
            .builder()
            .setTriangleIndices(triangleIndices)
            .setMaterial(material)
            .build()

        val renderableDefinition = RenderableDefinition
            .builder()
            .setVertices(vertices)
            .setSubmeshes(listOf(submesh))
            .build()

        val future = ModelRenderable
            .builder()
            .setSource(renderableDefinition)
            .build()

        val result: ModelRenderable?
        result = try {
            future.get() as ModelRenderable
        } catch (e: InterruptedException) {
            throw AssertionError("Error creating renderable.", e)
        } catch (e: ExecutionException) {
            throw AssertionError("Error creating renderable.", e)
        }
        return result ?: throw AssertionError("Error creating renderable.")
    }

Using that code without changes renders given look (I have dawn black lines to show splitting into the triangles):

AR SCeneForm polygon

The texture is an arrow looking up. And I want all applied textures to "look" up and tile, to make seamless borders when triangles touch with each other.

Making a solid fill:

enter image description here

I feel, that there is something I need to do with the UvCoordinates of each vertex (to map those to the world, not a single triangle), but I'm failing to find a way how to do that.

Also, to fill those triangles seamlessly, maybe I need to scale the UV coordinates gathered from the points respectively to the normalized triangle to prevent different texture scalings when triangles sizes are different.

Is there a way to "generalize" the uv coordinates?

Zoe
  • 27,060
  • 21
  • 118
  • 148
NonGrate
  • 862
  • 9
  • 22
  • 1
    Hi, did you find a solution? – Pepa Zapletal Jan 15 '22 at 09:28
  • 1
    Hi! We decided to use the Unity version of the ARCore. It's richer and more powerful, the android's ARCore look like a PoC rather than a full SDK. Also we've used a library to render the Unity library in Flutter (sorry, don't know which one as I don't have access to the source anymore). The Unity ARCore solution is much more precise. – NonGrate Jan 16 '22 at 09:46

0 Answers0