简体   繁体   English

使用Android和OpenGL ES / Rajawali标记3D模型的各个部分

[英]Labeling parts of 3D model with Android and OpenGL ES/Rajawali

I have imported a model (eg a teapot) using Rajawali into my scene. 我已将使用Rajawali的模型(例如茶壶)导入场景。 What I would like is to label parts of the model (eg the lid, body, foot, handle and the spout) using plain Android views, but I have no idea how this could be achieved. 我想使用简单的Android视图标记模型的各个部分(例如,盖子,身体,脚,手柄和壶嘴),但我不知道如何实现。 Specifically, positioning the labels on the right place seems challenging. 具体来说,将标签放置在正确的位置似乎具有挑战性。 The idea is that when I transform my model's position in the scene, the tips of the labels are still correctly positioned 想法是,当我变换模型在场景中的位置时,标签的尖端仍正确定位

Rajawali tutorial show how Android views can be placed on top of the scene here https://github.com/Rajawali/Rajawali/wiki/Tutorial-08-Adding-User-Interface-Elements . Rajawali教程在https://github.com/Rajawali/Rajawali/wiki/Tutorial-08-Adding-User-Interface-Elements处展示了如何将Android视图放置在场景顶部。 I also understand how using the transformation matrices a 3D coordinate on the model can be transformed into a 2D coordinate on the screen, but I have no idea how to determine the exact 3D coordinates on the model itself. 我也了解如何使用转换矩阵将模型上的3D坐标转换为屏幕上的2D坐标,但是我不知道如何确定模型本身的确切3D坐标。 The model is exported to OBJ format using Blender, so I assume there is some clever way of determining the coordinates in Blender and exporting them to a separate file or include them somehow in the OBJ file (but not render those points, only include them as metadata), but I have no idea how I could do that. 使用Blender将模型导出为OBJ格式,因此,我认为有一些聪明的方法可以在Blender中确定坐标并将其导出到单独的文件中,或者以某种方式将其包括在OBJ文件中(但不渲染这些点,仅将它们包括为元数据),但我不知道该怎么做。

Any ideas are very appreciated! 任何想法都非常感谢! :) :)

I would use a screenquad, not a view. 我会使用screenquad,而不是视图。 This is a general GL solution, and will also work with iOS. 这是一般的GL解决方案,也可以在iOS上使用。

You must determine the indices of the desired model vertices. 您必须确定所需模型顶点的索引。 Using the text rendering algo below, you can just fiddle them until you hit the right ones. 使用下面的文本渲染算法,您可以摆弄它们直到找到正确的。

  1. Create a reasonable ARGB bitmap with same aspect ratio as the screen. 创建与屏幕相同的长宽比的合理ARGB位图。
  2. Create the screenquad texture using this bitmap 使用此位图创建screenquad纹理
  3. Create a canvas using this bitmap 使用此位图创建画布
  4. The rest happens in onDrawFrame(). 其余的发生在onDrawFrame()中。 Clear the canvas using clear paint. 使用透明涂料清除画布。
  5. Use the MVP matrix to convert desired model vertices to canvas coordinates. 使用MVP矩阵将所需的模型顶点转换为画布坐标。
  6. Draw your desired text at the canvas coordinates 在画布坐标处绘制所需的文本
  7. Update the texture. 更新纹理。

  • Your text will render very precisely at the vertices you specfied. 您的文本将在您指定的顶点处非常精确地呈现。 The GL thread will double-buffer and loop you back to #4. GL线程将加倍缓冲并循环回到#4。 Super smooth 3D text animation! 超级流畅的3D文字动画!
  • Use double floating point math to avoid loss of precision during coordinate conversion, which results in wobbly text. 使用双浮点数学可避免坐标转换过程中的精度损失,这会导致文本不稳定。 You could even use the z value of the vertex to scale the text. 您甚至可以使用顶点的z值缩放文本。 Fancy! 看中!
  • The performance bottleneck is #7 since the entire bitmap must be copied to GL texture memory, every frame. 性能瓶颈是#7,因为必须将每个位图的整个位图都复制到GL纹理内存中。 Try to keep the bitmap as small as possible, maintaining aspect ratio. 尝试保持位图尽可能小,并保持宽高比。 Maybe let the user toggle the labels. 也许让用户切换标签。

  • Note that the copy to GL texture memory is redundant since in OpenGL-ES, GL memory is just regular memory. 请注意,复制到GL纹理内存是多余的,因为在OpenGL-ES中,GL内存只是常规内存。 For compatibility reasons, a redundant chunk of regular memory is reserved to artificially enforce the copy. 出于兼容性原因,保留了常规内存的冗余块以人为地强制执行副本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM