use of org.twak.utils.geom.Line3d in project chordatlas by twak.
the class GISGen method initObj.
public void initObj() {
ObjRead gObj = new ObjRead(tweed.toWorkspace(objFile));
LoopL<Point3d> fromOBJ = new LoopL<>();
Closer<Point3d> closer = new Closer<>();
for (int[] face : gObj.faces) {
Loop<Point3d> loop = fromOBJ.newLoop();
List<Point3d> points = new ArrayList<>();
for (int i = 0; i < face.length; i++) {
Point3d p = new Point3d(gObj.pts[face[i]]), n = new Point3d(gObj.pts[face[(i + 1) % face.length]]);
// !
n.y = p.y = 0;
loop.append(p);
points.add(p);
lines.add(new Line3d(p, n));
}
closer.add(points.toArray(new Point3d[points.size()]));
}
createBlocks(closer, fromOBJ);
}
use of org.twak.utils.geom.Line3d 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();
}
Aggregations