use of com.jme3.scene.VertexBuffer in project chordatlas by twak.
the class LineGen3d method calculate.
@Override
public void calculate() {
for (Spatial s : gNode.getChildren()) s.removeFromParent();
{
Geometry geom;
Mesh m = new Mesh();
m.setMode(Mesh.Mode.Lines);
List<Float> coords = new ArrayList();
List<Integer> inds = new ArrayList();
for (Line3d l : getLines()) {
inds.add(inds.size());
inds.add(inds.size());
coords.add((float) l.start.x);
coords.add((float) l.start.y);
coords.add((float) l.start.z);
coords.add((float) l.end.x);
coords.add((float) l.end.y);
coords.add((float) l.end.z);
}
m.setBuffer(VertexBuffer.Type.Position, 3, Arrayz.toFloatArray(coords));
m.setBuffer(VertexBuffer.Type.Index, 2, Arrayz.toIntArray(inds));
geom = new Geometry(filename, m);
geom.setCullHint(CullHint.Never);
Material lineMaterial = new Material(tweed.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
lineMaterial.setColor("Color", new ColorRGBA(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1f));
geom.setMaterial(lineMaterial);
geom.setLocalTranslation(0, 0, 0);
gNode.attachChild(geom);
}
// int c = 0;
VertexBuffer emptyVB = new VertexBuffer(Type.Index);
emptyVB.setupData(Usage.Static, 3, Format.UnsignedShort, BufferUtils.createShortBuffer(0));
{
Geometry geom;
Random randy = new Random();
for (Map.Entry<Loop<Point3d>, Integer> e : getFaces().entrySet()) {
Loop<Point3d> p = e.getKey();
final int callbackI = e.getValue();
Mesh m = Jme3z.fromLoop(p);
// m.setMode( Mesh.Mode.Triangles );
//
// List<Integer> inds = new ArrayList<>();
// List<Float> pos = new ArrayList<>();
// List<Float> norms = new ArrayList<>();
//
// Loopz.triangulate( p, true, inds, pos, norms );
//
// m.set setVe( Type.Index, Arrayz.toIntArray(inds));
geom = new Geometry(filename, m);
geom.setCullHint(CullHint.Never);
// ColorRGBA col = Jme3z.toJme( Rainbow.getColour( c++ ) );
ColorRGBA col = new ColorRGBA(color.getRed() * randy.nextFloat() / 500f + 0.1f, color.getGreen() * randy.nextFloat() / 500f + 0.1f, color.getBlue() * randy.nextFloat() / 500f + 0.1f, 1f);
Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
mat.setColor("Diffuse", col);
mat.setColor("Ambient", col);
mat.setBoolean("UseMaterialColors", true);
geom.setUserData(ClickMe.class.getSimpleName(), new Object[] { new ClickMe() {
@Override
public void clicked(Object data) {
polyClicked(callbackI);
}
} });
geom.setUserData(Gen.class.getSimpleName(), new Object[] { this });
geom.setMaterial(mat);
geom.setLocalTranslation(0, 0, 0);
if (TweedSettings.settings.LOD) {
LodGenerator lod = new LodGenerator(geom);
lod.bakeLods(LodGenerator.TriangleReductionMethod.COLLAPSE_COST, 10, 100);
GISLodControl lc = new GISLodControl();
lc.setTrisPerPixel(0.000001f);
geom.addControl(lc);
}
gNode.attachChild(geom);
}
}
gNode.updateModelBound();
super.calculate();
}
use of com.jme3.scene.VertexBuffer in project chordatlas by twak.
the class SkelFootprint method getColor.
public static ColorRGBA getColor(Geometry geom, Vector3f pt, int index, Tweed tweed) {
MatParam param = geom.getMaterial().getParam("DiffuseMap");
ImageRaster ir = ImageRaster.create(tweed.getAssetManager().loadTexture(((Texture2D) param.getValue()).getName()).getImage());
Mesh mesh = geom.getMesh();
// geom.getMaterial().getMaterialDef().
VertexBuffer pb = mesh.getBuffer(Type.Position);
VertexBuffer tb = mesh.getBuffer(Type.TexCoord);
IndexBuffer ib = mesh.getIndicesAsList();
Vector2f uva = new Vector2f(), uvb = new Vector2f(), uvc = new Vector2f();
Vector3f la = new Vector3f(), lb = new Vector3f(), lc = new Vector3f();
if (pb != null && pb.getFormat() == Format.Float && pb.getNumComponents() == 3) {
FloatBuffer fpb = (FloatBuffer) pb.getData();
FloatBuffer ftb = (FloatBuffer) tb.getData();
// aquire triangle's vertex indices
int vertIndex = index * 3;
int va = ib.get(vertIndex);
int vb = ib.get(vertIndex + 1);
int vc = ib.get(vertIndex + 2);
BufferUtils.populateFromBuffer(la, fpb, va);
BufferUtils.populateFromBuffer(lb, fpb, vb);
BufferUtils.populateFromBuffer(lc, fpb, vc);
BufferUtils.populateFromBuffer(uva, ftb, va);
BufferUtils.populateFromBuffer(uvb, ftb, vb);
BufferUtils.populateFromBuffer(uvc, ftb, vc);
// PaintThing.debug.put(1, new Line ( la.x, la.z, lb.x, lb.z) );
// PaintThing.debug.put(2, new Line ( lb.x, lb.z, lc.x, lc.z) );
// PaintThing.debug.put(3, new Line ( lc.x, lc.z, la.x, la.z) );
float[] bary = barycentric(pt, la, lb, lc);
int x = (int) ((uva.x * bary[0] + uvb.x * bary[1] + uvc.x * bary[2]) * ir.getWidth()), y = (int) ((uva.y * bary[0] + uvb.y * bary[1] + uvc.y * bary[2]) * ir.getHeight());
// ir.getHeight() - y -1 );
ColorRGBA out = ir.getPixel(x, y);
return out;
} else {
throw new UnsupportedOperationException("Position buffer not set or has incompatible format");
}
}
use of com.jme3.scene.VertexBuffer in project TeachingInSimulation by ScOrPiOzzy.
the class JmeUtil method getLineStart.
/**
* 获取Mesh line的真实的Start点,预设
* @param line com.jme3.scene.shape.Line
*/
public static Vector3f getLineStart(Line line) {
VertexBuffer position = line.getBuffer(Type.Position);
float[] arr = BufferUtils.getFloatArray((FloatBuffer) position.getDataReadOnly());
return new Vector3f(arr[0], arr[1], arr[2]);
}
Aggregations