如何解决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.")
}
使用该代码而不进行更改呈现给定的外观(我有黎明黑线显示分裂成三角形):
纹理是一个向上看的箭头。我希望所有应用的纹理都能“向上看”并平铺,以便在三角形相互接触时制作无缝边框。
进行实心填充:
我觉得,我需要对每个顶点的 UvCoordinates 做一些事情(将它们映射到世界,而不是单个三角形),但我找不到如何做到这一点的方法。
>此外,为了无缝填充这些三角形,也许我需要将从各个点收集的 UV 坐标分别缩放到标准化三角形,以防止在三角形大小不同时出现不同的纹理缩放。
有没有办法“概括”uv坐标?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。