I haven't found anything in LibGDX that would work with vector graphics.
我还没有在LibGDX中找到任何与矢量图形有关的东西。
This post suggests that AGG is close as it gets, they also mentioned that it is a lot of pain.
这篇文章暗示AGG是很接近的,他们也提到这是很痛苦的。
Is there a painless alternative ?
有没有无痛的选择?
2 个解决方案
#1
5
There does not seem to be any painless support for vector graphics in Libgdx at this point (mid-2013). First, for vector graphics generally that means SVG in practice.
在这一点上(2013年中期),Libgdx中似乎没有任何对矢量图形的无痛支持。首先,对于矢量图形来说,这通常意味着SVG。
Part of the problem with a "generic" SVG solution is that getting it to work with all the various corner cases seems to be an issue. However, if you are just trying to render your own SVG objects, you may have a simpler subset of SVG to deal with and hacking something up may work for you (even if its not generic enough for everybody).
“通用”SVG解决方案的部分问题是,如何让它与所有的角落案例一起工作似乎是个问题。但是,如果您只是尝试呈现自己的SVG对象,那么您可能有一个更简单的SVG子集来处理,对某些东西进行黑客攻击可能对您有用(即使对每个人来说还不够通用)。
Additionally, if you're willing to use bitmaps as an intermediary (you don't need to render the vector graphics directly to the screen), you just need to find a Java-based SVG parser and rasterizer (vs. one that uses a Libgdx or LWJGL backend).
此外,如果您愿意使用位图作为中介(不需要直接将矢量图形呈现到屏幕上),您只需找到一个基于java的SVG解析器和栅格化器(与使用Libgdx或LWJGL后端的解析器相比)。
See Using SVG files with libgdx. The suggestion here is to use the Libgdx ShapeRenderer
for simple "scalable" graphics. Its no SVG, but its might be reasonable for your use case.
参见使用SVG文件与libgdx。这里的建议是使用Libgdx ShapeRenderer来实现简单的“可伸缩”图形。它没有SVG,但是它可能适合您的用例。
Google searches turned up this GPL'd Java SVG renderer that uses an AWT backend. This code looks simple enough that it could be adapted to use Libgdx rendering. But, given how simple it is, its not clear how much of SVG is actually supports (or if it even works at all).
谷歌搜索找到了使用AWT后端的GPL Java SVG渲染器。这段代码看起来非常简单,可以使用Libgdx渲染。但是,考虑到SVG有多简单,不清楚SVG到底支持多少(或者甚至根本不能工作)。
The Apache Batik project is a generic Java SVG parser and renderer. It looks enormous. You may be able to get it to render SVG into .png format (and then convert those into Libgdx Pixmaps). (I don't have any experience with this.)
Apache Batik项目是一个通用的Java SVG解析器和呈现器。它看起来巨大的。您可以让它将SVG呈现为.png格式(然后将其转换为Libgdx像素图)。(我没有这方面的经验。)
There is a (dead?) libgdx SVG extension project but it looks like only the most basic SVG parsing has been completed.
有一个(死的?)libgdx SVG扩展项目,但是看起来只有最基本的SVG解析完成了。
#2
4
I'm still learning LibGDX too and am about to face some similiar problems like you; Rendering 2D models in the Orthographic View.
我还在学习LibGDX,即将面临一些类似于你的问题;在正投影视图中绘制二维模型。
LibGDX works with OpenGL ES for graphics and also supports importing models which are created with a plugin for Blender 3D. I haven't tried this yet, but here is a solution for doing so:
LibGDX使用OpenGL ES处理图形,还支持导入模型,这些模型是用Blender 3D插件创建的。我还没有尝试过这个,但这里有一个解决方法:
从搅拌机进口模型
处理代码
I guess that A solution to solve this would be to model your scalable graphics in Blender 3D. If you are using SVG files, then Blender 3D is able to import those files, so you could use Blender 3D as the first touchdown.
我想解决这个问题的办法是用Blender 3D建模可伸缩图形。如果您正在使用SVG文件,那么Blender 3D可以导入这些文件,因此您可以使用Blender 3D作为第一次触地。
ADD: I now managed to do it. There is a little twist though: The method with the python script is outdated. In the comments on the page to the first link above, there is a link to xoppa's tutorials. It's described there how to export models with the FBX converter tool. I made a 2D plane shape facing the front view in Blender 3D. Exported it to FBX and used the converter tool to make a G3DB file. Using LibGdx's G3dModelLoader method as described in xoppa's tutorials, you can now draw it in your view with a ModelBatch. Make your Orthographic camera look at 0,0,0 (or whatever fits your needs) and go a little back on the z axis - else you will not be able to see it. Since it's an Orthographic camera it doesen't matter how far, but somehow 0,0,1 would make some sort of sense :) Remember also to clear the GL_DEPTH_BUFFER_BIT now for each frame in your render.
补充:我现在已经做到了。不过有一点不太一样:python脚本的方法已经过时了。在上面第一个链接的页面评论中,有一个链接指向xoppa的教程。这里描述了如何使用FBX转换器工具导出模型。我用Blender 3D制作了一个面向前视图的二维平面图形。导出到FBX并使用转换器工具制作G3DB文件。使用xoppa教程中描述的LibGdx的G3dModelLoader方法,您现在可以使用ModelBatch在视图中绘制它。让你的正射摄影机看着0,0,0,0(或任何你需要的东西),在z轴上后退一点——否则你将看不到它。因为它是一个正射摄影机,所以不管它有多远,但是无论如何,0,1都会有一定的意义:)记住,现在要为渲染的每一帧清除GL_DEPTH_BUFFER_BIT。
#1
5
There does not seem to be any painless support for vector graphics in Libgdx at this point (mid-2013). First, for vector graphics generally that means SVG in practice.
在这一点上(2013年中期),Libgdx中似乎没有任何对矢量图形的无痛支持。首先,对于矢量图形来说,这通常意味着SVG。
Part of the problem with a "generic" SVG solution is that getting it to work with all the various corner cases seems to be an issue. However, if you are just trying to render your own SVG objects, you may have a simpler subset of SVG to deal with and hacking something up may work for you (even if its not generic enough for everybody).
“通用”SVG解决方案的部分问题是,如何让它与所有的角落案例一起工作似乎是个问题。但是,如果您只是尝试呈现自己的SVG对象,那么您可能有一个更简单的SVG子集来处理,对某些东西进行黑客攻击可能对您有用(即使对每个人来说还不够通用)。
Additionally, if you're willing to use bitmaps as an intermediary (you don't need to render the vector graphics directly to the screen), you just need to find a Java-based SVG parser and rasterizer (vs. one that uses a Libgdx or LWJGL backend).
此外,如果您愿意使用位图作为中介(不需要直接将矢量图形呈现到屏幕上),您只需找到一个基于java的SVG解析器和栅格化器(与使用Libgdx或LWJGL后端的解析器相比)。
See Using SVG files with libgdx. The suggestion here is to use the Libgdx ShapeRenderer
for simple "scalable" graphics. Its no SVG, but its might be reasonable for your use case.
参见使用SVG文件与libgdx。这里的建议是使用Libgdx ShapeRenderer来实现简单的“可伸缩”图形。它没有SVG,但是它可能适合您的用例。
Google searches turned up this GPL'd Java SVG renderer that uses an AWT backend. This code looks simple enough that it could be adapted to use Libgdx rendering. But, given how simple it is, its not clear how much of SVG is actually supports (or if it even works at all).
谷歌搜索找到了使用AWT后端的GPL Java SVG渲染器。这段代码看起来非常简单,可以使用Libgdx渲染。但是,考虑到SVG有多简单,不清楚SVG到底支持多少(或者甚至根本不能工作)。
The Apache Batik project is a generic Java SVG parser and renderer. It looks enormous. You may be able to get it to render SVG into .png format (and then convert those into Libgdx Pixmaps). (I don't have any experience with this.)
Apache Batik项目是一个通用的Java SVG解析器和呈现器。它看起来巨大的。您可以让它将SVG呈现为.png格式(然后将其转换为Libgdx像素图)。(我没有这方面的经验。)
There is a (dead?) libgdx SVG extension project but it looks like only the most basic SVG parsing has been completed.
有一个(死的?)libgdx SVG扩展项目,但是看起来只有最基本的SVG解析完成了。
#2
4
I'm still learning LibGDX too and am about to face some similiar problems like you; Rendering 2D models in the Orthographic View.
我还在学习LibGDX,即将面临一些类似于你的问题;在正投影视图中绘制二维模型。
LibGDX works with OpenGL ES for graphics and also supports importing models which are created with a plugin for Blender 3D. I haven't tried this yet, but here is a solution for doing so:
LibGDX使用OpenGL ES处理图形,还支持导入模型,这些模型是用Blender 3D插件创建的。我还没有尝试过这个,但这里有一个解决方法:
从搅拌机进口模型
处理代码
I guess that A solution to solve this would be to model your scalable graphics in Blender 3D. If you are using SVG files, then Blender 3D is able to import those files, so you could use Blender 3D as the first touchdown.
我想解决这个问题的办法是用Blender 3D建模可伸缩图形。如果您正在使用SVG文件,那么Blender 3D可以导入这些文件,因此您可以使用Blender 3D作为第一次触地。
ADD: I now managed to do it. There is a little twist though: The method with the python script is outdated. In the comments on the page to the first link above, there is a link to xoppa's tutorials. It's described there how to export models with the FBX converter tool. I made a 2D plane shape facing the front view in Blender 3D. Exported it to FBX and used the converter tool to make a G3DB file. Using LibGdx's G3dModelLoader method as described in xoppa's tutorials, you can now draw it in your view with a ModelBatch. Make your Orthographic camera look at 0,0,0 (or whatever fits your needs) and go a little back on the z axis - else you will not be able to see it. Since it's an Orthographic camera it doesen't matter how far, but somehow 0,0,1 would make some sort of sense :) Remember also to clear the GL_DEPTH_BUFFER_BIT now for each frame in your render.
补充:我现在已经做到了。不过有一点不太一样:python脚本的方法已经过时了。在上面第一个链接的页面评论中,有一个链接指向xoppa的教程。这里描述了如何使用FBX转换器工具导出模型。我用Blender 3D制作了一个面向前视图的二维平面图形。导出到FBX并使用转换器工具制作G3DB文件。使用xoppa教程中描述的LibGdx的G3dModelLoader方法,您现在可以使用ModelBatch在视图中绘制它。让你的正射摄影机看着0,0,0,0(或任何你需要的东西),在z轴上后退一点——否则你将看不到它。因为它是一个正射摄影机,所以不管它有多远,但是无论如何,0,1都会有一定的意义:)记住,现在要为渲染的每一帧清除GL_DEPTH_BUFFER_BIT。