Search in sources :

Example 76 with Transform

use of com.jme3.math.Transform in project chordatlas by twak.

the class ObjGen method calculate.

@Override
public void calculate() {
    tweed.clearCurrentToolState();
    gNode.removeFromParent();
    Transform oldTransform = null;
    for (Spatial s : gNode.getChildren()) {
        s.removeFromParent();
        oldTransform = s.getLocalTransform();
    }
    Spatial mesh = tweed.getAssetManager().loadModel(filename);
    Material mat = null;
    ColorRGBA genCol = new ColorRGBA(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, transparency);
    // addLocal( ColorRGBA.Black.mult( 0.5f ) );
    genCol.multLocal(0.35f);
    if (transparency == 0) {
        mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
        ColorRGBA c = Jme3z.toJme(color);
        mat.setColor("Diffuse", c);
        mat.setColor("Ambient", c);
        mat.setBoolean("UseMaterialColors", true);
    } else if (transparency == 1)
        mat = null;
    else {
        mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
        mat.getAdditionalRenderState().setBlendMode(BlendMode.PremultAlpha);
        mat.setColor("Color", genCol);
    }
    Mode mode = renderLines ? Mesh.Mode.Lines : Mesh.Mode.Triangles;
    if (mesh instanceof Geometry) {
        // objs with several objects are a node
        geometry = (Geometry) mesh;
        setTexture(geometry, mat);
        geometry.getMesh().setMode(mode);
    } else {
        mesh.setUserData(HandleMe.class.getSimpleName(), true);
        for (Spatial s : ((Node) mesh).getChildren()) ((Geometry) s).getMesh().setMode(mode);
    }
    hasTextures = mat == null;
    if (mat != null)
        mesh.setMaterial(mat);
    if (oldTransform != null)
        mesh.setLocalTransform(oldTransform);
    gNode.setUserData(HandleMe.class.getSimpleName(), true);
    gNode.attachChild(mesh);
    super.calculate();
}
Also used : Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) Mode(com.jme3.scene.Mesh.Mode) BlendMode(com.jme3.material.RenderState.BlendMode) Node(com.jme3.scene.Node) HandleMe(org.twak.tweed.handles.HandleMe) Material(com.jme3.material.Material) Transform(com.jme3.math.Transform)

Example 77 with Transform

use of com.jme3.math.Transform in project chordatlas by twak.

the class PanoGen method createPanoGen.

