Skip to main content

Converter JAVA3D in KML(Keyhole Markup Languauge)

No replies
sphere1
Offline
Joined: 2010-02-18
Points: 0

Hello,

i am new in this Site. I hope i am right here.
I wrote "Cube" in Java3D and would like to show my Cubes in Goolge Earths. Is there any converter for Java3D to KML?

Can somebody please help me? Any idea?

Thanks you.

Best Regards,
Sphere1

Here is my Code:

package Cube;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;

import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.Matrix4f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;

// Cube
public class Cube extends Applet {

public BranchGroup createSceneGraph() {

// erstelle Identitätstransformation
BranchGroup objRoot = new BranchGroup();

//Create the transform group node and initialize it to the identity.
TransformGroup objScale = new TransformGroup();
Transform3D t3d = new Transform3D();
t3d.setScale(0.4);
objScale.setTransform(t3d);
objRoot.addChild(objScale);

// Geometry of Cubes:
ColorCube colCube1 = new ColorCube(0.4);

com.sun.j3d.utils.picking.PickResult test2 = null;

ColorCube colCube2 = new ColorCube(0.2);

ColorCube colCube3 = new ColorCube(0.4);

//Create the transform Group node and initialize it to the identity.
TransformGroup RotTransCube1 = new TransformGroup();
RotTransCube1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objScale.addChild(RotTransCube1);

TransformGroup RotTransCube2 = new TransformGroup();
RotTransCube2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objScale.addChild(RotTransCube2);

TransformGroup rotationXAchse = new TransformGroup();
rotationXAchse.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objScale.addChild(rotationXAchse);

// Tranformation (Rotation of Cubbe Nr. 2)
Transform3D tTrans3dRotX = new Transform3D();
tTrans3dRotX.rotY(Math.toRadians(-45));

TransformGroup tTransGroupRoX = new TransformGroup(tTrans3dRotX);

rotationXAchse.addChild(tTransGroupRoX);
// End of Tranformation (Rotation of Cubbe Nr. 2)

// scrolling of Cube Nr. 1
Transform3D tTrans3dCube1 = new Transform3D();
Vector3d lPos1 = new Vector3d(1.0, 1.0, 2.0); // fix the Position
tTrans3dCube1.set(lPos1);

TransformGroup tTransGroupCube1 = new TransformGroup(tTrans3dCube1);
RotTransCube1.addChild(tTransGroupCube1);

// End of scrolling of Cube Nr.1

// Scrolling of Cube Nr.2
Transform3D tTrans3dCube2 = new Transform3D();
Vector3d lPos2 = new Vector3d(1.5, 0, 0);
tTrans3dCube2.set(lPos2);
TransformGroup tTransGroupCube2 = new TransformGroup(tTrans3dCube2);
RotTransCube2.addChild(tTransGroupCube2);
// End of scrolling og Cube Nr.2

tTransGroupCube1.addChild(colCube1);
tTransGroupCube2.addChild(colCube2);
tTransGroupRoX.addChild(colCube3);
objRoot.compile();

return objRoot;
}

public Cube() {

setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

Canvas3D canvas3D = new Canvas3D(config);
add("Center", canvas3D);

BranchGroup scene = createSceneGraph();

// SimpleUniverse is a Convenience Utility class
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

// This will move the ViewPlatform back a bit so the objects in the scene can be viewed.
simpleU.getViewingPlatform().setNominalViewingTransform();

simpleU.addBranchGraph(scene);

}

public static void main(String[] args) {

Frame frame = new MainFrame(new Cube(), 400, 256);

}
}