Sceneform 无缝地将纹理应用于三角形

问题描述

我正在使用 Sceneform 并且能够构建填充三角形的定制多边形(在我的例子中,我使用第一个锚点并用一对下一个锚点填充三角形(1-2-3,1 -3-4、1-4-5 等)。

这为我构建了一个多边形,但应用的纹理朝向第一个点对齐,我需要它始终朝着相同的方向查看所有三角形。

我从这里得到的三角形代码: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.")
    }

使用该代码而不进行更改呈现给定的外观(我有黎明黑线显示分裂成三角形):

AR SCeneForm polygon

纹理是一个向上看的箭头。我希望所有应用的纹理都能“向上看”并平铺,以便在三角形相互接触时制作无缝边框。

进行实心填充:

enter image description here

我觉得,我需要对每个顶点的 UvCoordinates 做一些事情(将它们映射到世界,而不是单个三角形),但我找不到如何做到这一点的方法。

>

此外,为了无缝填充这些三角形,也许我需要将从各个点收集的 UV 坐标分别缩放到标准化三角形,以防止在三角形大小不同时出现不同的纹理缩放。

有没有办法“概括”uv坐标?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)