private void createPanoGen(File f, List<Pano> results) {
    String name = f.getName().substring(0, f.getName().length() - 4);
    try {
        String[] sVals = name.split("[_]", 10);
        if (sVals.length < 6)
            return;
        List<Double> pos = Arrays.asList(Arrays.copyOfRange(sVals, 0, 6)).stream().map(z -> Double.parseDouble(z)).collect(Collectors.toList());
        double[] trans = new double[] { pos.get(0), pos.get(1), 0 };
        double[] north = new double[] { pos.get(0), pos.get(1) + 1e-6, 0 };
        // two part transform to align heights - geoid for 4326 is different to 27700
        MathTransform latLong2Country = CRS.findMathTransform(CRS.decode(sourceCRS), CRS.decode(TweedSettings.settings.gmlCoordSystem), true);
        latLong2Country.transform(trans, 0, trans, 0, 1);
        latLong2Country.transform(north, 0, north, 0, 1);
        if (TweedSettings.settings.gmlCoordSystem.equals("EPSG:3042")) {
            /* madrid?! */
            System.out.println("******* dirty hack in place for flipped CS");
            double tmp = trans[0];
            trans[0] = trans[1];
            trans[1] = tmp;
        }
        MathTransform country2Cartesian = CRS.findMathTransform(CRS.decode(TweedSettings.settings.gmlCoordSystem), DefaultGeocentricCRS.CARTESIAN, true);
        country2Cartesian.transform(trans, 0, trans, 0, 1);
        country2Cartesian.transform(north, 0, north, 0, 1);
        {
            Point3d tmp = new Point3d(trans);
            TweedSettings.settings.toOrigin.transform(tmp);
            tmp.get(trans);
            tmp = new Point3d(north);
            TweedSettings.settings.toOrigin.transform(tmp);
            tmp.get(north);
        }
        if (TweedSettings.settings.gmlCoordSystem.equals("EPSG:2062")) {
            // oviedo :(
            trans[2] -= 258;
            north[2] -= 258;
            trans[0] += 3;
            trans[0] += 3;
        }
        Vector3d location = new Vector3d(trans[0], 2.5f, /* camera height above floor */
        trans[2]);
        {
            Vector3d west = new Vector3d((float) (trans[0] - north[0]), 0f, (float) (north[2] - trans[2]));
            west.scale(0.6f / west.length());
            location.add(west);
        }
        System.out.println("pano@ " + location);
        results.add(new Pano(name, location, // + 360 - (toNorth * 180 /FastMath.PI ) ) % 360,
        (pos.get(3).floatValue() + 180), pos.get(4).floatValue(), pos.get(5).floatValue()));
    } catch (IndexOutOfBoundsException e) {
        e.printStackTrace();
    } catch (NoSuchAuthorityCodeException e) {
        e.printStackTrace();
    } catch (FactoryException e) {
        e.printStackTrace();
    } catch (TransformException e) {
        e.printStackTrace();
    }
}
Also used : Color(java.awt.Color) FactoryException(org.opengis.referencing.FactoryException) XStream(com.thoughtworks.xstream.XStream) Arrays(java.util.Arrays) CRS(org.geotools.referencing.CRS) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) ClickMe(org.twak.tweed.ClickMe) Random(java.util.Random) Mode(com.jme3.scene.Mesh.Mode) PlaneTool(org.twak.tweed.tools.PlaneTool) Vector4f(com.jme3.math.Vector4f) IDumpObjs(org.twak.tweed.IDumpObjs) Material(com.jme3.material.Material) TransformException(org.opengis.referencing.operation.TransformException) Point3d(javax.vecmath.Point3d) VertexBuffer(com.jme3.scene.VertexBuffer) BufferedImage(java.awt.image.BufferedImage) ListDownLayout(org.twak.utils.ui.ListDownLayout) DefaultGeocentricCRS(org.geotools.referencing.crs.DefaultGeocentricCRS) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) Dimension(java.awt.Dimension) List(java.util.List) Mesh(com.jme3.scene.Mesh) JPanel(javax.swing.JPanel) Geometry(com.jme3.scene.Geometry) ActionListener(java.awt.event.ActionListener) FacadeTool(org.twak.tweed.tools.FacadeTool) Vector2f(com.jme3.math.Vector2f) Vector3d(javax.vecmath.Vector3d) Filez(org.twak.utils.Filez) Mosaic(org.twak.readTrace.Mosaic) Tweed(org.twak.tweed.Tweed) ArrayList(java.util.ArrayList) TweedSettings(org.twak.tweed.TweedSettings) Spatial(com.jme3.scene.Spatial) Graphics2D(java.awt.Graphics2D) Mathz(org.twak.utils.Mathz) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) Iterator(java.util.Iterator) Files(java.nio.file.Files) BufferUtils(com.jme3.util.BufferUtils) Vector3f(com.jme3.math.Vector3f) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) MathTransform(org.opengis.referencing.operation.MathTransform) Jme3z(org.twak.siteplan.jme.Jme3z) EventMoveHandle(org.twak.tweed.EventMoveHandle) ObjDump(org.twak.utils.geom.ObjDump) ColorRGBA(com.jme3.math.ColorRGBA) JTextArea(javax.swing.JTextArea) Box(com.jme3.scene.shape.Box) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) MathTransform(org.opengis.referencing.operation.MathTransform) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d)

Aggregations

Vector3f (com.jme3.math.Vector3f)34 Transform (com.jme3.math.Transform)33 TempVars (com.jme3.util.TempVars)24 Quaternion (com.jme3.math.Quaternion)13 Matrix4f (com.jme3.math.Matrix4f)11 Bone (com.jme3.animation.Bone)9 BoundingBox (com.jme3.bounding.BoundingBox)9 Spatial (com.jme3.scene.Spatial)9 Geometry (com.jme3.scene.Geometry)8 ColorRGBA (com.jme3.math.ColorRGBA)7 Material (com.jme3.material.Material)6 Node (com.jme3.scene.Node)5 PointLight (com.jme3.light.PointLight)4 Mode (com.jme3.scene.Mesh.Mode)4 BoneContext (com.jme3.scene.plugins.blender.animations.BoneContext)4 FloatBuffer (java.nio.FloatBuffer)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Matrix4d (javax.vecmath.Matrix4d)4 Transform (com.bulletphysics.linearmath.Transform)3