I was looking for an example implementation of circle for debugging on the forum, didnt find an example
so here is another implementation using Graphic 2D for those who want to.
with this implementation, you can set a fill color and decide of the angle of the arc drawn.
a circle is a node with a Quad Child having a texture generated by Java2D
this is just an exemple so you guys can do other things, draw rectangles and stuff.
if you update anything, just call circle.generateImage(), so the texture gets updated.
and if you want to rotate the circle, just use the regular stuff you do with Nodes, dont edit the child node, just rotate the parent.
Result :
Usage :
[java]
//Usage :
Circle circle = new Circle(assetManager,50,5,Color.GRAY,360,Color.red,45);
circle.setLocalTranslation(0, 0, 0);
app.getRootNode().attachChild(circle);
[/java]
[java]
/*
To change this template, choose Tools | Templates
and open the template in the editor.
*/
package other;
@author bobo
*/
public class Circle extends Node {
private float radius = 5;
private int angle = 360;
private int borderAngle = 360;
private Color color = Color.BLACK;
private Color fillColor = null;
private AssetManager assetManager;
private final Texture texture = new Texture2D();
private float borderWidth;
private int heightResolution = 64;
private int widthResolution = 64;
private Material material;
private Geometry geometry;
/**
*
@param assetManager
@param radius radius of the circle
@param borderWidth width of the border
@param color fill color
@param borderAngle and of border displayed
@param fillColor filled color
@param angle and gle of the filled color
*/
public Circle(AssetManager assetManager, float radius, float borderWidth, Color color, int borderAngle, Color fillColor, int angle) {
this.assetManager = assetManager;
this.radius = radius;
this.color = color;
this.fillColor = fillColor;
this.borderWidth = borderWidth;
this.borderAngle = borderAngle;
this.angle = angle;
material = new Material(this.assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
material.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
initSpatial();
updateSpatial();
}
@navycougar said:
oh thats nice mifth,
I just tweaked your Circle2DTest example a little bit to show what we can do with it, here is the code:
.....
here is the code if you wanna update your example
....
@mifth said:
@navycougar is it possible to convert svg vector file to texture using your method? it would be really cool.
Just like these svg vector files:
http://streambag.se/files/freebsdlogo.svg
http://upload.wikimedia.org/wikipedia/commons/5/53/GNU_and_Tux.svg
Hey mifth, it is possible to generate a BufferedImage or an Awt Image from an SVG here are some links :
if you are having issues with the examples resolution, you can change the resolution of the circle by increasing the widthResolution and heighResolution of circle2D, by default its set to 64x64, if that’s not enough just increase to 256x256 ^^