Search in sources :

Example 16 with Line3d

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);
}
Also used : Closer(org.twak.viewTrace.Closer) Point3d(javax.vecmath.Point3d) ArrayList(java.util.ArrayList) LoopL(org.twak.utils.collections.LoopL) ObjRead(org.twak.utils.geom.ObjRead) Line3d(org.twak.utils.geom.Line3d)

Example 17 with Line3d

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();
}
Also used : Loop(org.twak.utils.collections.Loop) ClickMe(org.twak.tweed.ClickMe) VertexBuffer(com.jme3.scene.VertexBuffer) ArrayList(java.util.ArrayList) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material) Line3d(org.twak.utils.geom.Line3d) Geometry(com.jme3.scene.Geometry) LodGenerator(jme3tools.optimize.LodGenerator) ColorRGBA(com.jme3.math.ColorRGBA) Random(java.util.Random) Spatial(com.jme3.scene.Spatial) Point3d(javax.vecmath.Point3d) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Line3d (org.twak.utils.geom.Line3d)17 Point3d (javax.vecmath.Point3d)15 ArrayList (java.util.ArrayList)10 LinearForm3D (org.twak.utils.geom.LinearForm3D)10 List (java.util.List)8 Point2d (javax.vecmath.Point2d)8 Vector3d (javax.vecmath.Vector3d)7 Vector2d (javax.vecmath.Vector2d)5 Loop (org.twak.utils.collections.Loop)5 ColorRGBA (com.jme3.math.ColorRGBA)4 Line (org.twak.utils.Line)4 Pair (org.twak.utils.Pair)4 Material (com.jme3.material.Material)3 Geometry (com.jme3.scene.Geometry)3 Node (com.jme3.scene.Node)3 File (java.io.File)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Matrix4d (javax.vecmath.Matrix4d)3